Skip to content

Commit b829082

Browse files
committed
Merge branch 'main' into new-integration-test
2 parents 2a31f26 + 57e25fe commit b829082

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/network.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,46 +267,51 @@ static bool network_send_buffer (network_data *data, const char *endpoint, const
267267
}
268268

269269
int network_set_sqlite_result (sqlite3_context *context, NETWORK_RESULT *result) {
270-
int len = 0;
270+
int rc = 0;
271271
switch (result->code) {
272272
case CLOUDSYNC_NETWORK_OK:
273-
sqlite3_result_int(context, SQLITE_OK);
274-
len = 0;
273+
sqlite3_result_error_code(context, SQLITE_OK);
274+
rc = 0;
275275
break;
276276

277277
case CLOUDSYNC_NETWORK_ERROR:
278278
sqlite3_result_error(context, (result->buffer) ? result->buffer : "Memory error.", -1);
279279
sqlite3_result_error_code(context, SQLITE_ERROR);
280-
len = -1;
280+
rc = -1;
281281
break;
282282

283283
case CLOUDSYNC_NETWORK_BUFFER:
284+
sqlite3_result_error_code(context, SQLITE_OK);
284285
sqlite3_result_text(context, result->buffer, (int)result->blen, SQLITE_TRANSIENT);
285-
len = (int)result->blen;
286+
rc = (int)result->blen;
286287
break;
287288
}
288289

289290
if (result->buffer) cloudsync_memory_free(result->buffer);
290291

291-
return len;
292+
return rc;
292293
}
293294

294295
int network_download_changes (sqlite3_context *context, const char *download_url) {
295296
DEBUG_FUNCTION("network_download_changes");
296297

297-
int nrows = 0;
298298
network_data *data = (network_data *)cloudsync_get_auxdata(context);
299-
if (!data) {sqlite3_result_error(context, "Unable to retrieve CloudSync context.", -1); return -1;}
299+
if (!data) {
300+
sqlite3_result_error(context, "Unable to retrieve CloudSync context.", -1);
301+
return -1;
302+
}
300303

301304
NETWORK_RESULT result = network_receive_buffer(data, download_url, NULL, false, false, NULL, NULL);
305+
306+
int rc = SQLITE_OK;
302307
if (result.code == CLOUDSYNC_NETWORK_BUFFER) {
303-
nrows = cloudsync_payload_apply(context, result.buffer, (int)result.blen);
308+
rc = cloudsync_payload_apply(context, result.buffer, (int)result.blen);
304309
cloudsync_memory_free(result.buffer);
305310
} else {
306-
nrows = network_set_sqlite_result(context, &result);
311+
rc = network_set_sqlite_result(context, &result);
307312
}
308313

309-
return nrows;
314+
return rc;
310315
}
311316

312317
char *network_authentication_token(const char *key, const char *value) {
@@ -695,7 +700,8 @@ void cloudsync_network_sync (sqlite3_context *context, int wait_ms, int max_retr
695700
retries++;
696701
}
697702

698-
sqlite3_result_int(context, nrows);
703+
sqlite3_result_error_code(context, (nrows == -1) ? SQLITE_ERROR : SQLITE_OK);
704+
if (nrows >= 0) sqlite3_result_int(context, nrows);
699705
}
700706

701707
void cloudsync_network_sync0 (sqlite3_context *context, int argc, sqlite3_value **argv) {

0 commit comments

Comments
 (0)