Skip to content

Commit

Permalink
add crsql_config_set function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegn committed Dec 21, 2023
1 parent f4a958f commit a176f6d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 15 deletions.
12 changes: 11 additions & 1 deletion core/rs/core/src/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ fn bindgen_test_layout_crsql_ExtData() {
let ptr = UNINIT.as_ptr();
assert_eq!(
::core::mem::size_of::<crsql_ExtData>(),
128usize,
136usize,
concat!("Size of: ", stringify!(crsql_ExtData))
);
assert_eq!(
Expand Down Expand Up @@ -453,4 +453,14 @@ fn bindgen_test_layout_crsql_ExtData() {
stringify!(pSelectClockTablesStmt)
)
);
assert_eq!(
unsafe { ::core::ptr::addr_of!((*ptr).tieBreakSameColValue) as usize - ptr as usize },
128usize,
concat!(
"Offset of field: ",
stringify!(crsql_ExtData),
"::",
stringify!(tieBreakSameColValue)
)
);
}
30 changes: 30 additions & 0 deletions core/rs/core/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use sqlite::Context;
use sqlite_nostd as sqlite;
use sqlite_nostd::{ResultCode, Value};

use crate::c::crsql_ExtData;

pub extern "C" fn crsql_config_set(
ctx: *mut sqlite::context,
argc: i32,
argv: *mut *mut sqlite::value,
) {
let args = sqlite::args!(argc, argv);

let name = args[0].text();

match name {
"always-declare-winner" => {
let value = args[1].int() == 1;
let ext_data = ctx.user_data() as *mut crsql_ExtData;
unsafe { (*ext_data).tieBreakSameColValue = value };
}
_ => {
ctx.result_error("Unknown setting name");
ctx.result_error_code(ResultCode::ERROR);
return;
}
}

ctx.result_error_code(ResultCode::OK);
}
18 changes: 18 additions & 0 deletions core/rs/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod changes_vtab;
mod changes_vtab_read;
mod changes_vtab_write;
mod compare_values;
mod config;
mod consts;
mod create_cl_set_vtab;
mod create_crr;
Expand Down Expand Up @@ -52,6 +53,7 @@ use alter::crsql_compact_post_alter;
use automigrate::*;
use backfill::*;
use c::{crsql_freeExtData, crsql_newExtData};
use config::crsql_config_set;
use core::ffi::{c_int, c_void, CStr};
use create_crr::create_crr;
use db_version::{crsql_fill_db_version_if_needed, crsql_next_db_version};
Expand Down Expand Up @@ -153,6 +155,22 @@ pub extern "C" fn sqlite3_crsqlcore_init(
return null_mut();
}

let rc = db
.create_function_v2(
"crsql_config_set",
2,
sqlite::UTF8,
None,
Some(crsql_config_set),
None,
None,
None,
)
.unwrap_or(sqlite::ResultCode::ERROR);
if rc != ResultCode::OK {
return null_mut();
}

let rc = unpack_columns_vtab::create_module(db).unwrap_or(sqlite::ResultCode::ERROR);
if rc != ResultCode::OK {
return null_mut();
Expand Down
39 changes: 25 additions & 14 deletions core/rs/fractindex-core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a176f6d

Please sign in to comment.