library/src/databases/sqlite/BP-DBSqlite.cc
// Add query to the current query stack.  Returns a reference
// to sqli->last_query_uuid if run ok.  If adding query fails,
// this returns null.
Add query to the current query stack.  Returns a reference
to sqli->last_query_uuid if run ok.  If adding query fails,
this returns null.
Add query to the current query stack . Returns a reference to sqli - > last_query_uuid if run ok . If adding query fails this returns null .
char * BP_SQLiteAddQuery
(
	P_BP_DB_SQLITE          sqli,
	BP_DB_SQLITE_QUERY_TYPE query_type,
	char *                  sql
)
{
	if(!sqli)
		return NULL;
	if(!sql)
		return NULL;
	if(!BP_StringIsReasonablePrintableString(sql, bpstrlen(sql), BP_TRUE, BP_TRUE))
		return NULL;
	if(!query_type)
		return NULL;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(sqli->system_hreg);
	if(!sqli->queries)
	{
		sqli->queries = BP_CreateHashTableRegistry();
		char * init_table_path[] = {"queries", NULL};
		BP_HashRegAddTableByPath
		(
				sqli->queries,
				(char **) &init_table_path
		);
	}
	char uuid_buff[BP_UUID_LEN+1];
	BP_ZERO_STACK(uuid_buff);
	BP_GenRandomUUID_StoreInBuff((char *) &uuid_buff);
	char * query_table_path[] = {"queries", (char *) &uuid_buff, NULL};
	 for the query itself
	BP_HashRegAddTableByPath
	(
			sqli->queries,
			(char **) &query_table_path
	);
	char * params_table_path[] = {"queries", (char *) &uuid_buff, "params", NULL};
	 for the query itself
	BP_HashRegAddTableByPath
	(
			sqli->queries,
			(char **) &params_table_path
	);
	char * sql_table_path[] = {"queries", (char *) &uuid_buff, NULL};
	BP_HashRegAddDataToTableByPath
	(
			sqli->queries,
			(char **) &sql_table_path,
			"sql",
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			(void *) sql,
			bpstrlen(sql)
	);
	if(sqli->last_query_uuid)
	{
		ht_free(sqli->queries, sqli->last_query_uuid);
	}
	sqli->last_query_uuid = ht_strdup(sqli->queries, (char *) &uuid_buff);
	sqli->last_query_param_n = 0;
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(sqli->system_hreg);
	return sqli->last_query_uuid;
}
char * BP_SQLiteAddQuery ( P_BP_DB_SQLITE sqli , BP_DB_SQLITE_QUERY_TYPE query_type , char * sql ) { if ( ! sqli ) return NULL ; if ( ! sql ) return NULL ; if ( ! BP_StringIsReasonablePrintableString ( sql , bpstrlen ( sql ) , BP_TRUE , BP_TRUE ) ) return NULL ; if ( ! query_type ) return NULL ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( sqli -> system_hreg ) ; if ( ! sqli -> queries ) { sqli -> queries = BP_CreateHashTableRegistry ( ) ; char * init_table_path [ ] = { " " , NULL } ; BP_HashRegAddTableByPath ( sqli -> queries , ( char * * ) & init_table_path ) ; } char uuid_buff [ BP_UUID_LEN + 1 ] ; BP_ZERO_STACK ( uuid_buff ) ; BP_GenRandomUUID_StoreInBuff ( ( char * ) & uuid_buff ) ; char * query_table_path [ ] = { " " , ( char * ) & uuid_buff , NULL } ; BP_HashRegAddTableByPath ( sqli -> queries , ( char * * ) & query_table_path ) ; char * params_table_path [ ] = { " " , ( char * ) & uuid_buff , " " , NULL } ; BP_HashRegAddTableByPath ( sqli -> queries , ( char * * ) & params_table_path ) ; char * sql_table_path [ ] = { " " , ( char * ) & uuid_buff , NULL } ; BP_HashRegAddDataToTableByPath ( sqli -> queries , ( char * * ) & sql_table_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , ( void * ) sql , bpstrlen ( sql ) ) ; if ( sqli -> last_query_uuid ) { ht_free ( sqli -> queries , sqli -> last_query_uuid ) ; } sqli -> last_query_uuid = ht_strdup ( sqli -> queries , ( char * ) & uuid_buff ) ; sqli -> last_query_param_n = 0 ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( sqli -> system_hreg ) ; return sqli -> last_query_uuid ; }
Add query to the current query stack.
Add query to the current query stack .
// ensure we have a sqli pointer // ensure we have a sql string // ensure the string is reasonable/printable // return indicating failure // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Enter Critical Section and Prepare %%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // enter critical section // create queries table if it doesn't already exist // create the queries table // set table path to /queries/ // add new table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add UUID Table %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // generate a random uuid // generate random uuid and store in local buffer // set table path to /queries/ // add new table for the query itself // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Parameters Table %%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // add parameters table // add new table for the query itself // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add SQL Data %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set sql path // add sql to the new table (copied over) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Set Last UUID %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // destroy last query uuid if its already set // set the last query uuid here by duplicating it within our registry // set the last query parameter count // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Leave Critical Section and Exit %%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // leave critical section // return indicating success