@@ -171,7 +171,7 @@ const char * const SQL_SITEID_GETSET_ROWID_BY_SITEID =
171171 "RETURNING id;" ;
172172
173173const char * const SQL_BUILD_SELECT_NONPK_COLS_BY_ROWID =
174- "SELECT string_agg(quote_ident(column_name), ',') "
174+ "SELECT string_agg(quote_ident(column_name), ',' ORDER BY ordinal_position ) "
175175 "FROM information_schema.columns "
176176 "WHERE table_name = $1 AND column_name NOT IN ("
177177 "SELECT column_name FROM information_schema.key_column_usage "
@@ -381,15 +381,14 @@ const char * const SQL_DROP_CLOUDSYNC_TABLE =
381381
382382const char * const SQL_CLOUDSYNC_DELETE_COLS_NOT_IN_SCHEMA_OR_PKCOL =
383383 "DELETE FROM %s_cloudsync WHERE col_name NOT IN ("
384- "SELECT column_name FROM information_schema.columns WHERE table_name = $1 "
384+ "SELECT column_name FROM information_schema.columns WHERE table_name = '%s' "
385385 "UNION SELECT '%s'"
386386 ");" ;
387387
388388const char * const SQL_PRAGMA_TABLEINFO_PK_QUALIFIED_COLLIST_FMT =
389- "SELECT string_agg(quote_ident(column_name), ',') "
389+ "SELECT string_agg(quote_ident(column_name), ',' ORDER BY ordinal_position ) "
390390 "FROM information_schema.key_column_usage "
391- "WHERE table_name = '%s' AND constraint_name LIKE '%%_pkey' "
392- "ORDER BY ordinal_position;" ;
391+ "WHERE table_name = '%s' AND constraint_name LIKE '%%_pkey';" ;
393392
394393const char * const SQL_CLOUDSYNC_GC_DELETE_ORPHANED_PK =
395394 "DELETE FROM %s_cloudsync "
@@ -402,16 +401,14 @@ const char * const SQL_CLOUDSYNC_GC_DELETE_ORPHANED_PK =
402401const char * const SQL_PRAGMA_TABLEINFO_PK_COLLIST =
403402 "SELECT string_agg(quote_ident(column_name), ',') "
404403 "FROM information_schema.key_column_usage "
405- "WHERE table_name = %s AND constraint_name LIKE '%%_pkey' "
406- "ORDER BY ordinal_position;" ;
404+ "WHERE table_name = '%s' AND constraint_name LIKE '%%_pkey';" ;
407405
408406const char * const SQL_PRAGMA_TABLEINFO_PK_DECODE_SELECTLIST =
409407 "SELECT string_agg("
410- "'cloudsync_pk_decode(pk, ' || ordinal_position || ') AS ' || quote_ident(column_name), ','"
408+ "'cloudsync_pk_decode(pk, ' || ordinal_position || ') AS ' || quote_ident(column_name), ',' ORDER BY ordinal_position "
411409 ") "
412410 "FROM information_schema.key_column_usage "
413- "WHERE table_name = $1 AND constraint_name LIKE '%%_pkey' "
414- "ORDER BY ordinal_position;" ;
411+ "WHERE table_name = '%s' AND constraint_name LIKE '%%_pkey';" ;
415412
416413const char * const SQL_CLOUDSYNC_INSERT_MISSING_PKS_FROM_BASE_EXCEPT_SYNC =
417414 "SELECT cloudsync_insert('%s', %s) "
0 commit comments