Skip to content

Commit 2496398

Browse files
committed
Add sqlite3 compile time options more similar to cpython
1 parent f364830 commit 2496398

File tree

3 files changed

+426
-401
lines changed

3 files changed

+426
-401
lines changed

graalpython/com.oracle.graal.python.cext/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,19 @@ set(SQLITE3_SRC
240240
"${SRC_DIR}/modules/_sqlite/util.c"
241241
)
242242
native_module("_sqlite3" TRUE "${SQLITE3_SRC}")
243+
# This combines the flags CPython uses on macOS and Windows, on Linux systems
244+
# it usually links against the system sqlite3 so we do not really know. See
245+
# https://github.com/python/cpython/issues/88017 for some reasons
243246
target_include_directories("_sqlite3" PUBLIC "${SRC_DIR}/modules/_sqlite/sqlite")
247+
target_compile_definitions("_sqlite3" PRIVATE
248+
SQLITE_ENABLE_MATH_FUNCTIONS
249+
SQLITE_ENABLE_FTS5
250+
SQLITE_ENABLE_FTS4
251+
SQLITE_ENABLE_FTS3_PARENTHESIS
252+
SQLITE_ENABLE_RTREE
253+
SQLITE_OMIT_AUTOINIT
254+
SQLITE_TCL=0
255+
)
244256

245257
set(LIBHACL_HEADERS
246258
# "${SRC_DIR}/modules/_hacl/include/krml/FStar_UInt128_Verified.h"

graalpython/com.oracle.graal.python.test/src/tests/test_sqlite3.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -49,3 +49,15 @@ def test_basic_functionality():
4949
rows = conn.execute("select sqlite_version()")
5050
assert len(next(rows)[0]) >= 5
5151
conn.close()
52+
53+
54+
def test_fts5_works():
55+
import sqlite3
56+
conn = sqlite3.connect(':memory:')
57+
conn.execute("CREATE VIRTUAL TABLE IF NOT EXISTS your_table USING fts5(column1, column2)")
58+
conn.execute("CREATE VIRTUAL TABLE IF NOT EXISTS your_table USING fts4(column1, column2)")
59+
conn.execute("CREATE VIRTUAL TABLE IF NOT EXISTS your_table USING fts3(column1, column2)")
60+
conn.execute("CREATE VIRTUAL TABLE IF NOT EXISTS your_table USING rtree(column1, column2)")
61+
sqpi = next(conn.execute("SELECT pi()"))[0]
62+
assert 3.14 == float(f'{sqpi:.2f}'), sqpi
63+
conn.close()

0 commit comments

Comments
 (0)