@@ -225,6 +225,15 @@ middle_pgsql_t::table_desc::exec_prepared(char const *stmt, char const *param,
225225 return pgsql_execPrepared (sql_conn, stmt, 1 , ¶m, expect);
226226}
227227
228+ pg_result_t
229+ middle_pgsql_t ::table_desc::exec_prepared(char const *stmt, osmid_t osm_id,
230+ ExecStatusType expect) const
231+ {
232+ char buffer[64 ];
233+ sprintf (buffer, " %" PRIdOSMID, osm_id);
234+ return exec_prepared (stmt, buffer, expect);
235+ }
236+
228237void middle_pgsql_t::table_desc::stop (bool droptemp, bool build_indexes)
229238{
230239 time_t start, end;
@@ -543,9 +552,7 @@ void middle_pgsql_t::local_nodes_delete(osmid_t osm_id)
543552 // Make sure we're out of copy mode */
544553 tables[NODE_TABLE].end_copy ();
545554
546- char buffer[64 ];
547- sprintf (buffer, " %" PRIdOSMID, osm_id);
548- tables[NODE_TABLE].exec_prepared (" delete_node" , buffer, PGRES_COMMAND_OK);
555+ tables[NODE_TABLE].exec_prepared (" delete_node" , osm_id, PGRES_COMMAND_OK);
549556}
550557
551558void middle_pgsql_t::nodes_delete (osmid_t osm_id)
@@ -568,7 +575,7 @@ void middle_pgsql_t::node_changed(osmid_t osm_id)
568575 tables[REL_TABLE].end_copy ();
569576
570577 char buffer[64 ];
571- sprintf ( buffer, " %" PRIdOSMID, osm_id );
578+ sprintf (buffer, " %" PRIdOSMID, osm_id);
572579
573580 // keep track of whatever ways and rels these nodes intersect
574581 // TODO: dont need to stop the copy above since we are only reading?
@@ -635,10 +642,8 @@ bool middle_pgsql_t::ways_get(osmid_t id, osmium::memory::Buffer &buffer) const
635642 // Make sure we're out of copy mode
636643 assert (tables[WAY_TABLE].copyMode == 0 );
637644
638- char tmp[16 ];
639- snprintf (tmp, sizeof (tmp), " %" PRIdOSMID, id);
645+ auto res = tables[WAY_TABLE].exec_prepared (" get_way" , id);
640646
641- auto res = tables[WAY_TABLE].exec_prepared (" get_way" , tmp);
642647 if (PQntuples (res.get ()) != 1 ) {
643648 return false ;
644649 }
@@ -728,9 +733,7 @@ void middle_pgsql_t::ways_delete(osmid_t osm_id)
728733 // Make sure we're out of copy mode */
729734 tables[WAY_TABLE].end_copy ();
730735
731- char buffer[64 ];
732- sprintf ( buffer, " %" PRIdOSMID, osm_id );
733- tables[WAY_TABLE].exec_prepared (" delete_way" , buffer, PGRES_COMMAND_OK);
736+ tables[WAY_TABLE].exec_prepared (" delete_way" , osm_id, PGRES_COMMAND_OK);
734737}
735738
736739void middle_pgsql_t::iterate_ways (middle_t ::pending_processor& pf)
@@ -757,12 +760,9 @@ void middle_pgsql_t::way_changed(osmid_t osm_id)
757760 // Make sure we're out of copy mode */
758761 tables[REL_TABLE].end_copy ();
759762
760- char buffer[64 ];
761- sprintf (buffer, " %" PRIdOSMID, osm_id);
762-
763763 // keep track of whatever rels this way intersects
764764 // TODO: dont need to stop the copy above since we are only reading?
765- auto res = tables[REL_TABLE].exec_prepared (" mark_rels_by_way" , buffer );
765+ auto res = tables[REL_TABLE].exec_prepared (" mark_rels_by_way" , osm_id );
766766 for (int i = 0 ; i < PQntuples (res.get ()); ++i) {
767767 char *end;
768768 osmid_t marked = strtoosmid (PQgetvalue (res.get (), i, 0 ), &end, 10 );
@@ -852,10 +852,7 @@ bool middle_pgsql_t::relations_get(osmid_t id, osmium::memory::Buffer &buffer) c
852852 // Make sure we're out of copy mode
853853 assert (tables[REL_TABLE].copyMode == 0 );
854854
855- char tmp[16 ];
856- snprintf (tmp, sizeof (tmp), " %" PRIdOSMID, id);
857-
858- auto res = tables[REL_TABLE].exec_prepared (" get_rel" , tmp);
855+ auto res = tables[REL_TABLE].exec_prepared (" get_rel" , id);
859856 // Fields are: members, tags, member_count */
860857
861858 if (PQntuples (res.get ()) != 1 ) {
@@ -918,13 +915,10 @@ void middle_pgsql_t::relation_changed(osmid_t osm_id)
918915 // Make sure we're out of copy mode */
919916 tables[REL_TABLE].end_copy ();
920917
921- char buffer[64 ];
922- sprintf ( buffer, " %" PRIdOSMID, osm_id );
923-
924918 // keep track of whatever ways and rels these nodes intersect
925919 // TODO: dont need to stop the copy above since we are only reading?
926920 // TODO: can we just mark the id without querying? the where clause seems intersect reltable.parts with the id
927- auto res = tables[REL_TABLE].exec_prepared (" mark_rels" , buffer );
921+ auto res = tables[REL_TABLE].exec_prepared (" mark_rels" , osm_id );
928922 for (int i = 0 ; i < PQntuples (res.get ()); ++i) {
929923 char *end;
930924 osmid_t marked = strtoosmid (PQgetvalue (res.get (), i, 0 ), &end, 10 );
@@ -937,10 +931,7 @@ idlist_t middle_pgsql_t::relations_using_way(osmid_t way_id) const
937931 // Make sure we're out of copy mode */
938932 assert (tables[REL_TABLE].copyMode == 0 );
939933
940- char buffer[64 ];
941- sprintf (buffer, " %" PRIdOSMID, way_id);
942-
943- auto result = tables[REL_TABLE].exec_prepared (" rels_using_way" , buffer);
934+ auto result = tables[REL_TABLE].exec_prepared (" rels_using_way" , way_id);
944935 const int ntuples = PQntuples (result.get ());
945936 idlist_t rel_ids;
946937 rel_ids.resize ((size_t ) ntuples);
0 commit comments