library/src/databases/bpdb/BP-DBSQLSyntaxGenerators.cc
// This is a "master" routine that runs all checks necessary for
// generating a select info.  It analyzes all elements in a
// BPDB_SQLGEN_SELECT item, and returns ERR_FAILURE on bad
// values.  You should only ever need to call this function
// once to verify values.
This is a "master" routine that runs all checks necessary for
generating a select info.  It analyzes all elements in a
BPDB_SQLGEN_SELECT item, and returns ERR_FAILURE on bad
values.  You should only ever need to call this function
once to verify values.
This is a " master " routine that runs all checks necessary for generating a select info . It analyzes all elements in a BPDB_SQLGEN_SELECT item and returns ERR_FAILURE on bad values . You should only ever need to call this function once to verify values .
BP_ERROR_T BP_DBCheckSelectInfoAndGenerateMetadataLists
(
		P_BPDB_SQLGEN        syngen,
		P_BPDB_SQLGEN_SELECT select_info
)
{
	if(!syngen)
		return ERR_FAILURE;
	if(!syngen->bpdb)
		return ERR_FAILURE;
	if(!select_info)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists was called with a NULL select_info parameter");
		return ERR_FAILURE;
	}
	if(!select_info->table_name)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists was called with a NULL select_info->table_name parameter");
		return ERR_FAILURE;
	}
	if(select_info->limits)
	{
		if(select_info->limits->limit_low > select_info->limits->limit_high)
		{
			BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists was called with a limit_low > limit_high");
			return ERR_FAILURE;
		}
	}
	if(!BP_StringIsReasonableForTableNameDB(select_info->table_name, bpstrlen(select_info->table_name)))
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists was called with an unreasonable table name (did not pass filter check)");
		return ERR_FAILURE;
	}
	P_BP_LINKL table_name_list = BP_DBGenerateTableListFromSelectInfo(select_info);
	if(!table_name_list)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists called BP_DBGenerateTableListFromSelectInfo but it failed to generate table list.");
		return ERR_FAILURE;
	}
	P_BP_LINKL field_name_list = BP_DBGenerateFieldNameListFromSelectInfo(select_info, table_name_list);
	if(!field_name_list)
	{
		BP_DestroyLinkL(table_name_list, BP_TRUE);
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists called BP_DBGenerateFieldNameListFromSelectInfo but it failed to generate field list.");
		return ERR_FAILURE;
	}
	if(!select_info->field_names)
	{
		BP_DestroyLinkL(table_name_list, BP_TRUE);
		BP_DestroyLinkL(field_name_list, BP_TRUE);
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists contains unpopulated select_info->field_names");
		return ERR_FAILURE;
	}
	size_t select_field_n = BP_CountNullTerminatedPtrArray(select_info->field_names);
	if(!BP_DBCheckSelectFieldNameList(syngen->bpdb, field_name_list, table_name_list))
	{
		BP_DestroyLinkL(table_name_list, BP_TRUE);
		BP_DestroyLinkL(field_name_list, BP_TRUE);
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists called BP_DBCheckSelectFieldNameList but it failed.");
		return ERR_FAILURE;
	}
	if(select_info->select_where)
	{
		if(!BP_DBCheckSelectClauseElements(syngen->bpdb, select_info->select_where, select_info->select_where_entry_n, field_name_list))
		{
			BP_DestroyLinkL(table_name_list, BP_TRUE);
			BP_DestroyLinkL(field_name_list, BP_TRUE);
			BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists called BP_DBCheckSelectClauseElements but it failed.");
			return ERR_FAILURE;
		}
	}
	if(select_info->join_on && select_info->join_on_entry_n)
	{
		if(!BP_DBCheckJoinElements(syngen->bpdb, select_info->join_on, select_info->join_on_entry_n, table_name_list))
		{
			BP_DestroyLinkL(table_name_list, BP_TRUE);
			BP_DestroyLinkL(field_name_list, BP_TRUE);
			BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckSelectInfoAndGenerateMetadataLists called BP_DBCheckJoinElements but it failed.");
			return ERR_FAILURE;
		}
	}
	select_info->field_name_list = field_name_list;
	select_info->table_name_list = table_name_list;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_DBCheckSelectInfoAndGenerateMetadataLists ( P_BPDB_SQLGEN syngen , P_BPDB_SQLGEN_SELECT select_info ) { if ( ! syngen ) return ERR_FAILURE ; if ( ! syngen -> bpdb ) return ERR_FAILURE ; if ( ! select_info ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! select_info -> table_name ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( select_info -> limits ) { if ( select_info -> limits -> limit_low > select_info -> limits -> limit_high ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } } if ( ! BP_StringIsReasonableForTableNameDB ( select_info -> table_name , bpstrlen ( select_info -> table_name ) ) ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } P_BP_LINKL table_name_list = BP_DBGenerateTableListFromSelectInfo ( select_info ) ; if ( ! table_name_list ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } P_BP_LINKL field_name_list = BP_DBGenerateFieldNameListFromSelectInfo ( select_info , table_name_list ) ; if ( ! field_name_list ) { BP_DestroyLinkL ( table_name_list , BP_TRUE ) ; BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! select_info -> field_names ) { BP_DestroyLinkL ( table_name_list , BP_TRUE ) ; BP_DestroyLinkL ( field_name_list , BP_TRUE ) ; BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } size_t select_field_n = BP_CountNullTerminatedPtrArray ( select_info -> field_names ) ; if ( ! BP_DBCheckSelectFieldNameList ( syngen -> bpdb , field_name_list , table_name_list ) ) { BP_DestroyLinkL ( table_name_list , BP_TRUE ) ; BP_DestroyLinkL ( field_name_list , BP_TRUE ) ; BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( select_info -> select_where ) { if ( ! BP_DBCheckSelectClauseElements ( syngen -> bpdb , select_info -> select_where , select_info -> select_where_entry_n , field_name_list ) ) { BP_DestroyLinkL ( table_name_list , BP_TRUE ) ; BP_DestroyLinkL ( field_name_list , BP_TRUE ) ; BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } } if ( select_info -> join_on && select_info -> join_on_entry_n ) { if ( ! BP_DBCheckJoinElements ( syngen -> bpdb , select_info -> join_on , select_info -> join_on_entry_n , table_name_list ) ) { BP_DestroyLinkL ( table_name_list , BP_TRUE ) ; BP_DestroyLinkL ( field_name_list , BP_TRUE ) ; BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } } select_info -> field_name_list = field_name_list ; select_info -> table_name_list = table_name_list ; return ERR_SUCCESS ; }
This is a "master" routine that runs all checks necessary for
generating a select info.
This is a " master " routine that runs all checks necessary for generating a select info .
// ensure we have a syntax generator // if we don't have a database exit with failure // ensure we have select info to work with // ensure we have a table name // check limits if they were passed in // ensure table name is reasonable // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Generate List of Possible Tables for Query %%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create array of all possible table names // generate field name list // destroy the table list // return indicating failure // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Field Name Checks %%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // ensure we have feild names // destroy the lists // add error message // return indicating failure // gather field count // run field name check via list // destroy the lists // add error message // return err failure // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Where Clause Checks %%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // destroy the lists // add error message // return err failure // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Join Checks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // run checks // destroy the lists // add error message // exit indicating failure // set field name list and table name list before returning // return indicating success