library/src/databases/bpdb/BP-DBSQLSyntaxGenerators.cc
// Attempt to add a result entry to match with a result
Attempt to add a result entry to match with a result
Attempt to add a result entry to match with a result
BP_ERROR_T BP_DBAddSelectResultReferenceToResultHashTable
(
	P_BPDB_SQLGEN        syngen,
	P_BPDB_SQLGEN_SELECT select_info,
	char               * select_field_name,
	MYSQL_BIND *         result_entry
)
{
	if(!syngen)
		return ERR_FAILURE;
	if(!syngen->bpdb)
		return ERR_FAILURE;
	if(!select_info)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultReferenceToResultHashTable was called with a NULL select_info parameter.");
		return ERR_FAILURE;
	}
	if(!select_field_name)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultReferenceToResultHashTable was called with a NULL select_field_name parameter.");
		return ERR_FAILURE;
	}
	if(!result_entry)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultReferenceToResultHashTable was called with a NULL result_entry parameter.");
		return ERR_FAILURE;
	}
	printf("\n [dbg] Attempting to add to hash table here ptr: %p", result_entry);
	if(!select_info->fetched_record_hreg)
	{
		select_info->fetched_record_hreg = BP_CreateHashTableRegistry();
	}
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(select_info->fetched_record_hreg);
	char *table_path[3];
	BP_ZERO_STACK(table_path);
	table_path[0] = select_field_name;
	P_BP_HASH_TABLE_KEYED_ENTRY table_lookup = BP_HashRegLookupTableByPath(select_info->fetched_record_hreg, table_path);
	if(table_lookup)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultReferenceToResultHashTable attempted to call BP_HashRegLookupTableByPath on select_field_name but it failed.");
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(select_info->fetched_record_hreg, ERR_FAILURE);
	}
	BP_ERROR_T ret_val = BP_HashRegAddTableByPath(select_info->fetched_record_hreg, (char **) &table_path);
	if(!ret_val)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultReferenceToResultHashTable attempted to call BP_HashRegAddTableByPath on select_field_name but it failed.");
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(select_info->fetched_record_hreg, ERR_FAILURE);
	}
	table_lookup = BP_HashRegLookupTableByPath(select_info->fetched_record_hreg, table_path);
	if(!table_lookup)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultReferenceToResultHashTable attempted to call BP_HashRegLookupTableByPath after select_field_name addition, but it (lookup) failed.");
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(select_info->fetched_record_hreg, ERR_FAILURE);
	}
	BP_HashRegAddDataToTable
	(
		select_info->fetched_record_hreg,
		table_lookup,
		"result_data_ptr", 
		BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
		NULL,
		sizeof(MYSQL_BIND *)
	);
	char * lookup_path[] = {select_field_name, "result_data_ptr", NULL};
	P_BP_HASH_TABLE_KEYED_ENTRY result_data_ptr_lookup = BP_HashRegLookupTableEntryByPath(select_info->fetched_record_hreg, (char **) &lookup_path);
	if(!result_data_ptr_lookup)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultReferenceToResultHashTable attempted to add result data, but it failed to add to hreg.");
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(select_info->fetched_record_hreg, ERR_FAILURE);
	}
	printf("\n Using result entry:!: %p", result_entry);
	memcpy(result_data_ptr_lookup->data, &result_entry, sizeof(MYSQL_BIND * ));
	printf("\n Using data after?: %p", result_data_ptr_lookup->data);
	MYSQL_BIND ** tmp_ptr = (MYSQL_BIND**) result_data_ptr_lookup->data;
	printf("\n WATPTRDISPLAY HERE: %p", *tmp_ptr);
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(select_info->fetched_record_hreg, ERR_SUCCESS);
}
BP_ERROR_T BP_DBAddSelectResultReferenceToResultHashTable ( P_BPDB_SQLGEN syngen , P_BPDB_SQLGEN_SELECT select_info , char * select_field_name , MYSQL_BIND * result_entry ) { if ( ! syngen ) return ERR_FAILURE ; if ( ! syngen -> bpdb ) return ERR_FAILURE ; if ( ! select_info ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! select_field_name ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! result_entry ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } printf ( " \n " , result_entry ) ; if ( ! select_info -> fetched_record_hreg ) { select_info -> fetched_record_hreg = BP_CreateHashTableRegistry ( ) ; } BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( select_info -> fetched_record_hreg ) ; char * table_path [ 3 ] ; BP_ZERO_STACK ( table_path ) ; table_path [ 0 ] = select_field_name ; P_BP_HASH_TABLE_KEYED_ENTRY table_lookup = BP_HashRegLookupTableByPath ( select_info -> fetched_record_hreg , table_path ) ; if ( table_lookup ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( select_info -> fetched_record_hreg , ERR_FAILURE ) ; } BP_ERROR_T ret_val = BP_HashRegAddTableByPath ( select_info -> fetched_record_hreg , ( char * * ) & table_path ) ; if ( ! ret_val ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( select_info -> fetched_record_hreg , ERR_FAILURE ) ; } table_lookup = BP_HashRegLookupTableByPath ( select_info -> fetched_record_hreg , table_path ) ; if ( ! table_lookup ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( select_info -> fetched_record_hreg , ERR_FAILURE ) ; } BP_HashRegAddDataToTable ( select_info -> fetched_record_hreg , table_lookup , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( MYSQL_BIND * ) ) ; char * lookup_path [ ] = { select_field_name , " " , NULL } ; P_BP_HASH_TABLE_KEYED_ENTRY result_data_ptr_lookup = BP_HashRegLookupTableEntryByPath ( select_info -> fetched_record_hreg , ( char * * ) & lookup_path ) ; if ( ! result_data_ptr_lookup ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( select_info -> fetched_record_hreg , ERR_FAILURE ) ; } printf ( " \n " , result_entry ) ; memcpy ( result_data_ptr_lookup -> data , & result_entry , sizeof ( MYSQL_BIND * ) ) ; printf ( " \n " , result_data_ptr_lookup -> data ) ; MYSQL_BIND * * tmp_ptr = ( MYSQL_BIND * * ) result_data_ptr_lookup -> data ; printf ( " \n " , * tmp_ptr ) ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( select_info -> fetched_record_hreg , ERR_SUCCESS ) ; }
Attempt to add a result entry to match with a result
Attempt to add a result entry to match with a result
// run basic null checks // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Entry to Hash Registry (for name lookups) %%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // ensure we have a hash table registry // create registry just in time // lock critical section // set table path // set table path // attempt to lookup table from the previous path // if the item already exists, return indicating failure // -- Attempt to Add Table ----------- // add table to the db // leave critical section here (necessary) // try lookup again after addition // if the lookup fails, we have an erroneous condition // -- Attempt to Add Data to Table ----------- // attempt to add metadata entry to the table /* in BP-DB.h */ // set lookup path // retrive table metadata by path // result_data_ptr_lookup->data = (void *) result_entry; // copy in the pointer // = result_entry; // return indicating success