diff --git a/core/rs/bundle/Cargo.lock b/core/rs/bundle/Cargo.lock index e1f4bdb01..8b964eb60 100644 --- a/core/rs/bundle/Cargo.lock +++ b/core/rs/bundle/Cargo.lock @@ -121,9 +121,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libloading" diff --git a/core/rs/core/Cargo.lock b/core/rs/core/Cargo.lock index 244a76aa7..d2006ae23 100644 --- a/core/rs/core/Cargo.lock +++ b/core/rs/core/Cargo.lock @@ -105,9 +105,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.151" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" [[package]] name = "libloading" diff --git a/core/rs/core/src/c.rs b/core/rs/core/src/c.rs index b93686035..a053b8882 100644 --- a/core/rs/core/src/c.rs +++ b/core/rs/core/src/c.rs @@ -67,7 +67,7 @@ pub struct crsql_ExtData { pub pSetSiteIdOrdinalStmt: *mut sqlite::stmt, pub pSelectSiteIdOrdinalStmt: *mut sqlite::stmt, pub pSelectClockTablesStmt: *mut sqlite::stmt, - pub tieBreakSameColValue: ::core::ffi::c_int, + pub mergeEqualValues: ::core::ffi::c_int, } #[repr(C)] @@ -454,13 +454,13 @@ fn bindgen_test_layout_crsql_ExtData() { ) ); assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).tieBreakSameColValue) as usize - ptr as usize }, + unsafe { ::std::ptr::addr_of!((*ptr).mergeEqualValues) as usize - ptr as usize }, 128usize, concat!( "Offset of field: ", stringify!(crsql_ExtData), "::", - stringify!(tieBreakSameColValue) + stringify!(mergeEqualValues) ) ); } diff --git a/core/rs/core/src/changes_vtab_write.rs b/core/rs/core/src/changes_vtab_write.rs index e4fca3d52..3f26b07ab 100644 --- a/core/rs/core/src/changes_vtab_write.rs +++ b/core/rs/core/src/changes_vtab_write.rs @@ -93,7 +93,7 @@ fn did_cid_win( let local_value = col_val_stmt.column_value(0)?; let mut ret = crsql_compare_sqlite_values(insert_val, local_value); reset_cached_stmt(col_val_stmt.stmt)?; - if ret == 0 && unsafe { (*ext_data).tieBreakSameColValue == 1 } { + if ret == 0 && unsafe { (*ext_data).mergeEqualValues == 1 } { // values are the same (ret == 0) and the option to tie break on site_id is true ret = unsafe { let my_site_id = core::slice::from_raw_parts((*ext_data).siteId, 16); diff --git a/core/rs/core/src/config.rs b/core/rs/core/src/config.rs index 81961a863..e53fc3336 100644 --- a/core/rs/core/src/config.rs +++ b/core/rs/core/src/config.rs @@ -21,7 +21,7 @@ pub extern "C" fn crsql_config_set( MERGE_EQUAL_VALUES => { let value = args[1]; let ext_data = ctx.user_data() as *mut crsql_ExtData; - unsafe { (*ext_data).tieBreakSameColValue = value.int() }; + unsafe { (*ext_data).mergeEqualValues = value.int() }; value } _ => { @@ -74,7 +74,7 @@ pub extern "C" fn crsql_config_get( match name { MERGE_EQUAL_VALUES => { let ext_data = ctx.user_data() as *mut crsql_ExtData; - ctx.result_int(unsafe { (*ext_data).tieBreakSameColValue }); + ctx.result_int(unsafe { (*ext_data).mergeEqualValues }); } _ => { ctx.result_error("Unknown setting name"); diff --git a/core/rs/core/src/lib.rs b/core/rs/core/src/lib.rs index 57f38b6c5..0aafa90fb 100644 --- a/core/rs/core/src/lib.rs +++ b/core/rs/core/src/lib.rs @@ -214,7 +214,7 @@ pub extern "C" fn sqlite3_crsqlcore_init( let ext_data = unsafe { crsql_newExtData(db, site_id_buffer as *mut c_char) }; if ext_data.is_null() { - sqlite::free(site_id_buffer as *mut c_void); + // no need to free the site id buffer here, this is cleaned up already. return null_mut(); } @@ -486,6 +486,7 @@ pub extern "C" fn sqlite3_crsqlcore_init( ) .unwrap_or(sqlite::ResultCode::ERROR); if rc != ResultCode::OK { + unsafe { crsql_freeExtData(ext_data) }; return null_mut(); } @@ -502,6 +503,7 @@ pub extern "C" fn sqlite3_crsqlcore_init( ) .unwrap_or(sqlite::ResultCode::ERROR); if rc != ResultCode::OK { + unsafe { crsql_freeExtData(ext_data) }; return null_mut(); } diff --git a/core/rs/core/src/sha.rs b/core/rs/core/src/sha.rs index df78688cf..496cb4ccf 100644 --- a/core/rs/core/src/sha.rs +++ b/core/rs/core/src/sha.rs @@ -1,2 +1,2 @@ // The sha of the commit that this version of crsqlite was built from. -pub const SHA: &'static str = ""; +pub const SHA: &'static str = "3a01980562615001d765eec61e3ed58147a93f93"; diff --git a/core/src/ext-data.c b/core/src/ext-data.c index db82feba0..f8715f4f9 100644 --- a/core/src/ext-data.c +++ b/core/src/ext-data.c @@ -1,6 +1,7 @@ #include "ext-data.h" #include +#include #include "consts.h" @@ -11,6 +12,8 @@ void crsql_drop_table_info_vec(crsql_ExtData *pExtData); crsql_ExtData *crsql_newExtData(sqlite3 *db, unsigned char *siteIdBuffer) { crsql_ExtData *pExtData = sqlite3_malloc(sizeof *pExtData); + pExtData->siteId = siteIdBuffer; + pExtData->pPragmaSchemaVersionStmt = 0; int rc = sqlite3_prepare_v3(db, "PRAGMA schema_version", -1, SQLITE_PREPARE_PERSISTENT, @@ -47,7 +50,6 @@ crsql_ExtData *crsql_newExtData(sqlite3 *db, unsigned char *siteIdBuffer) { pExtData->pragmaSchemaVersion = -1; pExtData->pragmaDataVersion = -1; pExtData->pragmaSchemaVersionForTableInfos = -1; - pExtData->siteId = siteIdBuffer; pExtData->pDbVersionStmt = 0; pExtData->tableInfos = 0; pExtData->rowsImpacted = 0; @@ -67,14 +69,16 @@ crsql_ExtData *crsql_newExtData(sqlite3 *db, unsigned char *siteIdBuffer) { } // set defaults! - pExtData->tieBreakSameColValue = 0; + pExtData->mergeEqualValues = 0; while (sqlite3_step(pStmt) == SQLITE_ROW) { - const unsigned char *name = sqlite3_column_text(pStmt, 1); - if (sqlite3_stricmp(name, "merge-equal-values")) { - if (sqlite3_column_type(pStmt, 2) == SQLITE_INTEGER) { - const int value = sqlite3_column_int(pStmt, 2); - pExtData->tieBreakSameColValue = value; + const unsigned char *name = sqlite3_column_text(pStmt, 0); + int colType = sqlite3_column_type(pStmt, 1); + + if (strcmp("merge-equal-values", (char *)name) == 0) { + if (colType == SQLITE_INTEGER) { + const int value = sqlite3_column_int(pStmt, 1); + pExtData->mergeEqualValues = value; } else { // broken setting... crsql_freeExtData(pExtData); diff --git a/core/src/ext-data.h b/core/src/ext-data.h index c7379de47..c4ff801d0 100644 --- a/core/src/ext-data.h +++ b/core/src/ext-data.h @@ -43,7 +43,7 @@ struct crsql_ExtData { sqlite3_stmt *pSelectSiteIdOrdinalStmt; sqlite3_stmt *pSelectClockTablesStmt; - int tieBreakSameColValue; + int mergeEqualValues; }; crsql_ExtData *crsql_newExtData(sqlite3 *db, unsigned char *siteIdBuffer); diff --git a/py/correctness/tests/test_config.py b/py/correctness/tests/test_config.py index 012680816..3291000d2 100644 --- a/py/correctness/tests/test_config.py +++ b/py/correctness/tests/test_config.py @@ -1,8 +1,10 @@ -from crsql_correctness import connect, close, get_site_id -import pprint +from crsql_correctness import connect, close +import pathlib def test_config_merge_equal_values(): - db = connect(":memory:") + dbfile = "./config.db" + pathlib.Path(dbfile).unlink(missing_ok=True) + db = connect(dbfile) value = db.execute("SELECT crsql_config_set('merge-equal-values', 1);").fetchone() assert (value == (1,)) db.commit() @@ -11,4 +13,13 @@ def test_config_merge_equal_values(): assert (value == (1,)) value = db.execute("SELECT crsql_config_get('merge-equal-values');").fetchone() - assert (value == (1,)) \ No newline at end of file + assert (value == (1,)) + + close(db) + db = connect(dbfile) + + value = db.execute("SELECT value FROM crsql_master WHERE key = 'config.merge-equal-values'").fetchone() + assert (value == (1,)) + + value = db.execute("SELECT crsql_config_get('merge-equal-values')").fetchone() + assert (value == (1,))