@ -5,7 +5,7 @@
* Simple test to verify that RAG tables are created correctly in the vector database .
* Simple test to verify that RAG tables are created correctly in the vector database .
*/
*/
# include "sqlite3 db .h"
# include "sqlite3 .h"
# include <iostream>
# include <iostream>
# include <vector>
# include <vector>
# include <string>
# include <string>
@ -25,18 +25,26 @@ const std::vector<std::string> RAG_VIEWS = {
" rag_chunk_view "
" rag_chunk_view "
} ;
} ;
static int callback ( void * data , int argc , char * * argv , char * * azColName ) {
int * count = ( int * ) data ;
( * count ) + + ;
return 0 ;
}
int main ( ) {
int main ( ) {
// Initialize SQLite database
sqlite3 * db ;
SQLite3DB * db = new SQLite3DB ( ) ;
char * zErrMsg = 0 ;
int rc ;
// Open the default vector database path
// Open the default vector database path
const char * db_path = " /var/lib/proxysql/ai_features.db " ;
const char * db_path = " /var/lib/proxysql/ai_features.db " ;
std : : cout < < " Testing RAG schema in database: " < < db_path < < std : : endl ;
std : : cout < < " Testing RAG schema in database: " < < db_path < < std : : endl ;
// Try to open the database
// Try to open the database
if ( db - > open ( ( char * ) db_path ) ! = 0 ) {
rc = sqlite3_open ( db_path , & db ) ;
std : : cerr < < " ERROR: Failed to open database at " < < db_path < < std : : endl ;
if ( rc ) {
delete db ;
std : : cerr < < " ERROR: Can't open database: " < < sqlite3_errmsg ( db ) < < std : : endl ;
sqlite3_close ( db ) ;
return 1 ;
return 1 ;
}
}
@ -46,66 +54,49 @@ int main() {
bool all_tables_exist = true ;
bool all_tables_exist = true ;
for ( const std : : string & table_name : RAG_TABLES ) {
for ( const std : : string & table_name : RAG_TABLES ) {
std : : string query = " SELECT name FROM sqlite_master WHERE type='table' AND name=' " + table_name + " ' " ;
std : : string query = " SELECT name FROM sqlite_master WHERE type='table' AND name=' " + table_name + " ' " ;
char * error = nullptr ;
int count = 0 ;
int cols = 0 ;
rc = sqlite3_exec ( db , query . c_str ( ) , callback , & count , & zErrMsg ) ;
int affected_rows = 0 ;
SQLite3_result * result = db - > execute_statement ( query . c_str ( ) , & error , & cols , & affected_rows ) ;
if ( error ) {
if ( rc ! = SQLITE_OK ) {
std : : cerr < < " ERROR: SQL error for table " < < table_name < < " : " < < error < < std : : endl ;
std : : cerr < < " ERROR: SQL error : " < < zErrMsg < < std : : endl ;
sqlite3_free ( error ) ;
sqlite3_free ( zErrMsg ) ;
all_tables_exist = false ;
all_tables_exist = false ;
if ( result ) delete result ;
} else if ( count = = 0 ) {
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 ;
std : : cerr < < " ERROR: Table ' " < < table_name < < " ' does not exist " < < std : : endl ;
all_tables_exist = false ;
all_tables_exist = false ;
} else {
std : : cout < < " SUCCESS: Table ' " < < table_name < < " ' exists " < < std : : endl ;
}
}
if ( result ) delete result ;
}
}
// Check if RAG views exist
// Check if RAG views exist
bool all_views_exist = true ;
bool all_views_exist = true ;
for ( const std : : string & view_name : RAG_VIEWS ) {
for ( const std : : string & view_name : RAG_VIEWS ) {
std : : string query = " SELECT name FROM sqlite_master WHERE type='view' AND name=' " + view_name + " ' " ;
std : : string query = " SELECT name FROM sqlite_master WHERE type='view' AND name=' " + view_name + " ' " ;
char * error = nullptr ;
int count = 0 ;
int cols = 0 ;
rc = sqlite3_exec ( db , query . c_str ( ) , callback , & count , & zErrMsg ) ;
int affected_rows = 0 ;
SQLite3_result * result = db - > execute_statement ( query . c_str ( ) , & error , & cols , & affected_rows ) ;
if ( error ) {
if ( rc ! = SQLITE_OK ) {
std : : cerr < < " ERROR: SQL error for view " < < view_name < < " : " < < error < < std : : endl ;
std : : cerr < < " ERROR: SQL error : " < < zErrMsg < < std : : endl ;
sqlite3_free ( error ) ;
sqlite3_free ( zErrMsg ) ;
all_views_exist = false ;
all_views_exist = false ;
if ( result ) delete result ;
} else if ( count = = 0 ) {
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 ;
std : : cerr < < " ERROR: View ' " < < view_name < < " ' does not exist " < < std : : endl ;
all_views_exist = false ;
all_views_exist = false ;
} else {
std : : cout < < " SUCCESS: View ' " < < view_name < < " ' exists " < < std : : endl ;
}
}
if ( result ) delete result ;
}
}
// Clean up
// Clean up
db - > close ( ) ;
sqlite3_close ( db ) ;
delete db ;
// Final result
// Final result
if ( all_tables_exist & & all_views_exist ) {
if ( all_tables_exist & & all_views_exist ) {
std : : cout < < std : : endl < < " SUCCESS: All RAG schema objects exist ! " < < std : : endl ;
std : : cout < < " SUCCESS: All RAG schema objects exist " < < std : : endl ;
return 0 ;
return 0 ;
} else {
} else {
std : : cerr < < std : : endl < < " ERROR: Some RAG schema objects are missing! " < < std : : endl ;
std : : cerr < < " FAILURE: Some RAG schema objects are missing " < < std : : endl ;
return 1 ;
return 1 ;
}
}
}
}