Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker/postgresql/docker-compose.debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
context: ../..
dockerfile: docker/postgresql/Dockerfile.debug-no-optimization
container_name: cloudsync-postgres
command: postgres -c listen_addresses=*
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
Expand Down
4 changes: 3 additions & 1 deletion src/cloudsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,9 @@ int table_add_stmts (cloudsync_table_context *table, int ncols) {
if (rc != DBRES_OK) goto cleanup;

// precompile the insert/update local row statement
sql = cloudsync_memory_mprintf(SQL_CLOUDSYNC_UPSERT_RAW_COLVERSION, table->meta_ref, table->meta_ref);
sql = cloudsync_memory_mprintf(SQL_CLOUDSYNC_UPSERT_RAW_COLVERSION,
table->meta_ref, table->meta_ref,
table->meta_ref, table->meta_ref);
if (!sql) {rc = DBRES_NOMEM; goto cleanup;}
DEBUG_SQL("meta_row_insert_update_stmt: %s", sql);

Expand Down
5 changes: 4 additions & 1 deletion src/postgresql/sql_postgresql.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,10 @@ const char * const SQL_CLOUDSYNC_UPSERT_RAW_COLVERSION =
"INSERT INTO %s (pk, col_name, col_version, db_version, seq, site_id) "
"VALUES ($1, $2, $3, $4, $5, 0) "
"ON CONFLICT (pk, col_name) DO UPDATE SET "
"col_version = %s.col_version + 1, db_version = $6, seq = $7, site_id = 0;";
"col_version = CASE "
"WHEN (%s.col_version %% 2) = (excluded.col_version %% 2) THEN %s.col_version + 2 "
"ELSE %s.col_version + 1 END, "
"db_version = $6, seq = $7, site_id = 0;";

const char * const SQL_CLOUDSYNC_DELETE_PK_EXCEPT_COL =
"DELETE FROM %s WHERE pk = $1 AND col_name != '%s';"; // TODO: match SQLite delete semantics
Expand Down
5 changes: 4 additions & 1 deletion src/sqlite/sql_sqlite.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ const char * const SQL_CLOUDSYNC_UPSERT_RAW_COLVERSION =
"SELECT ?, ?, ?, ?, ?, 0 "
"WHERE 1 "
"ON CONFLICT DO UPDATE SET "
"col_version = \"%w\".col_version + 1, db_version = ?, seq = ?, site_id = 0;";
"col_version = CASE "
"WHEN (col_version %% 2) = (excluded.col_version %% 2) THEN col_version + 2 "
"ELSE col_version + 1 END, "
"db_version = ?, seq = ?, site_id = 0;";

const char * const SQL_CLOUDSYNC_DELETE_PK_EXCEPT_COL =
"DELETE FROM \"%w\" WHERE pk=? AND col_name!='%s';";
Expand Down
Loading
Loading