mirror of https://github.com/sysown/proxysql
Introduce canonical proxy_sqlite3 symbol TU; update lib Makefile; remove MAIN_PROXY_SQLITE3 from main.cpp
parent
7a7872f078
commit
8dc4246bdc
@ -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;
|
||||
@ -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"
|
||||
@ -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 <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// List of expected RAG tables
|
||||
const std::vector<std::string> 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<std::string> 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;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue