Skip to content

Commit 6507a41

Browse files
committed
Minor changes
1 parent 78c47e3 commit 6507a41

File tree

7 files changed

+30
-40
lines changed

7 files changed

+30
-40
lines changed

src/cloudsync.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ void cloudsync_rollback_hook (void *ctx);
5555

5656
// PAYLOAD
5757

58+
// available only on Desktop OS (no WASM, no mobile)
5859
//#ifdef CLOUDSYNC_DESKTOP_OS
5960
int cloudsync_payload_save (cloudsync_context *data, const char *payload_path, int *blob_size);
6061
//#endif
@@ -67,6 +68,8 @@ int cloudsync_payload_encode_final (cloudsync_payload_context *payload, cloud
6768
char *cloudsync_payload_blob (cloudsync_payload_context *payload, db_int64 *blob_size, db_int64 *nrows);
6869
size_t cloudsync_payload_context_size (size_t *header_size);
6970

71+
72+
7073
// END OK
7174

7275
// CLOUDSYNCTABLE CONTEXT

src/cloudsync_private.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
#include <stdbool.h>
1212
#include "cloudsync.h"
1313

14-
#ifndef SQLITE_CORE
15-
#include "sqlite3ext.h"
16-
#else
17-
#include "sqlite3.h"
18-
#endif
19-
2014
#define CLOUDSYNC_VALUE_NOTSET -1
2115
#define CLOUDSYNC_TOMBSTONE_VALUE "__[RIP]__"
2216
#define CLOUDSYNC_RLS_RESTRICTED_VALUE "__[RLS]__"

src/dbutils.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ typedef struct {
3333
} DATABASE_RESULT;
3434

3535
int dbutils_settings_check_version (sqlite3 *db, const char *version);
36+
bool table_add_to_context (db_t *db, cloudsync_context *data, table_algo algo, const char *table_name);
3637

3738
// MARK: - General -
3839

@@ -49,7 +50,6 @@ DATABASE_RESULT dbutils_exec (sqlite3_context *context, sqlite3 *db, const char
4950
// compile sql
5051
int rc = database_prepare(db, sql, (void **)&pstmt, 0);
5152
if (rc != SQLITE_OK) goto dbutils_exec_finalize;
52-
5353
// check bindings
5454
for (int i=0; i<count; ++i) {
5555
switch (types[i]) {
@@ -671,10 +671,8 @@ sqlite3_int64 dbutils_schema_version (sqlite3 *db) {
671671

672672
// MARK: - Settings -
673673

674-
int binary_comparison (int x, int y) {
675-
if (x == y) return 0;
676-
if (x > y) return 1;
677-
return -1;
674+
int dbutils_binary_comparison (int x, int y) {
675+
return (x == y) ? 0 : (x > y ? 1 : -1);
678676
}
679677

680678
char *dbutils_settings_get_value (sqlite3 *db, const char *key, char *buffer, size_t blen) {
@@ -777,9 +775,9 @@ int dbutils_settings_check_version (sqlite3 *db, const char *version) {
777775
if (count1 != 3 || count2 != 3) return -666;
778776

779777
int res = 0;
780-
if ((res = binary_comparison(major1, major2)) == 0) {
781-
if ((res = binary_comparison(minor1, minor2)) == 0) {
782-
return binary_comparison(patch1, patch2);
778+
if ((res = dbutils_binary_comparison(major1, major2)) == 0) {
779+
if ((res = dbutils_binary_comparison(minor1, minor2)) == 0) {
780+
return dbutils_binary_comparison(patch1, patch2);
783781
}
784782
}
785783

@@ -920,8 +918,6 @@ int dbutils_settings_load_callback (void *xdata, int ncols, char **values, char
920918
return 0;
921919
}
922920

923-
bool table_add_to_context (sqlite3 *db, cloudsync_context *data, table_algo algo, const char *table_name);
924-
925921
int dbutils_settings_table_load_callback (void *xdata, int ncols, char **values, char **names) {
926922
cloudsync_context *data = (cloudsync_context *)xdata;
927923
sqlite3 *db = cloudsync_db(data);
@@ -1049,9 +1045,6 @@ int dbutils_settings_init (sqlite3 *db, void *cloudsync_data, sqlite3_context *c
10491045
*/
10501046

10511047
return SQLITE_OK;
1052-
1053-
abort:
1054-
return rc;
10551048
}
10561049

10571050
int dbutils_update_schema_hash(sqlite3 *db, uint64_t *hash) {

src/dbutils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
#include "utils.h"
1313
#include "cloudsync_private.h"
1414

15+
#ifndef SQLITE_CORE
16+
#include "sqlite3ext.h"
17+
#else
18+
#include "sqlite3.h"
19+
#endif
20+
1521
#define CLOUDSYNC_SETTINGS_NAME "cloudsync_settings"
1622
#define CLOUDSYNC_SITEID_NAME "cloudsync_site_id"
1723
#define CLOUDSYNC_TABLE_SETTINGS_NAME "cloudsync_table_settings"

src/utils.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,17 @@ char *cloudsync_uuid_v7_stringify (uint8_t uuid[UUID_LEN], char value[UUID_STR_M
109109

110110
char *cloudsync_uuid_v7_string (char value[UUID_STR_MAXLEN], bool dash_format) {
111111
uint8_t uuid[UUID_LEN];
112-
if (cloudsync_uuid_v7(uuid) != 0) return NULL;
113112

113+
if (cloudsync_uuid_v7(uuid) != 0) return NULL;
114114
return cloudsync_uuid_v7_stringify(uuid, value, dash_format);
115115
}
116116

117117
int cloudsync_uuid_v7_compare (uint8_t value1[UUID_LEN], uint8_t value2[UUID_LEN]) {
118118
// reconstruct the timestamp by reversing the bit shifts and combining the bytes
119-
uint64_t t1 = ((uint64_t)value1[0] << 40) | ((uint64_t)value1[1] << 32) | ((uint64_t)value1[2] << 24) | ((uint64_t)value1[3] << 16) | ((uint64_t)value1[4] << 8) | ((uint64_t)value1[5]);
120-
uint64_t t2 = ((uint64_t)value2[0] << 40) | ((uint64_t)value2[1] << 32) | ((uint64_t)value2[2] << 24) | ((uint64_t)value2[3] << 16) | ((uint64_t)value2[4] << 8) | ((uint64_t)value2[5]);
119+
uint64_t t1 = ((uint64_t)value1[0] << 40) | ((uint64_t)value1[1] << 32) | ((uint64_t)value1[2] << 24) |
120+
((uint64_t)value1[3] << 16) | ((uint64_t)value1[4] << 8) | ((uint64_t)value1[5]);
121+
uint64_t t2 = ((uint64_t)value2[0] << 40) | ((uint64_t)value2[1] << 32) | ((uint64_t)value2[2] << 24) |
122+
((uint64_t)value2[3] << 16) | ((uint64_t)value2[4] << 8) | ((uint64_t)value2[5]);
121123

122124
if (t1 == t2) return memcmp(value1, value2, UUID_LEN);
123125
return (t1 > t2) ? 1 : -1;
@@ -154,10 +156,8 @@ char *cloudsync_string_dup (const char *str, bool lowercase) {
154156
}
155157

156158
int cloudsync_blob_compare(const char *blob1, size_t size1, const char *blob2, size_t size2) {
157-
if (size1 != size2) {
158-
return (int)(size1 - size2); // Blobs are different if sizes are different
159-
}
160-
return memcmp(blob1, blob2, size1); // Use memcmp for byte-by-byte comparison
159+
if (size1 != size2) return (int)(size1 - size2); // blobs are different if sizes are different
160+
return memcmp(blob1, blob2, size1); // use memcmp for byte-by-byte comparison
161161
}
162162

163163
void cloudsync_rowid_decode (db_int64 rowid, db_int64 *db_version, db_int64 *seq) {
@@ -184,13 +184,13 @@ char *cloudsync_string_replace_prefix(const char *input, char *prefix, char *rep
184184
size_t replacement_len = strlen(replacement);
185185

186186
if (strncmp(input, prefix, prefix_len) == 0) {
187-
// Allocate memory for new string
187+
// allocate memory for new string
188188
size_t input_len = strlen(input);
189189
size_t new_len = input_len - prefix_len + replacement_len;
190190
char *result = cloudsync_memory_alloc(new_len + 1); // +1 for null terminator
191191
if (!result) return NULL;
192192

193-
// Copy replacement and the rest of the input string
193+
// copy replacement and the rest of the input string
194194
strcpy(result, replacement);
195195
strcpy(result + replacement_len, input + prefix_len);
196196
return result;
@@ -201,7 +201,7 @@ char *cloudsync_string_replace_prefix(const char *input, char *prefix, char *rep
201201
}
202202

203203
/*
204-
Compute a normalized hash of a SQLite CREATE TABLE statement.
204+
Compute a normalized hash of a CREATE TABLE statement.
205205
206206
* Normalization:
207207
* - Skips comments (-- and / * )

src/utils.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,6 @@
2929
#define CLOUDSYNC_DESKTOP_OS 1
3030
#endif
3131

32-
#ifndef SQLITE_CORE
33-
#include "sqlite3ext.h"
34-
#else
35-
#include "sqlite3.h"
36-
#endif
37-
3832
#define CLOUDSYNC_DEBUG_FUNCTIONS 0
3933
#define CLOUDSYNC_DEBUG_DBFUNCTIONS 0
4034
#define CLOUDSYNC_DEBUG_SETTINGS 0
@@ -150,7 +144,7 @@ int cloudsync_blob_compare(const char *blob1, size_t size1, const char *blob2, s
150144

151145
void cloudsync_rowid_decode (db_int64 rowid, db_int64 *db_version, db_int64 *seq);
152146

153-
// available only on Desktop OS
147+
// available only on Desktop OS (no WASM, no mobile)
154148
#ifdef CLOUDSYNC_DESKTOP_OS
155149
bool cloudsync_file_delete (const char *path);
156150
char *cloudsync_file_read (const char *path, db_int64 *len);

test/unit.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int dbutils_settings_check_version (sqlite3 *db, const char *version);
4242
bool dbutils_migrate (sqlite3 *db);
4343
const char *vtab_opname_from_value (int value);
4444
int vtab_colname_is_legal (const char *name);
45-
int binary_comparison (int x, int y);
45+
int dbutils_binary_comparison (int x, int y);
4646
sqlite3 *do_create_database (void);
4747

4848
static int stdout_backup = -1; // Backup file descriptor for stdout
@@ -1918,11 +1918,11 @@ bool do_test_dbutils (void) {
19181918

19191919
int n1 = 1;
19201920
int n2 = 2;
1921-
cmp = binary_comparison(n1, n2);
1921+
cmp = dbutils_binary_comparison(n1, n2);
19221922
if (cmp != -1) goto finalize;
1923-
cmp = binary_comparison(n2, n1);
1923+
cmp = dbutils_binary_comparison(n2, n1);
19241924
if (cmp != 1) goto finalize;
1925-
cmp = binary_comparison(n1, n1);
1925+
cmp = dbutils_binary_comparison(n1, n1);
19261926
if (cmp != 0) goto finalize;
19271927

19281928
rc = SQLITE_OK;

0 commit comments

Comments
 (0)