void output_gazetteer_t::stop_copy(void) { /* Do we have a copy active? */ if (!copy_active) return; if (buffer.length() > 0) { pgsql_CopyData("place", Connection, buffer); buffer.clear(); } /* Terminate the copy */ if (PQputCopyEnd(Connection, nullptr) != 1) { std::cerr << "COPY_END for place failed: " << PQerrorMessage(Connection) << "\n"; util::exit_nicely(); } /* Check the result */ PGresult *res = PQgetResult(Connection); if (PQresultStatus(res) != PGRES_COMMAND_OK) { std::cerr << "COPY_END for place failed: " << PQerrorMessage(Connection) << "\n"; PQclear(res); util::exit_nicely(); } /* Discard the result */ PQclear(res); /* We no longer have an active copy */ copy_active = false; }
static void copy_error_data(const char *sql) { unsigned int sqlLen = strlen(sql); if (hLog) fprintf(hLog, "%s", sql); /* Make sure we have an active copy */ if (!CopyErrorActive) { pgsql_exec(ConnectionError, PGRES_COPY_IN, "COPY import_polygon_error (osm_type, osm_id, class, type, name, country_code, updated, errormessage, prevgeometry, newgeometry) FROM stdin;"); CopyErrorActive = 1; } /* If the combination of old and new data is too big, flush old data */ if (BufferErrorLen + sqlLen > BUFFER_SIZE - 10) { pgsql_CopyData("import_polygon_error", ConnectionError, BufferError); BufferErrorLen = 0; } /* * If new data by itself is too big, output it immediately, * otherwise just add it to the buffer. */ if (sqlLen > BUFFER_SIZE - 10) { pgsql_CopyData("import_polygon_error", ConnectionError, sql); sqlLen = 0; } else if (sqlLen > 0) { strcpy(BufferError + BufferErrorLen, sql); BufferErrorLen += sqlLen; sqlLen = 0; } /* If we have completed a line, output it */ if (BufferErrorLen > 0 && BufferError[BufferErrorLen-1] == '\n') { pgsql_CopyData("place", ConnectionError, BufferError); BufferErrorLen = 0; } return; }
static void copy_data(const char *sql) { unsigned int sqlLen = strlen(sql); /* Make sure we have an active copy */ if (!CopyActive) { pgsql_exec(Connection, PGRES_COPY_IN, "COPY place FROM STDIN"); CopyActive = 1; } /* If the combination of old and new data is too big, flush old data */ if (BufferLen + sqlLen > BUFFER_SIZE - 10) { pgsql_CopyData("place", Connection, Buffer); BufferLen = 0; } /* * If new data by itself is too big, output it immediately, * otherwise just add it to the buffer. */ if (sqlLen > BUFFER_SIZE - 10) { pgsql_CopyData("Place", Connection, sql); sqlLen = 0; } else if (sqlLen > 0) { strcpy(Buffer + BufferLen, sql); BufferLen += sqlLen; sqlLen = 0; } /* If we have completed a line, output it */ if (BufferLen > 0 && Buffer[BufferLen-1] == '\n') { pgsql_CopyData("place", Connection, Buffer); BufferLen = 0; } return; }
void output_gazetteer_t::copy_data(const char *sql) { unsigned int sqlLen = strlen(sql); /* Make sure we have an active copy */ if (!CopyActive) { pgsql_exec(Connection, PGRES_COPY_IN, "COPY place (osm_type, osm_id, class, type, name, admin_level, housenumber, street, addr_place, isin, postcode, country_code, extratags, geometry) FROM STDIN"); CopyActive = 1; } /* If the combination of old and new data is too big, flush old data */ if (BufferLen + sqlLen > BUFFER_SIZE - 10) { pgsql_CopyData("place", Connection, Buffer); BufferLen = 0; } /* * If new data by itself is too big, output it immediately, * otherwise just add it to the buffer. */ if (sqlLen > BUFFER_SIZE - 10) { pgsql_CopyData("Place", Connection, sql); sqlLen = 0; } else if (sqlLen > 0) { strcpy(Buffer + BufferLen, sql); BufferLen += sqlLen; sqlLen = 0; } /* If we have completed a line, output it */ if (BufferLen > 0 && Buffer[BufferLen-1] == '\n') { pgsql_CopyData("place", Connection, Buffer); BufferLen = 0; } return; }
inline void pgsql_CopyData(const char *context, PGconn *sql_conn, const std::string &sql) { pgsql_CopyData(context, sql_conn, sql.c_str(), sql.length()); }
inline void pgsql_CopyData(const char *context, PGconn *sql_conn, const char *sql) { pgsql_CopyData(context, sql_conn, sql, strlen(sql)); }