sqlite3_command::sqlite3_command(sqlite3_connection &con, const std::wstring &sql) : con(con),stmt(0),refs(0),argc(0) { const void *tail=NULL; if(sqlite3_prepare16(con.db(), sql.data(), (int)sql.length()*2, &this->stmt, &tail)!=SQLITE_OK) throw database_error(con); this->argc=sqlite3_column_count(this->stmt); }
void createDatabases(sqlite3_connection& con) { try { con.executenonquery("create table IF NOT EXISTS timing(property_name TEXT, total_wallclock FLOAT, total_usertime FLOAT, total_systime FLOAT, wallclock FLOAT, usertime FLOAT, systime FLOAT )"); } catch(std::exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { // Function IDs are only unique within a file con.executenonquery("create table IF NOT EXISTS function_statistics(row_number INTEGER PRIMARY KEY, function_id INTEGER, num_instructions INTEGER )"); } catch(std::exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS function_ids(row_number INTEGER PRIMARY KEY, file TEXT, function_name TEXT)"); } catch(std::exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS vectors(row_number INTEGER PRIMARY KEY, function_id INTEGER, index_within_function INTEGER, line INTEGER, offset INTEGER, sum_of_counts INTEGER, counts BLOB, instr_seq BLOB)"); } catch(std::exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS clusters(row_number INTEGER PRIMARY KEY, cluster INTEGER, function_id INTEGER, index_within_function INTEGER, vectors_row INTEGER, dist INTEGER)"); } catch(std::exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } }
table_generator::table_generator( sqlite3_connection & con, std::string const & n ) : m_pimpl( new table_generator::table_generator_impl ) { int check = con.executeint( "select count(*) from sqlite_master where type like 'table' and name like '"+n+"'" ); // ^^^ we use 'like' here because sqlite3 is case-insensitive if( 0 != check ) { throw database_error( "table_generator() db table '%s' already exists.", n.c_str() ); } this->m_pimpl->db = &con; this->m_pimpl->name = n; }
void createDatabases(sqlite3_connection& con) { try { con.executenonquery("create table IF NOT EXISTS run_parameters(window_size INTEGER, stride INTEGER)"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS detection_parameters(similarity_threshold FLOAT, false_negative_rate FLOAT)"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS vector_generator_timing(file TEXT, total_wallclock FLOAT, total_usertime FLOAT, total_systime FLOAT, vecgen_wallclock FLOAT, vecgen_usertime FLOAT, vecgen_systime FLOAT )"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS timing(property_name TEXT, total_wallclock FLOAT, total_usertime FLOAT, total_systime FLOAT, wallclock FLOAT, usertime FLOAT, systime FLOAT )"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { // Function IDs are only unique within a file con.executenonquery("create table IF NOT EXISTS function_statistics(row_number INTEGER PRIMARY KEY, function_id INTEGER, num_instructions INTEGER )"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS results(row_number INTEGER PRIMARY KEY, edit_distance INTEGER, false_positive_rate FLOAT )"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS function_ids(row_number INTEGER PRIMARY KEY, file TEXT, function_name TEXT)"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { // index_within_function values are only unique within a file and function // con.executenonquery("create table IF NOT EXISTS vectors(row_number INTEGER PRIMARY KEY, line INTEGER, offset INTEGER, sum_of_counts INTEGER, counts BLOB, instr_seq TEXT, function_id INTEGER, index_within_function INTEGER )"); con.executenonquery("create table IF NOT EXISTS vectors(row_number INTEGER PRIMARY KEY, function_id INTEGER, index_within_function INTEGER, line INTEGER, offset INTEGER, sum_of_counts INTEGER, counts BLOB, instr_seq BLOB)"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { // index_within_function values are only unique within a file and function con.executenonquery("create index IF NOT EXISTS vectors_sum_of_counts_index on vectors(sum_of_counts)"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS clusters(row_number INTEGER PRIMARY KEY, cluster INTEGER, function_id INTEGER, index_within_function INTEGER, vectors_row INTEGER, dist INTEGER)"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try { con.executenonquery("create table IF NOT EXISTS postprocessed_clusters(row_number INTEGER PRIMARY KEY, cluster INTEGER, function_id INTEGER, index_within_function INTEGER, vectors_row INTEGER, dist INTEGER )"); } catch(exception &ex) { cerr << "Exception Occurred: " << ex.what() << endl; } try {con.executenonquery("create table if not exists function_coverage(function_id integer, num_instructions_covered_not_postprocessed integer, fraction_instructions_covered_not_postprocessed float, num_instructions_covered_postprocessed integer, fraction_instructions_covered_postprocessed float)");} catch(exception &ex) {cerr << "Exception Occurred: " << ex.what() << endl;} try {con.executenonquery("create table if not exists total_coverage(num_instructions_covered_not_postprocessed integer, fraction_instructions_covered_not_postprocessed float, num_instructions_covered_postprocessed integer, fraction_instructions_covered_postprocessed float)");} catch(exception &ex) {cerr << "Exception Occurred: " << ex.what() << endl;} try {con.executenonquery("create index if not exists clusters_by_function on clusters(function_id)");} catch(exception &ex) {cerr << "Exception Occurred: " << ex.what() << endl;} try {con.executenonquery("create index if not exists postprocessed_clusters_by_function on postprocessed_clusters(function_id)");} catch(exception &ex) {cerr << "Exception Occurred: " << ex.what() << endl;} try {con.executenonquery("create index if not exists function_statistics_by_function on function_statistics(function_id)");} catch(exception &ex) {cerr << "Exception Occurred: " << ex.what() << endl;} try { sqlite3_command(con, "create index if not exists clusters_index_by_cluster on clusters(cluster)").executenonquery(); } catch (exception& ex) {cerr << "Exception Occurred: " << ex.what() << endl;} try { sqlite3_command(con, "create index if not exists postprocessed_clusters_index_by_cluster on postprocessed_clusters(cluster)").executenonquery(); } catch (exception& ex) {cerr << "Exception Occurred: " << ex.what() << endl;} }