library/src/databases/bpdb/BP-DB.cc
// attempts to retrieve the number of columns for a specified table
attempts to retrieve the number of columns for a specified table
attempts to retrieve the number of columns for a specified table
size_t BP_DBGetColumnCountForTable
(
		P_BPDB bpdb,
		char *table_name
)
{
	if(!bpdb)
		return NULL;
	if(!table_name)
		return NULL;
	if(!BP_StringIsReasonableForTableNameDB(table_name, bpstrlen(table_name)))
		return NULL;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(bpdb->system_hreg);
	P_BP_HASH_TABLE_KEYED_ENTRY columns_table = BP_DBLookupTableColumns(bpdb, table_name);
	if(!columns_table)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(bpdb->system_hreg, 0);
	if(!columns_table->data)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(bpdb->system_hreg, 0);
	size_t column_count = 0;
	BP_HASH_ITER_OPEN((P_BP_HASH_TABLE_KEYED_ENTRY) columns_table->data, column_iter)
	{
		column_count++;
	} BP_HASH_ITER_CLOSE;
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(bpdb->system_hreg);
	return column_count;
}
size_t BP_DBGetColumnCountForTable ( P_BPDB bpdb , char * table_name ) { if ( ! bpdb ) return NULL ; if ( ! table_name ) return NULL ; if ( ! BP_StringIsReasonableForTableNameDB ( table_name , bpstrlen ( table_name ) ) ) return NULL ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( bpdb -> system_hreg ) ; P_BP_HASH_TABLE_KEYED_ENTRY columns_table = BP_DBLookupTableColumns ( bpdb , table_name ) ; if ( ! columns_table ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( bpdb -> system_hreg , 0 ) ; if ( ! columns_table -> data ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( bpdb -> system_hreg , 0 ) ; size_t column_count = 0 ; BP_HASH_ITER_OPEN ( ( P_BP_HASH_TABLE_KEYED_ENTRY ) columns_table -> data , column_iter ) { column_count ++ ; } BP_HASH_ITER_CLOSE ; BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( bpdb -> system_hreg ) ; return column_count ; }
attempts to retrieve the number of columns for a specified table
attempts to retrieve the number of columns for a specified table
// run basic checks // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Enter Critical Section and Attempt to lookup table %%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // enter critical section // attempt to look up the columns "table" within the hash registry // return zero if we couldn't perform a lookup // return zero if the lookup has no entries // this is the value to be returned // open the iterator // increment the column count // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Exit Critical Section and Return Row %%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to leave critical section // return the filled out column count