Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ if (USE_TURSO)
include_directories(src/main/tursoLibs/include)
endif()

# Apply library-default SQLite flags (driven by package.json toggles such as
# performanceMode, fts5 and rtree) FIRST, then user-supplied sqliteFlags. clang's
# last-define-wins rule lets the user override any default when both define the
# same macro. This mirrors iOS, where the podspec appends sqliteFlags after the
# optimizedCflags. Use add_compile_options (not add_definitions) because CMake
# sorts COMPILE_DEFINITIONS alphabetically before emitting them, which would
# break the override ordering for pairs like -DSQLITE_FOO=1 vs -DSQLITE_FOO=0.
separate_arguments(DEFAULT_SQLITE_FLAGS_LIST UNIX_COMMAND "${DEFAULT_SQLITE_FLAGS}")
separate_arguments(SQLITE_FLAGS_LIST UNIX_COMMAND "${SQLITE_FLAGS}")

add_definitions(
${SQLITE_FLAGS_LIST}
)
add_compile_options(${DEFAULT_SQLITE_FLAGS_LIST})
add_compile_options(${SQLITE_FLAGS_LIST})

add_library(
${PACKAGE_NAME}
Expand Down
26 changes: 17 additions & 9 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ if(!tokenizers.isEmpty()) {
println "[OP-SQLITE] Tokenizers enabled. Detected tokenizers: " + tokenizers
}

// Build the list of library-default SQLite compile flags driven by package.json
// toggles. These are emitted via CMake add_definitions() BEFORE the user-supplied
// sqliteFlags, so that user flags take precedence when both define the same macro
// (clang's last-define-wins). This matches the iOS podspec behavior where
// optimizedCflags are appended before sqliteFlags.
def defaultSqliteFlags = []
if (performanceMode) {
defaultSqliteFlags += ["-DSQLITE_DQS=0", "-DSQLITE_DEFAULT_MEMSTATUS=0", "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", "-DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1", "-DSQLITE_MAX_EXPR_DEPTH=0", "-DSQLITE_OMIT_DEPRECATED=1", "-DSQLITE_OMIT_PROGRESS_CALLBACK=1", "-DSQLITE_OMIT_SHARED_CACHE=1", "-DSQLITE_USE_ALLOCA=1", "-DSQLITE_THREADSAFE=1"]
}
if (enableFTS5) {
defaultSqliteFlags += "-DSQLITE_ENABLE_FTS5=1"
}
if (enableRtree) {
defaultSqliteFlags += "-DSQLITE_ENABLE_RTREE=1"
}

android {
namespace "com.op.sqlite"

Expand Down Expand Up @@ -159,15 +175,6 @@ android {
cFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
cppFlags += "-DOP_SQLITE_USE_CRSQLITE=1"
}
if(performanceMode) {
cFlags += ["-DSQLITE_DQS=0", "-DSQLITE_DEFAULT_MEMSTATUS=0", "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1", "-DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1", "-DSQLITE_MAX_EXPR_DEPTH=0", "-DSQLITE_OMIT_DEPRECATED=1", "-DSQLITE_OMIT_PROGRESS_CALLBACK=1", "-DSQLITE_OMIT_SHARED_CACHE=1", "-DSQLITE_USE_ALLOCA=1", "-DSQLITE_THREADSAFE=1"]
}
if(enableFTS5) {
cFlags += ["-DSQLITE_ENABLE_FTS5=1"]
}
if(enableRtree) {
cFlags += ["-DSQLITE_ENABLE_RTREE=1"]
}
if(useSqliteVec) {
cFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
cppFlags += "-DOP_SQLITE_USE_SQLITE_VEC=1"
Expand All @@ -192,6 +199,7 @@ android {
cppFlags "-O3 -frtti -fexceptions -Wall -fstack-protector-all"
abiFilters(*reactNativeArchitectures())
arguments "-DANDROID_STL=c++_shared",
"-DDEFAULT_SQLITE_FLAGS='${defaultSqliteFlags.join(' ')}'",
"-DSQLITE_FLAGS='$sqliteFlags'",
"-DUSE_SQLCIPHER=${useSQLCipher ? 1 : 0}",
"-DUSE_CRSQLITE=${useCRSQLite ? 1 : 0}",
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ All keys are optional, only turn on the features you want:
- `crsqlite` is an extension that allows replication to a server backed sqlite database copy. [Repo here](https://github.com/vlcn-io/cr-sqlite).
- `performanceMode` turns on certain compilation flags that make sqlite speedier at the cost of disabling some features. You should almost always turn this on, but test your app thoroughly.
- `iosSqlite` uses the embedded iOS version from sqlite, which saves disk space but may use an older version and cannot load extensions as Apple disables it due to security concerns. On Android SQLite is always compiled from source as each vendor messes with sqlite or uses outdated versions.
- `sqliteFlags` allows you to pass your own compilation flags to further disable/enable features and extensions. It follows the C flag format: `-D[YOUR_FLAG]=[YOUR_VALUE]`. If you are running large queries on large databases sometimes on Android devices you might get a IO exception. You can disable temporary files by using adding the `"-DSQLITE_TEMP_STORE=2"` flag.
- `sqliteFlags` allows you to pass your own compilation flags to further disable/enable features and extensions. It follows the C flag format: `-D[YOUR_FLAG]=[YOUR_VALUE]`. If you are running large queries on large databases sometimes on Android devices you might get a IO exception. You can disable temporary files by using adding the `"-DSQLITE_TEMP_STORE=2"` flag. Flags listed here are applied AFTER the library defaults (including those added by `performanceMode`), so they override any default with the same name on both iOS and Android. For example, setting `"sqliteFlags": "-DSQLITE_DQS=3"` re-enables double-quoted string literals even when `performanceMode` is on.
- `fts5` enables the full [text search extension](https://www.sqlite.org/fts5.html).
- `tokenizers` allows you to write your own C tokenizers. Read more in the corresponding section in this documentation.
- `rtree` enables the [rtree extension](https://www.sqlite.org/rtree.html)
Expand Down
Loading