library/src/databases/bpdb/BP-DBSQLSyntaxGenerators.cc
// Attempts to add a result to the select info structure.  Used internally.
Attempts to add a result to the select info structure.  Used internally.
Attempts to add a result to the select info structure . Used internally .
BP_ERROR_T BP_DBAddSelectResultToSelectInfo
(
	P_BPDB_SQLGEN        syngen,
	P_BPDB_SQLGEN_SELECT select_info,
	char               * select_field_name
)
{
	if(!syngen)
		return ERR_FAILURE;
	if(!syngen->bpdb)
		return ERR_FAILURE;
	if(!select_info)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultToSelectInfo was called with a NULL select_info parameter.");
		return ERR_FAILURE;
	}
	if(!select_field_name)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultToSelectInfo was called with a NULL select_field_name parameter.");
		return ERR_FAILURE;
	}
	if(!select_info->bind_results_tq_allocator)
	{
		select_info->bind_results_tq_allocator = BP_CreateLinkL(".", BP_TRUE);
		select_info->bind_results = NULL;
	}
	select_info->bind_results = (MYSQL_BIND *) tq_realloc
	(
		select_info->bind_results_tq_allocator,
		select_info->bind_results,
		sizeof(MYSQL_BIND) * (select_info->bind_results_n + 1),
		BPLN
	);
	if(!select_info->bind_results)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultToSelectInfo attempted to reallocate space for new entry, but allocation failed.");
		return ERR_FAILURE;
	}
	MYSQL_BIND * new_bind_result = &select_info->bind_results[select_info->bind_results_n];
	memset(new_bind_result, 0x00, sizeof(MYSQL_BIND));
	select_info->bind_results_n++;
	P_BPDB_SQL_TABLE_COLUMN_METADATA column_metadata = BP_DBLookupTableColumnMetadataFromJoinedFieldName(syngen->bpdb, select_field_name);
	if(!column_metadata)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultToSelectInfo called BP_DBLookupTableColumnMetadataFromJoinedFieldName but it failed.");
		return ERR_FAILURE;
	}
	switch(column_metadata->mariadb_column_metadata.data_type_as_enum)
	{
		case BPDB_MARIADB_COLUMN_TYPE_TINYINT:
			new_bind_result->buffer_type = MYSQL_TYPE_TINY;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_SMALLINT:
			new_bind_result->buffer_type = MYSQL_TYPE_SHORT;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_MEDIUMINT:
			new_bind_result->buffer_type = MYSQL_TYPE_INT24;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_INT:
			new_bind_result->buffer_type = MYSQL_TYPE_LONG;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_BIGINT:
			new_bind_result->buffer_type = MYSQL_TYPE_LONGLONG;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_DECIMAL:
			new_bind_result->buffer_type = MYSQL_TYPE_DECIMAL;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_FLOAT:
			new_bind_result->buffer_type = MYSQL_TYPE_FLOAT;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_DOUBLE:
			new_bind_result->buffer_type = MYSQL_TYPE_DOUBLE;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_BIT:
			new_bind_result->buffer_type = MYSQL_TYPE_BIT;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_CHAR:
			new_bind_result->buffer_type = MYSQL_TYPE_STRING;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_VARCHAR:
			new_bind_result->buffer_type = MYSQL_TYPE_VAR_STRING;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_BINARY:
			new_bind_result->buffer_type = MYSQL_TYPE_STRING;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_VARBINARY:
			new_bind_result->buffer_type = MYSQL_TYPE_VAR_STRING;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TINYBLOB:
			new_bind_result->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_BLOB:
			break;
		case BPDB_MARIADB_COLUMN_TYPE_MEDIUMBLOB:
			new_bind_result->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_LONGBLOB:
			new_bind_result->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TINYTEXT:
			new_bind_result->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TEXT:
			new_bind_result->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_MEDIUMTEXT:
			new_bind_result->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_LONGTEXT:
			new_bind_result->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_ENUM:
			new_bind_result->buffer_type = MYSQL_TYPE_ENUM;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_DATE:
			new_bind_result->buffer_type = MYSQL_TYPE_DATE;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TIME:
			new_bind_result->buffer_type = MYSQL_TYPE_TIME;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_DATETIME:
			new_bind_result->buffer_type = MYSQL_TYPE_DATETIME;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TIMESTAMP:
			new_bind_result->buffer_type = MYSQL_TYPE_TIMESTAMP;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_YEAR:
			new_bind_result->buffer_type = MYSQL_TYPE_YEAR;
			break;
		default:
			BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectResultToSelectInfo column type lookup failed.  This should never happen.");
			return ERR_FAILURE;
	}
	return ERR_SUCCESS;
}
BP_ERROR_T BP_DBAddSelectResultToSelectInfo ( P_BPDB_SQLGEN syngen , P_BPDB_SQLGEN_SELECT select_info , char * select_field_name ) { 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 ( ! select_info -> bind_results_tq_allocator ) { select_info -> bind_results_tq_allocator = BP_CreateLinkL ( " " , BP_TRUE ) ; select_info -> bind_results = NULL ; } select_info -> bind_results = ( MYSQL_BIND * ) tq_realloc ( select_info -> bind_results_tq_allocator , select_info -> bind_results , sizeof ( MYSQL_BIND ) * ( select_info -> bind_results_n + 1 ) , BPLN ) ; if ( ! select_info -> bind_results ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } MYSQL_BIND * new_bind_result = & select_info -> bind_results [ select_info -> bind_results_n ] ; memset ( new_bind_result , 0x00 , sizeof ( MYSQL_BIND ) ) ; select_info -> bind_results_n ++ ; P_BPDB_SQL_TABLE_COLUMN_METADATA column_metadata = BP_DBLookupTableColumnMetadataFromJoinedFieldName ( syngen -> bpdb , select_field_name ) ; if ( ! column_metadata ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } switch ( column_metadata -> mariadb_column_metadata . data_type_as_enum ) { case BPDB_MARIADB_COLUMN_TYPE_TINYINT : new_bind_result -> buffer_type = MYSQL_TYPE_TINY ; break ; case BPDB_MARIADB_COLUMN_TYPE_SMALLINT : new_bind_result -> buffer_type = MYSQL_TYPE_SHORT ; break ; case BPDB_MARIADB_COLUMN_TYPE_MEDIUMINT : new_bind_result -> buffer_type = MYSQL_TYPE_INT24 ; break ; case BPDB_MARIADB_COLUMN_TYPE_INT : new_bind_result -> buffer_type = MYSQL_TYPE_LONG ; break ; case BPDB_MARIADB_COLUMN_TYPE_BIGINT : new_bind_result -> buffer_type = MYSQL_TYPE_LONGLONG ; break ; case BPDB_MARIADB_COLUMN_TYPE_DECIMAL : new_bind_result -> buffer_type = MYSQL_TYPE_DECIMAL ; break ; case BPDB_MARIADB_COLUMN_TYPE_FLOAT : new_bind_result -> buffer_type = MYSQL_TYPE_FLOAT ; break ; case BPDB_MARIADB_COLUMN_TYPE_DOUBLE : new_bind_result -> buffer_type = MYSQL_TYPE_DOUBLE ; break ; case BPDB_MARIADB_COLUMN_TYPE_BIT : new_bind_result -> buffer_type = MYSQL_TYPE_BIT ; break ; case BPDB_MARIADB_COLUMN_TYPE_CHAR : new_bind_result -> buffer_type = MYSQL_TYPE_STRING ; break ; case BPDB_MARIADB_COLUMN_TYPE_VARCHAR : new_bind_result -> buffer_type = MYSQL_TYPE_VAR_STRING ; break ; case BPDB_MARIADB_COLUMN_TYPE_BINARY : new_bind_result -> buffer_type = MYSQL_TYPE_STRING ; break ; case BPDB_MARIADB_COLUMN_TYPE_VARBINARY : new_bind_result -> buffer_type = MYSQL_TYPE_VAR_STRING ; break ; case BPDB_MARIADB_COLUMN_TYPE_TINYBLOB : new_bind_result -> buffer_type = MYSQL_TYPE_BLOB ; break ; case BPDB_MARIADB_COLUMN_TYPE_BLOB : break ; case BPDB_MARIADB_COLUMN_TYPE_MEDIUMBLOB : new_bind_result -> buffer_type = MYSQL_TYPE_BLOB ; break ; case BPDB_MARIADB_COLUMN_TYPE_LONGBLOB : new_bind_result -> buffer_type = MYSQL_TYPE_BLOB ; break ; case BPDB_MARIADB_COLUMN_TYPE_TINYTEXT : new_bind_result -> buffer_type = MYSQL_TYPE_BLOB ; break ; case BPDB_MARIADB_COLUMN_TYPE_TEXT : new_bind_result -> buffer_type = MYSQL_TYPE_BLOB ; break ; case BPDB_MARIADB_COLUMN_TYPE_MEDIUMTEXT : new_bind_result -> buffer_type = MYSQL_TYPE_BLOB ; break ; case BPDB_MARIADB_COLUMN_TYPE_LONGTEXT : new_bind_result -> buffer_type = MYSQL_TYPE_BLOB ; break ; case BPDB_MARIADB_COLUMN_TYPE_ENUM : new_bind_result -> buffer_type = MYSQL_TYPE_ENUM ; break ; case BPDB_MARIADB_COLUMN_TYPE_DATE : new_bind_result -> buffer_type = MYSQL_TYPE_DATE ; break ; case BPDB_MARIADB_COLUMN_TYPE_TIME : new_bind_result -> buffer_type = MYSQL_TYPE_TIME ; break ; case BPDB_MARIADB_COLUMN_TYPE_DATETIME : new_bind_result -> buffer_type = MYSQL_TYPE_DATETIME ; break ; case BPDB_MARIADB_COLUMN_TYPE_TIMESTAMP : new_bind_result -> buffer_type = MYSQL_TYPE_TIMESTAMP ; break ; case BPDB_MARIADB_COLUMN_TYPE_YEAR : new_bind_result -> buffer_type = MYSQL_TYPE_YEAR ; break ; default : BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } return ERR_SUCCESS ; }
Attempts to add a result to the select info structure.
Attempts to add a result to the select info structure .
// ensure we have a syntax generator and a bpdb handle // run basic parameter checks // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Allocate Memory for Bind %%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Create TQ if necessary // bind results // ensure you have a bind results allocated // set the bind results reference (for more readable code below) // zero out the new result structure after realloc // increment the bind results count // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Lookup Column Metadata %%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to lookup column metadata for the field // return indicating failure // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Set Bind Result Type from Metadata %%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // switch on the enum type // if we failed a type match, exit with failure // NOTE: Do not add hash table entry here.  If you do, due to potential reallocs //       when adding new entries, the hash table can wind up with bad entries. // return indicating success