library/src/databases/sqlite/BP-DBSqlite.cc
// adds a result column to a query result
adds a result column to a query result
adds a result column to a query result
BP_ERROR_T BP_SQLiteAddResultColumnEntry
(
	P_BP_DB_SQLITE                sqli,
	char *                        query_result_uuid,
	size_t                        result_idx,
	char *                        col_name,
	size_t                        col_idx,
	BP_DB_SQLITE_QUERY_PARAM_TYPE type,
	void *                        data,
	size_t                        data_size
)
{
	if(!sqli)
		return ERR_FAILURE;
	if(!sqli->system_hreg)
		return ERR_FAILURE;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(sqli->system_hreg);
	if(!sqli->query_result_cache)
	{
		sqli->query_result_cache = BP_CreateHashTableRegistry();
		char * results_path[] = {"results", NULL};
		BP_HashRegAddTableByPath(sqli->query_result_cache, (char **) &results_path);
	}
	char * query_results_path[] = {"results", query_result_uuid, NULL};
	BP_HashRegAddTableByPath(sqli->query_result_cache, (char **) &query_results_path);
	P_BP_HASH_TABLE_KEYED_ENTRY lookup_entry = BP_HashRegLookupTableByPath(sqli->query_result_cache, (char **) &query_results_path);
	if(!lookup_entry)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(sqli->system_hreg, ERR_FAILURE);
	P_BP_HASH_TABLE_KEYED_ENTRY result_records = (P_BP_HASH_TABLE_KEYED_ENTRY) lookup_entry->data;
	char idx_buff[100];
	sprintf((char *) &idx_buff, "%u", result_idx);
	char * query_results_iter_path[] =
	{
		"results",
		query_result_uuid,
		(char *) &idx_buff,
		NULL
	};
	BP_HashRegAddTableByPath
	(
			sqli->query_result_cache,
			(char **) &query_results_iter_path
	);
	char * query_results_inner_iter_path[] =
	{
		"results",
		query_result_uuid,
		(char *) &idx_buff,
		col_name,
		NULL
	};
	BP_HashRegAddTableByPath
	(
			sqli->query_result_cache,
			(char **) &query_results_inner_iter_path
	);
	BP_HashRegAddDataToTableByPath
	(
			sqli->query_result_cache,
			(char **) &query_results_inner_iter_path,
			"record_data",
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			data,
			data_size
	);
	BP_HashRegAddDataToTableByPath
	(
			sqli->query_result_cache,
			(char **) &query_results_inner_iter_path,
			"record_metadata",
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			NULL,
			sizeof(BP_DB_SQLITE_RESULT_METADATA)
	);
	char * query_results_metadata_iter_lookup_path[] =
	{
			"results",
			query_result_uuid,
			(char *) &idx_buff,
			col_name,
			"record_metadata",
			NULL
	};
	P_BP_HASH_TABLE_KEYED_ENTRY record_metadata_entry = BP_HashRegLookupTableEntryByPath(sqli->query_result_cache, (char **) &query_results_metadata_iter_lookup_path);
	P_BP_DB_SQLITE_RESULT_METADATA record_metadata = (P_BP_DB_SQLITE_RESULT_METADATA) record_metadata_entry->data;
	if(record_metadata)
	{
		record_metadata->result_idx = result_idx;
		record_metadata->col_idx    = col_idx;
		record_metadata->type       = type;
		record_metadata->data_size  = data_size;
	}
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(sqli->system_hreg);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_SQLiteAddResultColumnEntry ( P_BP_DB_SQLITE sqli , char * query_result_uuid , size_t result_idx , char * col_name , size_t col_idx , BP_DB_SQLITE_QUERY_PARAM_TYPE type , void * data , size_t data_size ) { if ( ! sqli ) return ERR_FAILURE ; if ( ! sqli -> system_hreg ) return ERR_FAILURE ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( sqli -> system_hreg ) ; if ( ! sqli -> query_result_cache ) { sqli -> query_result_cache = BP_CreateHashTableRegistry ( ) ; char * results_path [ ] = { " " , NULL } ; BP_HashRegAddTableByPath ( sqli -> query_result_cache , ( char * * ) & results_path ) ; } char * query_results_path [ ] = { " " , query_result_uuid , NULL } ; BP_HashRegAddTableByPath ( sqli -> query_result_cache , ( char * * ) & query_results_path ) ; P_BP_HASH_TABLE_KEYED_ENTRY lookup_entry = BP_HashRegLookupTableByPath ( sqli -> query_result_cache , ( char * * ) & query_results_path ) ; if ( ! lookup_entry ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( sqli -> system_hreg , ERR_FAILURE ) ; P_BP_HASH_TABLE_KEYED_ENTRY result_records = ( P_BP_HASH_TABLE_KEYED_ENTRY ) lookup_entry -> data ; char idx_buff [ 100 ] ; sprintf ( ( char * ) & idx_buff , " " , result_idx ) ; char * query_results_iter_path [ ] = { " " , query_result_uuid , ( char * ) & idx_buff , NULL } ; BP_HashRegAddTableByPath ( sqli -> query_result_cache , ( char * * ) & query_results_iter_path ) ; char * query_results_inner_iter_path [ ] = { " " , query_result_uuid , ( char * ) & idx_buff , col_name , NULL } ; BP_HashRegAddTableByPath ( sqli -> query_result_cache , ( char * * ) & query_results_inner_iter_path ) ; BP_HashRegAddDataToTableByPath ( sqli -> query_result_cache , ( char * * ) & query_results_inner_iter_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , data , data_size ) ; BP_HashRegAddDataToTableByPath ( sqli -> query_result_cache , ( char * * ) & query_results_inner_iter_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_DB_SQLITE_RESULT_METADATA ) ) ; char * query_results_metadata_iter_lookup_path [ ] = { " " , query_result_uuid , ( char * ) & idx_buff , col_name , " " , NULL } ; P_BP_HASH_TABLE_KEYED_ENTRY record_metadata_entry = BP_HashRegLookupTableEntryByPath ( sqli -> query_result_cache , ( char * * ) & query_results_metadata_iter_lookup_path ) ; P_BP_DB_SQLITE_RESULT_METADATA record_metadata = ( P_BP_DB_SQLITE_RESULT_METADATA ) record_metadata_entry -> data ; if ( record_metadata ) { record_metadata -> result_idx = result_idx ; record_metadata -> col_idx = col_idx ; record_metadata -> type = type ; record_metadata -> data_size = data_size ; } BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( sqli -> system_hreg ) ; return ERR_SUCCESS ; }
adds a result column to a query result
adds a result column to a query result
// ensure we have a sqli pointer // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Enter Critical Section and Add Param %%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // enter critical section // create result cache if to doesn't exist // create a query cache // set the results path // add results table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt Table Lookup %%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set query results path // attempt to add the table (fails graceful if already exists) // attempt lookup new (or existing) // ensure we can lookup our entry // set records ptr // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Attempt Table Record Addition %%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // get the index from the count // set query results path // attempt to add the table (fails graceful if already exists) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Inner Table For Record %%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // note: inner record contains data and metadata. // set query results path // attempt to add the table (fails graceful if already exists) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Inner Table %%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // add data to table by path // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Metadata to Record %%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // add metadata to table // set query results path // lookup the record metadata // create typed reference to record metadata // if the lookup was ok, go ahead and fill in values // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Leave Critical Section and Exit %%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // leave critical section // return indicating success