library/src/databases/bpdb/BP-DBSQLSyntaxGenerators.cc
// Checks "where" clause elements to make sure they make sense from a logical perspective.
Checks "where" clause elements to make sure they make sense from a logical perspective.
Checks " where " clause elements to make sure they make sense from a logical perspective .
BP_ERROR_T BP_DBCheckSelectClauseElements
(
	P_BPDB              bpdb,
	P_BPDB_SELECT_WHERE wheres,
	size_t              wheres_n,
	P_BP_LINKL          field_name_list
)
{
	if(!bpdb)
		return ERR_FAILURE;
	if(!wheres)
	{
		BP_DBAddErrorMsg(bpdb, "BP_DBCheckSelectClauseElements was called with a NULL 'wheres' parameter.");
		return ERR_FAILURE;
	}
	if(!wheres_n)
	{
		BP_DBAddErrorMsg(bpdb, "BP_DBCheckSelectClauseElements was called with a zero where count");
		return ERR_FAILURE;
	}
	if(!field_name_list)
	{
		BP_DBAddErrorMsg(bpdb, "BP_DBCheckSelectClauseElements was called with a NULL field_name_list parameter.");
		return ERR_FAILURE;
	}
	size_t where_iter_n = 0;
	for(; where_iter_n < wheres_n; where_iter_n++)
	{
		if(!wheres[where_iter_n].field_name)
		{
			char tmp_buff[1024];
			BP_ZERO_STACK(tmp_buff);
			sprintf((char *) &tmp_buff, "BP_DBCheckSelectClauseElements reports that the field name at index position %zu was NULL.", where_iter_n);
			BP_DBAddErrorMsg(bpdb, (char *) &tmp_buff);
			return ERR_FAILURE;
		}
		if(!BP_LinkLSearchForString(field_name_list, wheres[where_iter_n].field_name, bpstrlen(wheres[where_iter_n].field_name)))
			return ERR_FAILURE;
		if(wheres[where_iter_n].value_type == BPDB_SELECT_WHERE_VALUE_TYPE_TABLE_AND_COLUMN)
		{
			if(!BP_LinkLSearchForString(field_name_list, wheres[where_iter_n].value, bpstrlen(wheres[where_iter_n].value)))
			{
				char tmp_buff[1024+bpstrlen(wheres[where_iter_n].value)];
				BP_ZERO_STACK(tmp_buff);
				sprintf((char *) &tmp_buff, "BP_DBCheckSelectClauseElements reports that the field name '%s' could not be found in field_name_list ", wheres[where_iter_n].value);
				BP_DBAddErrorMsg(bpdb, (char *) &tmp_buff);
				return ERR_FAILURE;
			}
		}
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_DBCheckSelectClauseElements ( P_BPDB bpdb , P_BPDB_SELECT_WHERE wheres , size_t wheres_n , P_BP_LINKL field_name_list ) { if ( ! bpdb ) return ERR_FAILURE ; if ( ! wheres ) { BP_DBAddErrorMsg ( bpdb , " " ) ; return ERR_FAILURE ; } if ( ! wheres_n ) { BP_DBAddErrorMsg ( bpdb , " " ) ; return ERR_FAILURE ; } if ( ! field_name_list ) { BP_DBAddErrorMsg ( bpdb , " " ) ; return ERR_FAILURE ; } size_t where_iter_n = 0 ; for ( ; where_iter_n < wheres_n ; where_iter_n ++ ) { if ( ! wheres [ where_iter_n ] . field_name ) { char tmp_buff [ 1024 ] ; BP_ZERO_STACK ( tmp_buff ) ; sprintf ( ( char * ) & tmp_buff , " " , where_iter_n ) ; BP_DBAddErrorMsg ( bpdb , ( char * ) & tmp_buff ) ; return ERR_FAILURE ; } if ( ! BP_LinkLSearchForString ( field_name_list , wheres [ where_iter_n ] . field_name , bpstrlen ( wheres [ where_iter_n ] . field_name ) ) ) return ERR_FAILURE ; if ( wheres [ where_iter_n ] . value_type == BPDB_SELECT_WHERE_VALUE_TYPE_TABLE_AND_COLUMN ) { if ( ! BP_LinkLSearchForString ( field_name_list , wheres [ where_iter_n ] . value , bpstrlen ( wheres [ where_iter_n ] . value ) ) ) { char tmp_buff [ 1024 + bpstrlen ( wheres [ where_iter_n ] . value ) ] ; BP_ZERO_STACK ( tmp_buff ) ; sprintf ( ( char * ) & tmp_buff , " " , wheres [ where_iter_n ] . value ) ; BP_DBAddErrorMsg ( bpdb , ( char * ) & tmp_buff ) ; return ERR_FAILURE ; } } } return ERR_SUCCESS ; }
Checks "where" clause elements to make sure they make sense from a logical perspective.
Checks " where " clause elements to make sure they make sense from a logical perspective .
// we must have a bpdb at all times (for error reporting) // basic checks /*
		// create some stack space
		char tmp_buff[1024+bpstrlen(table_and_field[0])];
		BP_ZERO_STACK(tmp_buff);

		// add message indicating that we found an empty field
		sprintf((char *) &tmp_buff, "BP_DBCheckSelectFieldNameList reports that the table '%s' could not be found in table_name_list ", table_and_field[0]);

		// add error and exit
		BP_DBAddErrorMsg(bpdb, (char *) &tmp_buff);
		*/ // where iter for walking // walk the where clauses and run checks // ensure we have a field name // create some stack space // add message indicating that we found an empty field // add error and exit // search for the where clause field in field name list // if the value is a table, check it here // check for field // create some stack space // add message indicating that we found an empty field // add error and exit // return indicating success