|
17 | 17 | #include <math.h> |
18 | 18 |
|
19 | 19 | #include "cloudsync.h" |
| 20 | +#include "cloudsync_private.h" |
20 | 21 | #include "lz4.h" |
21 | 22 | #include "pk.h" |
22 | 23 | #include "vtab.h" |
@@ -145,6 +146,22 @@ typedef struct { |
145 | 146 |
|
146 | 147 | } cloudsync_table_context; |
147 | 148 |
|
| 149 | +struct cloudsync_pk_decode_bind_context { |
| 150 | + sqlite3_stmt *vm; |
| 151 | + char *tbl; |
| 152 | + int64_t tbl_len; |
| 153 | + const void *pk; |
| 154 | + int64_t pk_len; |
| 155 | + char *col_name; |
| 156 | + int64_t col_name_len; |
| 157 | + int64_t col_version; |
| 158 | + int64_t db_version; |
| 159 | + const void *site_id; |
| 160 | + int64_t site_id_len; |
| 161 | + int64_t cl; |
| 162 | + int64_t seq; |
| 163 | +}; |
| 164 | + |
148 | 165 | struct cloudsync_context { |
149 | 166 | char *libversion; |
150 | 167 | uint8_t site_id[UUID_LEN]; |
@@ -423,6 +440,31 @@ void cloudsync_set_auxdata (sqlite3_context *context, void *xdata) { |
423 | 440 | if (data) data->aux_data = xdata; |
424 | 441 | } |
425 | 442 |
|
| 443 | +// MARK: - PK Context - |
| 444 | + |
| 445 | +char *cloudsync_pk_context_tbl (cloudsync_pk_decode_bind_context *ctx, int64_t *tbl_len) { |
| 446 | + *tbl_len = ctx->tbl_len; |
| 447 | + return ctx->tbl; |
| 448 | +} |
| 449 | + |
| 450 | +void *cloudsync_pk_context_pk (cloudsync_pk_decode_bind_context *ctx, int64_t *pk_len) { |
| 451 | + *pk_len = ctx->pk_len; |
| 452 | + return (void *)ctx->pk; |
| 453 | +} |
| 454 | + |
| 455 | +char *cloudsync_pk_context_colname (cloudsync_pk_decode_bind_context *ctx, int64_t *colname_len) { |
| 456 | + *colname_len = ctx->col_name_len; |
| 457 | + return ctx->col_name; |
| 458 | +} |
| 459 | + |
| 460 | +int64_t cloudsync_pk_context_cl (cloudsync_pk_decode_bind_context *ctx) { |
| 461 | + return ctx->cl; |
| 462 | +} |
| 463 | + |
| 464 | +int64_t cloudsync_pk_context_dbversion (cloudsync_pk_decode_bind_context *ctx) { |
| 465 | + return ctx->db_version; |
| 466 | +} |
| 467 | + |
426 | 468 | // MARK: - Table Utils - |
427 | 469 |
|
428 | 470 | char *table_build_values_sql (sqlite3 *db, cloudsync_table_context *table) { |
@@ -1496,11 +1538,13 @@ void cloudsync_sync_key(cloudsync_context *data, const char *key, const char *va |
1496 | 1538 | } |
1497 | 1539 | } |
1498 | 1540 |
|
| 1541 | +#if 0 |
1499 | 1542 | void cloudsync_sync_table_key(cloudsync_context *data, const char *table, const char *column, const char *key, const char *value) { |
1500 | 1543 | DEBUG_SETTINGS("cloudsync_sync_table_key table: %s column: %s key: %s value: %s", table, column, key, value); |
1501 | | - // TODO: implement me |
| 1544 | + // Unused in this version |
1502 | 1545 | return; |
1503 | 1546 | } |
| 1547 | +#endif |
1504 | 1548 |
|
1505 | 1549 | int cloudsync_commit_hook (void *ctx) { |
1506 | 1550 | cloudsync_context *data = (cloudsync_context *)ctx; |
@@ -2834,8 +2878,8 @@ int cloudsync_init_internal (sqlite3_context *context, const char *table_name, c |
2834 | 2878 | // It is safe to call the following function multiple times, if there is nothing to update nothing will be changed. |
2835 | 2879 | // After an alter table, in contrast, all the cloudsync triggers, tables and stmts must be recreated. |
2836 | 2880 |
|
2837 | | - // sync algo with table |
2838 | | - cloudsync_sync_table_key(data, table_name, "*", CLOUDSYNC_KEY_ALGO, crdt_algo_name(algo_new)); |
| 2881 | + // sync algo with table (unused in this version) |
| 2882 | + // cloudsync_sync_table_key(data, table_name, "*", CLOUDSYNC_KEY_ALGO, crdt_algo_name(algo_new)); |
2839 | 2883 |
|
2840 | 2884 | // check triggers |
2841 | 2885 | dbutils_check_triggers(db, table_name, algo_new); |
|
0 commit comments