- // Insert into placex
- paramValues[0] = (const char *)place_id;
- paramValues[1] = (const char *)feature.type;
- paramValues[2] = (const char *)feature.id;
- paramValues[3] = (const char *)feature.key;
- paramValues[4] = (const char *)feature.value;
-
- featureNameString[0] = 0;
- if (featureNameLines)
- {
- namePos = 0;
- lineTypeLen = 0;
- lineValueLen = 0;
- for(i = 0; i < featureNameLines; i++)
- {
- lineTypeLen = strlen(BAD_CAST featureName[i].type);
- lineValueLen = strlen(BAD_CAST featureName[i].value);
- if (namePos+lineTypeLen+lineValueLen+7 > MAX_FEATURENAMESTRING)
- {
- fprintf(stderr, "feature name too long: %s", (const char *)featureName[i].value);
- break;
- }
- if (namePos) strcpy(featureNameString+(namePos++), ",");
- strcpy(featureNameString+(namePos++), "\"");
- strcpy(featureNameString+namePos, BAD_CAST featureName[i].type);
- namePos += lineTypeLen;
- strcpy(featureNameString+namePos, "\"=>\"");
- namePos += 4;
- strcpy(featureNameString+namePos, BAD_CAST featureName[i].value);
- namePos += lineValueLen;
- strcpy(featureNameString+(namePos++), "\"");
- }
- }
- paramValues[5] = (const char *)featureNameString;
-
- featureExtraTagString[0] = 0;
- if (featureExtraTagLines)
- {
- namePos = 0;
- lineTypeLen = 0;
- lineValueLen = 0;
- for(i = 0; i < featureExtraTagLines; i++)
- {
- lineTypeLen = strlen(BAD_CAST featureExtraTag[i].type);
- lineValueLen = strlen(BAD_CAST featureExtraTag[i].value);
- if (namePos+lineTypeLen+lineValueLen+7 > MAX_FEATUREEXTRATAGSTRING)
- {
- fprintf(stderr, "feature extra tag too long: %s", (const char *)featureExtraTag[i].value);
- break;
- }
- if (namePos) strcpy(featureExtraTagString+(namePos++),",");
- strcpy(featureExtraTagString+(namePos++), "\"");
- strcpy(featureExtraTagString+namePos, BAD_CAST featureExtraTag[i].type);
- namePos += lineTypeLen;
- strcpy(featureExtraTagString+namePos, "\"=>\"");
- namePos += 4;
- strcpy(featureExtraTagString+namePos, BAD_CAST featureExtraTag[i].value);
- namePos += lineValueLen;
- strcpy(featureExtraTagString+(namePos++), "\"");
- }
- }
- paramValues[6] = (const char *)featureExtraTagString;
-
- paramValues[7] = (const char *)feature.adminLevel;
- paramValues[8] = (const char *)feature.houseNumber;
- paramValues[9] = (const char *)feature.rankAddress;
- paramValues[10] = (const char *)feature.rankSearch;
- paramValues[11] = (const char *)feature.geometry;
- res = PQexecPrepared(conn, "placex_insert", 12, paramValues, NULL, NULL, 0);
- if (PQresultStatus(res) != PGRES_COMMAND_OK)
- {
- fprintf(stderr, "index_placex: INSERT failed: %s", PQerrorMessage(conn));
- PQclear(res);
- exit(EXIT_FAILURE);
- }
- PQclear(res);
-
- for(i = 0; i < featureAddressLines; i++)
- {
- // insert into place_address
- paramValues[0] = (const char *)place_id;
- paramValues[1] = (const char *)featureAddress[i].distance;
- paramValues[2] = (const char *)featureAddress[i].type;
- paramValues[3] = (const char *)featureAddress[i].id;
- paramValues[4] = (const char *)featureAddress[i].key;
- paramValues[5] = (const char *)featureAddress[i].value;
- paramValues[6] = (const char *)featureAddress[i].isAddress;
- res = PQexecPrepared(conn, "place_addressline_insert", 7, paramValues, NULL, NULL, 0);
- if (PQresultStatus(res) != PGRES_COMMAND_OK)
- {
- fprintf(stderr, "place_addressline_insert: INSERT failed: %s", PQerrorMessage(conn));
- PQclear(res);
- exit(EXIT_FAILURE);
- }
- PQclear(res);
-
- xmlFree(featureAddress[i].type);
- xmlFree(featureAddress[i].id);
- xmlFree(featureAddress[i].key);
- xmlFree(featureAddress[i].value);
- xmlFree(featureAddress[i].distance);
- }
-
- if (featureNameLines)
- {
- paramValues[0] = (const char *)place_id;
- res = PQexecPrepared(conn, "search_name_insert", 1, paramValues, NULL, NULL, 0);
- if (PQresultStatus(res) != PGRES_COMMAND_OK)
- {
- fprintf(stderr, "search_name_insert: INSERT failed: %s", PQerrorMessage(conn));
- PQclear(res);
- exit(EXIT_FAILURE);
- }
- PQclear(res);
- }
-
- partionQueryName = xmlHashLookup2(partionTableTagsHash, feature.key, feature.value);
- if (partionQueryName)
- {
- // insert into partition table
- paramValues[0] = (const char *)place_id;
- paramValues[1] = (const char *)feature.geometry;
- res = PQexecPrepared(conn, partionQueryName, 2, paramValues, NULL, NULL, 0);
- if (PQresultStatus(res) != PGRES_COMMAND_OK)
- {
- fprintf(stderr, "%s: INSERT failed: %s", partionQueryName, PQerrorMessage(conn));
- PQclear(res);
- exit(EXIT_FAILURE);
- }
- PQclear(res);
-
- }
+ // Insert into placex
+ paramValues[0] = (const char *)place_id;
+ paramValues[1] = (const char *)feature.type;
+ paramValues[2] = (const char *)feature.id;
+ paramValues[3] = (const char *)feature.key;
+ paramValues[4] = (const char *)feature.value;
+
+ featureNameString[0] = 0;
+ if (featureNameLines)
+ {
+ namePos = 0;
+ lineTypeLen = 0;
+ lineValueLen = 0;
+ for (i = 0; i < featureNameLines; i++)
+ {
+ lineTypeLen = (int)strlen((char *) featureName[i].type);
+ lineValueLen = (int)strlen((char *) featureName[i].value);
+ if (namePos+lineTypeLen+lineValueLen+7 > MAX_FEATURENAMESTRING)
+ {
+ fprintf(stderr, "feature name too long: %s", (const char *)featureName[i].value);
+ break;
+ }
+ if (namePos) strcpy(featureNameString+(namePos++), ",");
+ strcpy(featureNameString+(namePos++), "\"");
+ strcpy(featureNameString+namePos, (char*) featureName[i].type);
+ namePos += lineTypeLen;
+ strcpy(featureNameString+namePos, "\"=>\"");
+ namePos += 4;
+ strcpy(featureNameString+namePos, (char *) featureName[i].value);
+ namePos += lineValueLen;
+ strcpy(featureNameString+(namePos++), "\"");
+
+ xmlFree(featureName[i].type);
+ xmlFree(featureName[i].value);
+ }
+ }
+ paramValues[5] = (const char *)featureNameString;
+
+ paramValues[6] = (const char *)feature.countryCode;
+
+ featureExtraTagString[0] = 0;
+ if (featureExtraTagLines)
+ {
+ namePos = 0;
+ lineTypeLen = 0;
+ lineValueLen = 0;
+ for (i = 0; i < featureExtraTagLines; i++)
+ {
+ lineTypeLen = strlen((char *) featureExtraTag[i].type);
+ lineValueLen = strlen((char *) featureExtraTag[i].value);
+ if (namePos+lineTypeLen+lineValueLen+7 > MAX_FEATUREEXTRATAGSTRING)
+ {
+ fprintf(stderr, "feature extra tag too long: %s", (const char *)featureExtraTag[i].value);
+ break;
+ }
+ if (namePos) strcpy(featureExtraTagString+(namePos++),",");
+ strcpy(featureExtraTagString+(namePos++), "\"");
+ strcpy(featureExtraTagString+namePos, (char *) featureExtraTag[i].type);
+ namePos += lineTypeLen;
+ strcpy(featureExtraTagString+namePos, "\"=>\"");
+ namePos += 4;
+ strcpy(featureExtraTagString+namePos, (char *) featureExtraTag[i].value);
+ namePos += lineValueLen;
+ strcpy(featureExtraTagString+(namePos++), "\"");
+
+ xmlFree(featureExtraTag[i].type);
+ xmlFree(featureExtraTag[i].value);
+ }
+ }
+ paramValues[7] = (const char *)featureExtraTagString;
+
+ if (xmlStrlen(feature.parentPlaceID) == 0)
+ paramValues[8] = "0";
+ else
+ paramValues[8] = (const char *)feature.parentPlaceID;
+
+ paramValues[9] = (const char *)feature.adminLevel;
+ paramValues[10] = (const char *)feature.houseNumber;
+ paramValues[11] = (const char *)feature.rankAddress;
+ paramValues[12] = (const char *)feature.rankSearch;
+ paramValues[13] = (const char *)feature.geometry;
+ if (strlen(paramValues[3]) && strlen(paramValues[13]))
+ {
+ if (verbose) fprintf(stderr, "placex_insert: %s\n", paramValues[0]);
+ res = PQexecPrepared(conn, "placex_insert", 14, paramValues, NULL, NULL, 0);
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ {
+ fprintf(stderr, "index_placex: INSERT failed: %s", PQerrorMessage(conn));
+ fprintf(stderr, "index_placex: INSERT failed: %s %s %s", paramValues[0], paramValues[1], paramValues[2]);
+ PQclear(res);
+ exit(EXIT_FAILURE);
+ }
+ PQclear(res);
+ }
+
+ for (i = 0; i < featureAddressLines; i++)
+ {
+ // insert into place_address
+ paramValues[0] = (const char *)place_id;
+ paramValues[1] = (const char *)featureAddress[i].distance;
+ if (paramValues[1] == NULL || strlen(paramValues[1]) == 0) paramValues[1] = "0";
+ paramValues[2] = (const char *)featureAddress[i].type;
+ paramValues[3] = (const char *)featureAddress[i].id;
+ paramValues[4] = (const char *)featureAddress[i].key;
+ paramValues[5] = (const char *)featureAddress[i].value;
+ paramValues[6] = (const char *)featureAddress[i].isAddress;
+ if (verbose) fprintf(stderr, "placex_insert: %s %s\n", paramValues[2], paramValues[3]);
+ res = PQexecPrepared(conn, "place_addressline_insert", 7, paramValues, NULL, NULL, 0);
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ {
+ fprintf(stderr, "place_addressline_insert: INSERT failed: %s", PQerrorMessage(conn));
+ fprintf(stderr, "(%s,%s,%s,%s,%s,%s,%s)",paramValues[0],paramValues[1],paramValues[2],paramValues[3],paramValues[4],paramValues[5],paramValues[6]);
+ PQclear(res);
+ exit(EXIT_FAILURE);
+ }
+ PQclear(res);
+
+ xmlFree(featureAddress[i].type);
+ xmlFree(featureAddress[i].id);
+ xmlFree(featureAddress[i].key);
+ xmlFree(featureAddress[i].value);
+ xmlFree(featureAddress[i].distance);
+ }
+
+ if (featureNameLines)
+ {
+ if (xmlStrlen(feature.parentPlaceID) > 0 && featureAddressLines == 0)
+ {
+ paramValues[0] = (const char *)place_id;
+ paramValues[1] = (const char *)feature.parentPlaceID;
+ if (verbose) fprintf(stderr, "search_name_from_parent_insert: INSERT %s %s\n", paramValues[0], paramValues[1]);
+ res = PQexecPrepared(conn, "search_name_from_parent_insert", 2, paramValues, NULL, NULL, 0);
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ {
+ fprintf(stderr, "search_name_from_parent_insert: INSERT failed: %s", PQerrorMessage(conn));
+ PQclear(res);
+ exit(EXIT_FAILURE);
+ }
+ PQclear(res);
+ }
+ else
+ {
+ paramValues[0] = (const char *)place_id;
+ if (verbose) fprintf(stderr, "search_name_insert: INSERT %s\n", paramValues[0]);
+ res = PQexecPrepared(conn, "search_name_insert", 1, paramValues, NULL, NULL, 0);
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ {
+ fprintf(stderr, "search_name_insert: INSERT failed: %s", PQerrorMessage(conn));
+ PQclear(res);
+ exit(EXIT_FAILURE);
+ }
+ PQclear(res);
+ }
+ }
+
+ partionQueryName = xmlHashLookup2(partionTableTagsHash, feature.key, feature.value);
+ if (partionQueryName)
+ {
+ // insert into partition table
+ paramValues[0] = (const char *)place_id;
+ paramValues[1] = (const char *)feature.geometry;
+ res = PQexecPrepared(conn, partionQueryName, 2, paramValues, NULL, NULL, 0);
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ {
+ fprintf(stderr, "%s: INSERT failed: %s", partionQueryName, PQerrorMessage(conn));
+ PQclear(res);
+ exit(EXIT_FAILURE);
+ }
+ PQclear(res);
+ }