From 8dc4246bdcddbe3fa133e5749f23f2a1e29b5b49 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Tue, 20 Jan 2026 20:34:35 +0000 Subject: [PATCH] Introduce canonical proxy_sqlite3 symbol TU; update lib Makefile; remove MAIN_PROXY_SQLITE3 from main.cpp --- include/sqlite3db.h | 15 +++++ lib/Anomaly_Detector.cpp | 50 +++++++-------- lib/Makefile | 2 +- lib/proxy_sqlite3_symbols.cpp | 48 +++++++++++++++ lib/sqlite3db.cpp | 28 ++++++++- src/main.cpp | 3 +- test/build_rag_test.sh | 51 ---------------- test/test_rag_schema.cpp | 111 ---------------------------------- 8 files changed, 118 insertions(+), 190 deletions(-) create mode 100644 lib/proxy_sqlite3_symbols.cpp delete mode 100755 test/build_rag_test.sh delete mode 100644 test/test_rag_schema.cpp diff --git a/include/sqlite3db.h b/include/sqlite3db.h index bdd01fc9b..d546c26d5 100644 --- a/include/sqlite3db.h +++ b/include/sqlite3db.h @@ -28,12 +28,20 @@ extern int (*proxy_sqlite3_bind_int)(sqlite3_stmt*, int, int); extern int (*proxy_sqlite3_bind_int64)(sqlite3_stmt*, int, sqlite3_int64); extern int (*proxy_sqlite3_bind_null)(sqlite3_stmt*, int); extern int (*proxy_sqlite3_bind_text)(sqlite3_stmt*,int,const char*,int,void(*)(void*)); +extern int (*proxy_sqlite3_bind_blob)(sqlite3_stmt*, int, const void*, int, void(*)(void*)); extern const char *(*proxy_sqlite3_column_name)(sqlite3_stmt*, int N); extern const unsigned char *(*proxy_sqlite3_column_text)(sqlite3_stmt*, int iCol); extern int (*proxy_sqlite3_column_bytes)(sqlite3_stmt*, int iCol); extern int (*proxy_sqlite3_column_type)(sqlite3_stmt*, int iCol); extern int (*proxy_sqlite3_column_count)(sqlite3_stmt *pStmt); extern int (*proxy_sqlite3_column_int)(sqlite3_stmt*, int iCol); +extern sqlite3_int64 (*proxy_sqlite3_column_int64)(sqlite3_stmt*, int iCol); +extern double (*proxy_sqlite3_column_double)(sqlite3_stmt*, int iCol); +extern sqlite3_int64 (*proxy_sqlite3_last_insert_rowid)(sqlite3*); +extern const char *(*proxy_sqlite3_errstr)(int); +extern sqlite3* (*proxy_sqlite3_db_handle)(sqlite3_stmt*); +extern int (*proxy_sqlite3_enable_load_extension)(sqlite3*, int); +extern int (*proxy_sqlite3_auto_extension)(void(*)(void)); extern const char *(*proxy_sqlite3_errmsg)(sqlite3*); extern int (*proxy_sqlite3_finalize)(sqlite3_stmt *pStmt); extern int (*proxy_sqlite3_reset)(sqlite3_stmt *pStmt); @@ -77,12 +85,19 @@ int (*proxy_sqlite3_bind_int)(sqlite3_stmt*, int, int); int (*proxy_sqlite3_bind_int64)(sqlite3_stmt*, int, sqlite3_int64); int (*proxy_sqlite3_bind_null)(sqlite3_stmt*, int); int (*proxy_sqlite3_bind_text)(sqlite3_stmt*,int,const char*,int,void(*)(void*)); +int (*proxy_sqlite3_bind_blob)(sqlite3_stmt*, int, const void*, int, void(*)(void*)); +sqlite3_int64 (*proxy_sqlite3_column_int64)(sqlite3_stmt*, int iCol); +double (*proxy_sqlite3_column_double)(sqlite3_stmt*, int iCol); +sqlite3_int64 (*proxy_sqlite3_last_insert_rowid)(sqlite3*); +const char *(*proxy_sqlite3_errstr)(int); +sqlite3* (*proxy_sqlite3_db_handle)(sqlite3_stmt*); const char *(*proxy_sqlite3_column_name)(sqlite3_stmt*, int N); const unsigned char *(*proxy_sqlite3_column_text)(sqlite3_stmt*, int iCol); int (*proxy_sqlite3_column_bytes)(sqlite3_stmt*, int iCol); int (*proxy_sqlite3_column_type)(sqlite3_stmt*, int iCol); int (*proxy_sqlite3_column_count)(sqlite3_stmt *pStmt); int (*proxy_sqlite3_column_int)(sqlite3_stmt*, int iCol); +int (*proxy_sqlite3_auto_extension)(void(*)(void)); const char *(*proxy_sqlite3_errmsg)(sqlite3*); int (*proxy_sqlite3_finalize)(sqlite3_stmt *pStmt); int (*proxy_sqlite3_reset)(sqlite3_stmt *pStmt); diff --git a/lib/Anomaly_Detector.cpp b/lib/Anomaly_Detector.cpp index 0da65e93c..46c949126 100644 --- a/lib/Anomaly_Detector.cpp +++ b/lib/Anomaly_Detector.cpp @@ -449,24 +449,24 @@ AnomalyResult Anomaly_Detector::check_embedding_similarity(const std::string& qu // Execute search sqlite3* db = vector_db->get_db(); sqlite3_stmt* stmt = NULL; - int rc = sqlite3_prepare_v2(db, search, -1, &stmt, NULL); + int rc = (*proxy_sqlite3_prepare_v2)(db, search, -1, &stmt, NULL); if (rc != SQLITE_OK) { - proxy_debug(PROXY_DEBUG_ANOMALY, 3, "Embedding search prepare failed: %s", sqlite3_errmsg(db)); + proxy_debug(PROXY_DEBUG_ANOMALY, 3, "Embedding search prepare failed: %s", (*proxy_sqlite3_errmsg)(db)); return result; } // Check if any threat patterns matched - rc = sqlite3_step(stmt); + rc = (*proxy_sqlite3_step)(stmt); if (rc == SQLITE_ROW) { // Found similar threat pattern result.is_anomaly = true; // Extract pattern info - const char* pattern_name = reinterpret_cast(sqlite3_column_text(stmt, 0)); - const char* pattern_type = reinterpret_cast(sqlite3_column_text(stmt, 1)); - int severity = sqlite3_column_int(stmt, 2); - double distance = sqlite3_column_double(stmt, 3); + const char* pattern_name = reinterpret_cast((*proxy_sqlite3_column_text)(stmt, 0)); + const char* pattern_type = reinterpret_cast((*proxy_sqlite3_column_text)(stmt, 1)); + int severity = (*proxy_sqlite3_column_int)(stmt, 2); + double distance = (*proxy_sqlite3_column_double)(stmt, 3); // Calculate risk score based on severity and similarity // - Base score from severity (1-10) -> 0.1-1.0 @@ -752,21 +752,21 @@ int Anomaly_Detector::add_threat_pattern(const std::string& pattern_name, "(pattern_name, pattern_type, query_example, embedding, severity) " "VALUES (?, ?, ?, ?, ?)"; - int rc = sqlite3_prepare_v2(db, insert, -1, &stmt, NULL); + int rc = (*proxy_sqlite3_prepare_v2)(db, insert, -1, &stmt, NULL); if (rc != SQLITE_OK) { - proxy_error("Anomaly: Failed to prepare pattern insert: %s\n", sqlite3_errmsg(db)); + proxy_error("Anomaly: Failed to prepare pattern insert: %s\n", (*proxy_sqlite3_errmsg)(db)); return -1; } // Bind values - sqlite3_bind_text(stmt, 1, pattern_name.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 2, pattern_type.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 3, query_example.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_blob(stmt, 4, embedding.data(), embedding.size() * sizeof(float), SQLITE_TRANSIENT); - sqlite3_bind_int(stmt, 5, severity); + (*proxy_sqlite3_bind_text)(stmt, 1, pattern_name.c_str(), -1, SQLITE_TRANSIENT); + (*proxy_sqlite3_bind_text)(stmt, 2, pattern_type.c_str(), -1, SQLITE_TRANSIENT); + (*proxy_sqlite3_bind_text)(stmt, 3, query_example.c_str(), -1, SQLITE_TRANSIENT); + (*proxy_sqlite3_bind_blob)(stmt, 4, embedding.data(), embedding.size() * sizeof(float), SQLITE_TRANSIENT); + (*proxy_sqlite3_bind_int)(stmt, 5, severity); // Execute insert - rc = sqlite3_step(stmt); + rc = (*proxy_sqlite3_step)(stmt); if (rc != SQLITE_DONE) { proxy_error("Anomaly: Failed to insert pattern: %s\n", sqlite3_errmsg(db)); sqlite3_finalize(stmt); @@ -776,7 +776,7 @@ int Anomaly_Detector::add_threat_pattern(const std::string& pattern_name, sqlite3_finalize(stmt); // Get the inserted rowid - sqlite3_int64 rowid = sqlite3_last_insert_rowid(db); + sqlite3_int64 rowid = (*proxy_sqlite3_last_insert_rowid)(db); // Update virtual table (sqlite-vec needs explicit rowid insertion) char update_vec[256]; @@ -819,17 +819,17 @@ std::string Anomaly_Detector::list_threat_patterns() { return "[]"; } - while (sqlite3_step(stmt) == SQLITE_ROW) { + while ((*proxy_sqlite3_step)(stmt) == SQLITE_ROW) { json pattern; - pattern["id"] = sqlite3_column_int64(stmt, 0); - const char* name = reinterpret_cast(sqlite3_column_text(stmt, 1)); - const char* type = reinterpret_cast(sqlite3_column_text(stmt, 2)); - const char* example = reinterpret_cast(sqlite3_column_text(stmt, 3)); + pattern["id"] = (*proxy_sqlite3_column_int64)(stmt, 0); + const char* name = reinterpret_cast((*proxy_sqlite3_column_text)(stmt, 1)); + const char* type = reinterpret_cast((*proxy_sqlite3_column_text)(stmt, 2)); + const char* example = reinterpret_cast((*proxy_sqlite3_column_text)(stmt, 3)); pattern["pattern_name"] = name ? name : ""; pattern["pattern_type"] = type ? type : ""; pattern["query_example"] = example ? example : ""; - pattern["severity"] = sqlite3_column_int(stmt, 4); - pattern["created_at"] = sqlite3_column_int64(stmt, 5); + pattern["severity"] = (*proxy_sqlite3_column_int)(stmt, 4); + pattern["created_at"] = (*proxy_sqlite3_column_int64)(stmt, 5); patterns.push_back(pattern); } @@ -915,7 +915,7 @@ std::string Anomaly_Detector::get_statistics() { int rc = sqlite3_prepare_v2(db, count_query, -1, &stmt, NULL); if (rc == SQLITE_OK) { - rc = sqlite3_step(stmt); + rc = (*proxy_sqlite3_step)(stmt); if (rc == SQLITE_ROW) { stats["threat_patterns_count"] = sqlite3_column_int(stmt, 0); } @@ -928,7 +928,7 @@ std::string Anomaly_Detector::get_statistics() { if (rc == SQLITE_OK) { json by_type = json::object(); - while (sqlite3_step(stmt) == SQLITE_ROW) { + while ((*proxy_sqlite3_step)(stmt) == SQLITE_ROW) { const char* type = reinterpret_cast(sqlite3_column_text(stmt, 0)); int count = sqlite3_column_int(stmt, 1); if (type) { diff --git a/lib/Makefile b/lib/Makefile index 1d7af9872..d1a066011 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -63,7 +63,7 @@ MYCXXFLAGS := $(STDCPP) $(MYCFLAGS) $(PSQLCH) $(ENABLE_EPOLL) default: libproxysql.a .PHONY: default -_OBJ_CXX := ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo sqlite3db.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo MySQL_Query_Processor.oo PgSQL_Query_Processor.oo ProxySQL_Admin.oo ProxySQL_Config.oo ProxySQL_Restapi.oo MySQL_Monitor.oo MySQL_Logger.oo thread.oo MySQL_PreparedStatement.oo ProxySQL_Cluster.oo ClickHouse_Authentication.oo ClickHouse_Server.oo ProxySQL_Statistics.oo Chart_bundle_js.oo ProxySQL_HTTP_Server.oo ProxySQL_RESTAPI_Server.oo font-awesome.min.css.oo main-bundle.min.css.oo MySQL_Variables.oo c_tokenizer.oo proxysql_utils.oo proxysql_coredump.oo proxysql_sslkeylog.oo \ +_OBJ_CXX := ProxySQL_GloVars.oo network.oo debug.oo configfile.oo Query_Cache.oo SpookyV2.oo MySQL_Authentication.oo gen_utils.oo sqlite3db.oo mysql_connection.oo MySQL_HostGroups_Manager.oo mysql_data_stream.oo MySQL_Thread.oo MySQL_Session.oo MySQL_Protocol.oo mysql_backend.oo Query_Processor.oo MySQL_Query_Processor.oo PgSQL_Query_Processor.oo ProxySQL_Admin.oo ProxySQL_Config.oo ProxySQL_Restapi.oo MySQL_Monitor.oo MySQL_Logger.oo thread.oo MySQL_PreparedStatement.oo ProxySQL_Cluster.oo ClickHouse_Authentication.oo ClickHouse_Server.oo ProxySQL_Statistics.oo Chart_bundle_js.oo ProxySQL_HTTP_Server.oo ProxySQL_RESTAPI_Server.oo font-awesome.min.css.oo main-bundle.min.css.oo MySQL_Variables.oo c_tokenizer.oo proxysql_utils.oo proxysql_coredump.oo proxysql_sslkeylog.oo proxy_sqlite3_symbols.oo \ sha256crypt.oo \ BaseSrvList.oo BaseHGC.oo Base_HostGroups_Manager.oo \ QP_rule_text.oo QP_query_digest_stats.oo \ diff --git a/lib/proxy_sqlite3_symbols.cpp b/lib/proxy_sqlite3_symbols.cpp new file mode 100644 index 000000000..1b51047d3 --- /dev/null +++ b/lib/proxy_sqlite3_symbols.cpp @@ -0,0 +1,48 @@ +#include "sqlite3.h" + +/* + * This translation unit defines the storage for the proxy_sqlite3_* + * function pointers. Exactly one TU must define these symbols to + * avoid multiple-definition issues; other TUs should include + * include/sqlite3db.h which declares them as extern. + */ + +int (*proxy_sqlite3_bind_double)(sqlite3_stmt*, int, double) = sqlite3_bind_double; +int (*proxy_sqlite3_bind_int)(sqlite3_stmt*, int, int) = sqlite3_bind_int; +int (*proxy_sqlite3_bind_int64)(sqlite3_stmt*, int, sqlite3_int64) = sqlite3_bind_int64; +int (*proxy_sqlite3_bind_null)(sqlite3_stmt*, int) = sqlite3_bind_null; +int (*proxy_sqlite3_bind_text)(sqlite3_stmt*,int,const char*,int,void(*)(void*)) = sqlite3_bind_text; +int (*proxy_sqlite3_bind_blob)(sqlite3_stmt*, int, const void*, int, void(*)(void*)) = sqlite3_bind_blob; +const char *(*proxy_sqlite3_column_name)(sqlite3_stmt*, int) = sqlite3_column_name; +const unsigned char *(*proxy_sqlite3_column_text)(sqlite3_stmt*, int) = sqlite3_column_text; +int (*proxy_sqlite3_column_bytes)(sqlite3_stmt*, int) = sqlite3_column_bytes; +int (*proxy_sqlite3_column_type)(sqlite3_stmt*, int) = sqlite3_column_type; +int (*proxy_sqlite3_column_count)(sqlite3_stmt*) = sqlite3_column_count; +int (*proxy_sqlite3_column_int)(sqlite3_stmt*, int) = sqlite3_column_int; +sqlite3_int64 (*proxy_sqlite3_column_int64)(sqlite3_stmt*, int) = sqlite3_column_int64; +double (*proxy_sqlite3_column_double)(sqlite3_stmt*, int) = sqlite3_column_double; +sqlite3_int64 (*proxy_sqlite3_last_insert_rowid)(sqlite3*) = sqlite3_last_insert_rowid; +const char *(*proxy_sqlite3_errstr)(int) = sqlite3_errstr; +sqlite3* (*proxy_sqlite3_db_handle)(sqlite3_stmt*) = sqlite3_db_handle; +int (*proxy_sqlite3_enable_load_extension)(sqlite3*, int) = sqlite3_enable_load_extension; +/* Some platforms may expose sqlite3_enable_load_extension as a macro or different symbol; provide a weak alias to help the linker. */ +extern "C" int proxy_sqlite3_enable_load_extension_alias(sqlite3* db, int onoff) __attribute__((weak)); +int proxy_sqlite3_enable_load_extension_alias(sqlite3* db, int onoff) { return sqlite3_enable_load_extension(db, onoff); } +int (*proxy_sqlite3_auto_extension)(void(*)(void)) = sqlite3_auto_extension; +const char *(*proxy_sqlite3_errmsg)(sqlite3*) = sqlite3_errmsg; +int (*proxy_sqlite3_finalize)(sqlite3_stmt *) = sqlite3_finalize; +int (*proxy_sqlite3_reset)(sqlite3_stmt *) = sqlite3_reset; +int (*proxy_sqlite3_clear_bindings)(sqlite3_stmt*) = sqlite3_clear_bindings; +int (*proxy_sqlite3_close_v2)(sqlite3*) = sqlite3_close_v2; +int (*proxy_sqlite3_get_autocommit)(sqlite3*) = sqlite3_get_autocommit; +void (*proxy_sqlite3_free)(void*) = sqlite3_free; +int (*proxy_sqlite3_status)(int, int*, int*, int) = sqlite3_status; +int (*proxy_sqlite3_status64)(int, long long*, long long*, int) = sqlite3_status64; +int (*proxy_sqlite3_changes)(sqlite3*) = sqlite3_changes; +long long (*proxy_sqlite3_total_changes64)(sqlite3*) = sqlite3_total_changes64; +int (*proxy_sqlite3_step)(sqlite3_stmt*) = sqlite3_step; +int (*proxy_sqlite3_config)(int, ...) = sqlite3_config; +int (*proxy_sqlite3_shutdown)(void) = sqlite3_shutdown; +int (*proxy_sqlite3_prepare_v2)(sqlite3*, const char*, int, sqlite3_stmt**, const char**) = sqlite3_prepare_v2; +int (*proxy_sqlite3_open_v2)(const char*, sqlite3**, int, const char*) = sqlite3_open_v2; +int (*proxy_sqlite3_exec)(sqlite3*, const char*, int (*)(void*,int,char**,char**), void*, char**) = sqlite3_exec; diff --git a/lib/sqlite3db.cpp b/lib/sqlite3db.cpp index 37d7f3cb1..760174299 100644 --- a/lib/sqlite3db.cpp +++ b/lib/sqlite3db.cpp @@ -1,5 +1,8 @@ #include "proxysql.h" +#include "sqlite3.h" #include "cpp.h" + + //#include "SpookyV2.h" #include #include @@ -1001,12 +1004,20 @@ void SQLite3DB::LoadPlugin(const char *plugin_name) { proxy_sqlite3_bind_int64 = NULL; proxy_sqlite3_bind_null = NULL; proxy_sqlite3_bind_text = NULL; + proxy_sqlite3_bind_blob = NULL; proxy_sqlite3_column_name = NULL; proxy_sqlite3_column_text = NULL; proxy_sqlite3_column_bytes = NULL; proxy_sqlite3_column_type = NULL; proxy_sqlite3_column_count = NULL; proxy_sqlite3_column_int = NULL; + proxy_sqlite3_column_int64 = NULL; + proxy_sqlite3_column_double = NULL; + proxy_sqlite3_last_insert_rowid = NULL; + proxy_sqlite3_errstr = NULL; + proxy_sqlite3_db_handle = NULL; + proxy_sqlite3_enable_load_extension = NULL; + proxy_sqlite3_auto_extension = NULL; proxy_sqlite3_errmsg = NULL; proxy_sqlite3_finalize = NULL; proxy_sqlite3_reset = NULL; @@ -1081,12 +1092,20 @@ void SQLite3DB::LoadPlugin(const char *plugin_name) { proxy_sqlite3_bind_int64 = sqlite3_bind_int64; proxy_sqlite3_bind_null = sqlite3_bind_null; proxy_sqlite3_bind_text = sqlite3_bind_text; + proxy_sqlite3_bind_blob = sqlite3_bind_blob; proxy_sqlite3_column_name = sqlite3_column_name; proxy_sqlite3_column_text = sqlite3_column_text; proxy_sqlite3_column_bytes = sqlite3_column_bytes; - proxy_sqlite3_column_type = sqlite3_column_type; + proxy_sqlite3_column_type = sqlite3_column_type; /* signature matches */ proxy_sqlite3_column_count = sqlite3_column_count; proxy_sqlite3_column_int = sqlite3_column_int; + proxy_sqlite3_column_int64 = sqlite3_column_int64; + proxy_sqlite3_column_double = sqlite3_column_double; + proxy_sqlite3_last_insert_rowid = sqlite3_last_insert_rowid; + proxy_sqlite3_errstr = sqlite3_errstr; + proxy_sqlite3_db_handle = sqlite3_db_handle; + proxy_sqlite3_enable_load_extension = sqlite3_enable_load_extension; + proxy_sqlite3_auto_extension = sqlite3_auto_extension; proxy_sqlite3_errmsg = sqlite3_errmsg; proxy_sqlite3_finalize = sqlite3_finalize; proxy_sqlite3_reset = sqlite3_reset; @@ -1117,6 +1136,13 @@ void SQLite3DB::LoadPlugin(const char *plugin_name) { assert(proxy_sqlite3_column_type); assert(proxy_sqlite3_column_count); assert(proxy_sqlite3_column_int); + assert(proxy_sqlite3_column_int64); + assert(proxy_sqlite3_column_double); + assert(proxy_sqlite3_last_insert_rowid); + assert(proxy_sqlite3_errstr); + assert(proxy_sqlite3_db_handle); + assert(proxy_sqlite3_enable_load_extension); + assert(proxy_sqlite3_auto_extension); assert(proxy_sqlite3_errmsg); assert(proxy_sqlite3_finalize); assert(proxy_sqlite3_reset); diff --git a/src/main.cpp b/src/main.cpp index 9defb9ed8..c9494198f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,7 @@ -#define MAIN_PROXY_SQLITE3 #include "../deps/json/json.hpp" + + using json = nlohmann::json; #define PROXYJSON diff --git a/test/build_rag_test.sh b/test/build_rag_test.sh deleted file mode 100755 index ac69d6b96..000000000 --- a/test/build_rag_test.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -# -# build_rag_test.sh - Simple build script for RAG test -# - -set -e - -# Check if we're in the right directory -if [ ! -f "test_rag_schema.cpp" ]; then - echo "ERROR: test_rag_schema.cpp not found in current directory" - exit 1 -fi - -# Try to find ProxySQL source directory -PROXYSQL_SRC=$(pwd) -if [ ! -f "${PROXYSQL_SRC}/include/proxysql.h" ]; then - # Try to find it in parent directories - PROXYSQL_SRC=$(while [ ! -f ./include/proxysql.h ]; do cd .. 2>/dev/null || exit 1; if [ "$(pwd)" = "/" ]; then exit 1; fi; done; pwd) -fi - -if [ ! -f "${PROXYSQL_SRC}/include/proxysql.h" ]; then - echo "ERROR: Could not find ProxySQL source directory" - exit 1 -fi - -echo "Found ProxySQL source at: ${PROXYSQL_SRC}" - -# Set up include paths -IDIRS="-I${PROXYSQL_SRC}/include \ - -I${PROXYSQL_SRC}/deps/jemalloc/jemalloc/include/jemalloc \ - -I${PROXYSQL_SRC}/deps/mariadb-client-library/mariadb_client/include \ - -I${PROXYSQL_SRC}/deps/libconfig/libconfig/lib \ - -I${PROXYSQL_SRC}/deps/re2/re2 \ - -I${PROXYSQL_SRC}/deps/sqlite3/sqlite3 \ - -I${PROXYSQL_SRC}/deps/pcre/pcre \ - -I${PROXYSQL_SRC}/deps/clickhouse-cpp/clickhouse-cpp \ - -I${PROXYSQL_SRC}/deps/clickhouse-cpp/clickhouse-cpp/contrib/absl \ - -I${PROXYSQL_SRC}/deps/libmicrohttpd/libmicrohttpd \ - -I${PROXYSQL_SRC}/deps/libmicrohttpd/libmicrohttpd/src/include \ - -I${PROXYSQL_SRC}/deps/libhttpserver/libhttpserver/src \ - -I${PROXYSQL_SRC}/deps/libinjection/libinjection/src \ - -I${PROXYSQL_SRC}/deps/curl/curl/include \ - -I${PROXYSQL_SRC}/deps/libev/libev \ - -I${PROXYSQL_SRC}/deps/json" - -# Compile the test -echo "Compiling test_rag_schema..." -g++ -std=c++11 -ggdb ${IDIRS} test_rag_schema.cpp -o test_rag_schema -pthread -ldl - -echo "SUCCESS: test_rag_schema compiled successfully" -echo "Run with: ./test_rag_schema" \ No newline at end of file diff --git a/test/test_rag_schema.cpp b/test/test_rag_schema.cpp deleted file mode 100644 index 6b5fcc793..000000000 --- a/test/test_rag_schema.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/** - * @file test_rag_schema.cpp - * @brief Test RAG database schema creation - * - * Simple test to verify that RAG tables are created correctly in the vector database. - */ - -#include "sqlite3db.h" -#include -#include -#include - -// List of expected RAG tables -const std::vector RAG_TABLES = { - "rag_sources", - "rag_documents", - "rag_chunks", - "rag_fts_chunks", - "rag_vec_chunks", - "rag_sync_state" -}; - -// List of expected RAG views -const std::vector RAG_VIEWS = { - "rag_chunk_view" -}; - -int main() { - // Initialize SQLite database - SQLite3DB* db = new SQLite3DB(); - - // Open the default vector database path - const char* db_path = "/var/lib/proxysql/ai_features.db"; - std::cout << "Testing RAG schema in database: " << db_path << std::endl; - - // Try to open the database - if (db->open((char*)db_path) != 0) { - std::cerr << "ERROR: Failed to open database at " << db_path << std::endl; - delete db; - return 1; - } - - std::cout << "SUCCESS: Database opened successfully" << std::endl; - - // Check if RAG tables exist - bool all_tables_exist = true; - for (const std::string& table_name : RAG_TABLES) { - std::string query = "SELECT name FROM sqlite_master WHERE type='table' AND name='" + table_name + "'"; - char* error = nullptr; - int cols = 0; - int affected_rows = 0; - SQLite3_result* result = db->execute_statement(query.c_str(), &error, &cols, &affected_rows); - - if (error) { - std::cerr << "ERROR: SQL error for table " << table_name << ": " << error << std::endl; - sqlite3_free(error); - all_tables_exist = false; - if (result) delete result; - continue; - } - - if (result && result->rows_count() > 0) { - std::cout << "SUCCESS: Table '" << table_name << "' exists" << std::endl; - } else { - std::cerr << "ERROR: Table '" << table_name << "' does not exist" << std::endl; - all_tables_exist = false; - } - - if (result) delete result; - } - - // Check if RAG views exist - bool all_views_exist = true; - for (const std::string& view_name : RAG_VIEWS) { - std::string query = "SELECT name FROM sqlite_master WHERE type='view' AND name='" + view_name + "'"; - char* error = nullptr; - int cols = 0; - int affected_rows = 0; - SQLite3_result* result = db->execute_statement(query.c_str(), &error, &cols, &affected_rows); - - if (error) { - std::cerr << "ERROR: SQL error for view " << view_name << ": " << error << std::endl; - sqlite3_free(error); - all_views_exist = false; - if (result) delete result; - continue; - } - - if (result && result->rows_count() > 0) { - std::cout << "SUCCESS: View '" << view_name << "' exists" << std::endl; - } else { - std::cerr << "ERROR: View '" << view_name << "' does not exist" << std::endl; - all_views_exist = false; - } - - if (result) delete result; - } - - // Clean up - db->close(); - delete db; - - // Final result - if (all_tables_exist && all_views_exist) { - std::cout << std::endl << "SUCCESS: All RAG schema objects exist!" << std::endl; - return 0; - } else { - std::cerr << std::endl << "ERROR: Some RAG schema objects are missing!" << std::endl; - return 1; - } -} \ No newline at end of file