Skip to content

Commit

Permalink
Fix bug in hstore rework.
Browse files Browse the repository at this point in the history
Bad idea to remove the k/v pairs from the linked list after
writing their colum, as write_wkts is called more than once.

So flag them to have their own column.

Afterwords check this flag to see if a given
k/v pair should be written to the hstore or not.
  • Loading branch information
Sven Geggus committed Apr 4, 2011
1 parent 6525dfa commit 8c86c5d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions keyvals.c
Expand Up @@ -25,6 +25,7 @@ void initList(struct keyval *head)
head->prev = head;
head->key = NULL;
head->value = NULL;
head->has_column = 0;
}

void freeItem(struct keyval *p)
Expand Down Expand Up @@ -251,6 +252,8 @@ int addItem(struct keyval *head, const char *name, const char *value, int noDupe
item->key = strdup(name);
item->value = strdup(value);
#endif
item->has_column=0;


#if 1
// Add to head
Expand Down
5 changes: 5 additions & 0 deletions keyvals.h
Expand Up @@ -11,6 +11,11 @@
struct keyval {
char *key;
char *value;
/* if a hstore column is requested we need a flag to store if a key
has its own column because it should not be added to the hstore
in this case
*/
int has_column;
struct keyval *next;
struct keyval *prev;
};
Expand Down
2 changes: 1 addition & 1 deletion osm2pgsql.c
Expand Up @@ -183,7 +183,7 @@ static void long_usage(char *arg0)
printf(" \t\tThis includes the username, userid, timestamp and version.\n");
printf(" \t\tNote: this option also requires additional entries in your style file.\n");
printf(" -k|--hstore\t\tAdd tags without column to an additional hstore (key/value) column to postgresql tables\n");
printf(" -j|--hstore-all\t\tAdd all tags to an additional hstore (key/value) column in postgresql tables\n");
printf(" -j|--hstore-all\tAdd all tags to an additional hstore (key/value) column in postgresql tables\n");
printf(" -z|--hstore-column\tAdd an additional hstore (key/value) column containing all tags\n");
printf(" \tthat start with the specified string, eg --hstore-column \"name:\" will\n");
printf(" \tproduce an extra hstore column that contains all name:xx tags\n");
Expand Down
8 changes: 4 additions & 4 deletions output-pgsql.c
Expand Up @@ -456,8 +456,8 @@ static void write_hstore(enum table_id table, struct keyval *tags)
while (xtags->next->key != NULL)
{

/* hard exclude z_order tag from hstore */
if (strcmp("z_order",xtags->next->key)==0) {
/* hard exclude z_order tag and keys which have their own column */
if ((xtags->next->has_column) || (strcmp("z_order",xtags->next->key)==0)) {
// update the tag-pointer to point to the next tag
xtags = xtags->next;
continue;
Expand Down Expand Up @@ -619,7 +619,7 @@ static int pgsql_out_node(int id, struct keyval *tags, double node_lat, double n
escape_type(sql, sqllen, tag->value, exportList[OSMTYPE_NODE][i].type);
exportList[OSMTYPE_NODE][i].count++;
if (HSTORE_NORM==Options->enable_hstore)
removeTag(tag);
tag->has_column=1;
}
else
sprintf(sql, "\\N");
Expand Down Expand Up @@ -671,7 +671,7 @@ static void write_wkts(int id, struct keyval *tags, const char *wkt, enum table_
exportList[OSMTYPE_WAY][j].count++;
escape_type(sql, sqllen, tag->value, exportList[OSMTYPE_WAY][j].type);
if (HSTORE_NORM==Options->enable_hstore)
removeTag(tag);
tag->has_column=1;
}
else
sprintf(sql, "\\N");
Expand Down

0 comments on commit 8c86c5d

Please sign in to comment.