Skip to content

Commit eadf243

Browse files
committed
Fixed an issue with cloudsync_payload_load.
1 parent c45c84e commit eadf243

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/cloudsync.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2331,6 +2331,9 @@ void cloudsync_payload_save (sqlite3_context *context, int argc, sqlite3_value *
23312331
snprintf(buf, sizeof(buf), "%lld", new_seq);
23322332
dbutils_settings_set_key_value(db, context, CLOUDSYNC_KEY_SEND_SEQ, buf);
23332333
}
2334+
2335+
// returns blob size
2336+
sqlite3_result_int64(context, (sqlite3_int64)blob_size);
23342337
}
23352338

23362339
void cloudsync_payload_load (sqlite3_context *context, int argc, sqlite3_value **argv) {
@@ -2344,7 +2347,6 @@ void cloudsync_payload_load (sqlite3_context *context, int argc, sqlite3_value *
23442347

23452348
// retrieve full path to file
23462349
const char *path = (const char *)sqlite3_value_text(argv[0]);
2347-
file_delete(path);
23482350

23492351
size_t payload_size = 0;
23502352
char *payload = file_read(path, &payload_size);
@@ -2355,6 +2357,8 @@ void cloudsync_payload_load (sqlite3_context *context, int argc, sqlite3_value *
23552357

23562358
int nrows = cloudsync_payload_apply (context, payload, (int)payload_size);
23572359
if (payload) cloudsync_memory_free(payload);
2360+
2361+
// returns number of applied rows
23582362
if (nrows != -1) sqlite3_result_int(context, nrows);
23592363
}
23602364

@@ -3027,6 +3031,8 @@ void cloudsync_terminate (sqlite3_context *context, int argc, sqlite3_value **ar
30273031
// reset the site_id so the cloudsync_context_init will be executed again
30283032
// if any other cloudsync function is called after terminate
30293033
data->site_id[0] = 0;
3034+
3035+
sqlite3_result_int(context, 1);
30303036
}
30313037

30323038
// MARK: -
@@ -3187,8 +3193,18 @@ void cloudsync_init (sqlite3_context *context, const char *table, const char *al
31873193
}
31883194
}
31893195

3190-
if (rc == SQLITE_OK) dbutils_update_schema_hash(db, &data->schema_hash);
3191-
else sqlite3_exec(db, "ROLLBACK TO cloudsync_init; RELEASE cloudsync_init", NULL, NULL, NULL);
3196+
// in case of error, rollback transaction
3197+
if (rc != SQLITE_OK) {
3198+
sqlite3_exec(db, "ROLLBACK TO cloudsync_init; RELEASE cloudsync_init", NULL, NULL, NULL);
3199+
return;
3200+
}
3201+
3202+
dbutils_update_schema_hash(db, &data->schema_hash);
3203+
3204+
// returns site_id as TEXT
3205+
char buffer[UUID_STR_MAXLEN];
3206+
cloudsync_uuid_v7_stringify(data->site_id, buffer, false);
3207+
sqlite3_result_text(context, buffer, -1, NULL);
31923208
}
31933209

31943210
void cloudsync_init3 (sqlite3_context *context, int argc, sqlite3_value **argv) {

src/cloudsync.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
extern "C" {
2121
#endif
2222

23-
#define CLOUDSYNC_VERSION "0.8.34"
23+
#define CLOUDSYNC_VERSION "0.8.35"
2424

2525
int sqlite3_cloudsync_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
2626

0 commit comments

Comments
 (0)