library/src/databases/bpdb/BP-DBSQLSyntaxGenerators.cc
// attempt to check fieldnames against schema
attempt to check fieldnames against schema
attempt to check fieldnames against schema
BP_ERROR_T BP_DBCheckFieldNamesAgainstSchema(P_BPDB_SQLGEN syngen, P_BP_LINKL field_name_list)
{
	if(!syngen)
		return ERR_FAILURE;
	if(!syngen->bpdb)
		return ERR_FAILURE;
	if(!field_name_list)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckFieldNamesAgainstSchema was called with a NULL field_name_list parameter");
		return ERR_FAILURE;
	}
	P_BP_LINKL_DATA field_name_iter = TAILQ_FIRST(&field_name_list->head);
	if(!field_name_iter)
		return ERR_FAILURE;
	TAILQ_FOREACH(field_name_iter, &field_name_list->head, linkl_data)
	{
		if
		(
			field_name_iter->data_type != BP_MEMPROF_ALLOC_TYPE_STRDUP   &&
			field_name_iter->data_type != BP_MEMPROF_ALLOC_TYPE_STRNDUP
		)
		{
			BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckFieldNamesAgainstSchema has a link data type which isn't a string.  Corruption detected.");
			return ERR_FAILURE;
		}
		if(!BP_DBLookupTableColumnByJoinedFieldName(syngen->bpdb, (char *) field_name_iter->data))
		{
			char tmp_str[bpstrlen((char*) field_name_iter->data)+512];
			sprintf((char *) &tmp_str, "BP_DBCheckFieldNamesAgainstSchema reports that '%s' fails lookup in BP_DBLookupTableColumnByJoinedFieldName", (char *) field_name_iter->data);
			BP_DBAddErrorMsg(syngen->bpdb, (char*) &tmp_str);
			return ERR_FAILURE;
		}
		if(!BP_DBLookupTableColumnMetadataFromJoinedFieldName(syngen->bpdb, (char *) field_name_iter->data))
		{
			char tmp_str[bpstrlen((char*) field_name_iter->data)+512];
			sprintf((char *) &tmp_str, "BP_DBCheckFieldNamesAgainstSchema reports that '%s' fails METADATA lookup in BP_DBLookupTableColumnMetadataFromJoinedFieldName", (char *) field_name_iter->data);
			BP_DBAddErrorMsg(syngen->bpdb, "BP_DBCheckFieldNamesAgainstSchema failed to lookup .");
			return ERR_FAILURE;
		}
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_DBCheckFieldNamesAgainstSchema ( P_BPDB_SQLGEN syngen , P_BP_LINKL field_name_list ) { if ( ! syngen ) return ERR_FAILURE ; if ( ! syngen -> bpdb ) return ERR_FAILURE ; if ( ! field_name_list ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } P_BP_LINKL_DATA field_name_iter = TAILQ_FIRST ( & field_name_list -> head ) ; if ( ! field_name_iter ) return ERR_FAILURE ; TAILQ_FOREACH ( field_name_iter , & field_name_list -> head , linkl_data ) { if ( field_name_iter -> data_type != BP_MEMPROF_ALLOC_TYPE_STRDUP && field_name_iter -> data_type != BP_MEMPROF_ALLOC_TYPE_STRNDUP ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! BP_DBLookupTableColumnByJoinedFieldName ( syngen -> bpdb , ( char * ) field_name_iter -> data ) ) { char tmp_str [ bpstrlen ( ( char * ) field_name_iter -> data ) + 512 ] ; sprintf ( ( char * ) & tmp_str , " " , ( char * ) field_name_iter -> data ) ; BP_DBAddErrorMsg ( syngen -> bpdb , ( char * ) & tmp_str ) ; return ERR_FAILURE ; } if ( ! BP_DBLookupTableColumnMetadataFromJoinedFieldName ( syngen -> bpdb , ( char * ) field_name_iter -> data ) ) { char tmp_str [ bpstrlen ( ( char * ) field_name_iter -> data ) + 512 ] ; sprintf ( ( char * ) & tmp_str , " " , ( char * ) field_name_iter -> data ) ; BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } } return ERR_SUCCESS ; }
attempt to check fieldnames against schema
attempt to check fieldnames against schema
// basic null checks // attempt to get the first item // ensure we have a first item // looks for a pointer in the item // only work with strndup/strdup types // attempt to lookup a column based on the field name // create some dynamic stack data // add error message // exit routine // attempt to lookup column metadata based on field name (required to ensure // that metadata exists in the table being analyzed) // create some dynamic stack data // add error message // exit routine // return indicating success