Skip to content

Commit 0830a37

Browse files
committed
Fixed SQLite unit test
1 parent 18d62ef commit 0830a37

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

src/cloudsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
extern "C" {
1818
#endif
1919

20-
#define CLOUDSYNC_VERSION "0.9.95"
20+
#define CLOUDSYNC_VERSION "0.9.96"
2121
#define CLOUDSYNC_MAX_TABLENAME_LEN 512
2222

2323
#define CLOUDSYNC_VALUE_NOTSET -1

src/sqlite/database_sqlite.c

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -250,22 +250,16 @@ char *sql_build_insert_missing_pks_query(const char *schema, const char *table_n
250250
const char *base_ref, const char *meta_ref) {
251251
UNUSED_PARAMETER(schema);
252252

253-
// Build pk_decode select list
254-
char *pkdecode = sql_build_pk_decode_selectlist_query(NULL, table_name);
255-
if (!pkdecode) {
256-
pkdecode = cloudsync_string_dup("cloudsync_pk_decode(pk, 1) AS rowid");
257-
if (!pkdecode) return NULL;
258-
}
259-
260-
// SQLite: Use EXCEPT (type-flexible)
261-
char *result = cloudsync_memory_mprintf(
253+
// SQLite: Use NOT EXISTS with cloudsync_pk_encode (same approach as PostgreSQL).
254+
// This avoids needing pk_decode select list which requires executing a query.
255+
return cloudsync_memory_mprintf(
262256
"SELECT cloudsync_insert('%q', %s) "
263-
"FROM (SELECT %s FROM \"%w\" EXCEPT SELECT %s FROM \"%w\");",
264-
table_name, pkvalues_identifiers, pkvalues_identifiers, base_ref, pkdecode, meta_ref
257+
"FROM \"%w\" "
258+
"WHERE NOT EXISTS ("
259+
" SELECT 1 FROM \"%w\" WHERE pk = cloudsync_pk_encode(%s)"
260+
");",
261+
table_name, pkvalues_identifiers, base_ref, meta_ref, pkvalues_identifiers
265262
);
266-
267-
cloudsync_memory_free(pkdecode);
268-
return result;
269263
}
270264

271265
// MARK: - PRIVATE -

0 commit comments

Comments
 (0)