Skip to content

Commit e768ead

Browse files
committed
feat: add function cloudsync_network_has_unsent_changes
1 parent 959d911 commit e768ead

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/network.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,20 @@ void cloudsync_network_set_apikey (sqlite3_context *context, int argc, sqlite3_v
622622

623623
// MARK: -
624624

625+
void cloudsync_network_has_unsent_changes (sqlite3_context *context, int argc, sqlite3_value **argv) {
626+
sqlite3 *db = sqlite3_context_db_handle(context);
627+
628+
char *sql = "SELECT max(db_version), hex(site_id) FROM cloudsync_changes() WHERE site_id == (SELECT site_id FROM cloudsync_site_id WHERE rowid=0)";
629+
int last_local_change = (int)dbutils_int_select(db, sql);
630+
if (last_local_change == 0) {
631+
sqlite3_result_int(context, 0);
632+
return;
633+
}
634+
635+
int sent_db_version = dbutils_settings_get_int_value(db, CLOUDSYNC_KEY_SEND_DBVERSION);
636+
sqlite3_result_int(context, (sent_db_version < last_local_change));
637+
}
638+
625639
void cloudsync_network_send_changes (sqlite3_context *context, int argc, sqlite3_value **argv) {
626640
DEBUG_FUNCTION("cloudsync_network_send_changes");
627641

@@ -789,6 +803,9 @@ int cloudsync_network_register (sqlite3 *db, char **pzErrMsg, void *ctx) {
789803
rc = dbutils_register_function(db, "cloudsync_network_set_apikey", cloudsync_network_set_apikey, 1, pzErrMsg, ctx, NULL);
790804
if (rc != SQLITE_OK) return rc;
791805

806+
rc = dbutils_register_function(db, "cloudsync_network_has_unsent_changes", cloudsync_network_has_unsent_changes, 0, pzErrMsg, ctx, NULL);
807+
if (rc != SQLITE_OK) return rc;
808+
792809
rc = dbutils_register_function(db, "cloudsync_network_send_changes", cloudsync_network_send_changes, 0, pzErrMsg, ctx, NULL);
793810
if (rc != SQLITE_OK) return rc;
794811

0 commit comments

Comments
 (0)