library/src/databases/bpdb/BP-DBSQLSyntaxGenerators.cc
// Adds a select parameter to a select info query.  This shouldn't be used directly.  This is used internally
// by BP_DBSGSelectFrom to add parameters inline.
Adds a select parameter to a select info query.  This shouldn't be used directly.  This is used internally
by BP_DBSGSelectFrom to add parameters inline.
Adds a select parameter to a select info query . This shouldn ' t be used directly . This is used internally by BP_DBSGSelectFrom to add parameters inline .
BP_ERROR_T BP_DBAddSelectWhereParameterToSelectInfo
(
	P_BPDB_SQLGEN        syngen,
	P_BPDB_SQLGEN_SELECT select_info,
	P_BPDB_SELECT_WHERE  select_where
)
{
	if(!syngen)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectWhereParameterToSelectInfo provided syngen parameter was null.");
		return ERR_FAILURE;
	}
	if(!syngen->bpdb)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectWhereParameterToSelectInfo provided syngen had no bpdb member (syngen->bpdb == NULL).");
		return ERR_FAILURE;
	}
	if(!select_info)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectWhereParameterToSelectInfo was called with a NULL select_info parameter.");
		return ERR_FAILURE;
	}
	if(!select_where)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectWhereParameterToSelectInfo was called with a NULL select_where parameter.");
		return ERR_FAILURE;
	}
	if(!select_info->bind_parameters_tq_allocator)
		select_info->bind_parameters_tq_allocator = BP_CreateLinkL(".", BP_TRUE);
	select_info->bind_parameters = (MYSQL_BIND *) tq_realloc
	(
		select_info->bind_parameters_tq_allocator,
		select_info->bind_parameters,
		sizeof(MYSQL_BIND) * (select_info->bind_parameters_n + 1),
		BPLN
	);
	if(!select_info->bind_parameters)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectWhereParameterToSelectInfo failed to allocate space for bind parameters.");
		return ERR_FAILURE;
	}
	MYSQL_BIND * new_bind_parameter = &select_info->bind_parameters[select_info->bind_parameters_n];
	memset(new_bind_parameter, 0x00, sizeof(MYSQL_BIND));
	select_info->bind_parameters_n++;
	P_BPDB_SQL_TABLE_COLUMN_METADATA column_metadata = BP_DBLookupTableColumnMetadataFromJoinedFieldName(syngen->bpdb, select_where->field_name);
	if(!column_metadata)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectWhereParameterToSelectInfo called BP_DBLookupTableColumnMetadataFromJoinedFieldName but it failed.");
		return ERR_FAILURE;
	}
	void * selected_value       = NULL;
	size_t selected_value_len = 0;
	long int * tmp_long_int_ptr = NULL;
	switch(select_where->value_type)
	{
		case BPDB_SELECT_WHERE_VALUE_TYPE_UNSET:
			break;
		case BPDB_SELECT_WHERE_VALUE_TYPE_HEX_STRING:
		case BPDB_SELECT_WHERE_VALUE_TYPE_POSITIVE_INTEGER:
		case BPDB_SELECT_WHERE_VALUE_TYPE_NEGATIVE_INTEGER:
		case BPDB_SELECT_WHERE_VALUE_TYPE_QUOTED_LITERAL:
		case BPDB_SELECT_WHERE_VALUE_TYPE_TABLE_AND_COLUMN:
			printf("\n [QUOTED STRING] THIS IS THE FINAL VALUE AS A QUOTED STRING: %s", select_where->value);
			selected_value = select_where->value;
			new_bind_parameter->buffer_type = MYSQL_TYPE_BLOB;
			break;
		default:
			break;
	}
	if(!selected_value)
	{
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectWhereParameterToSelectInfo had value type conversion fail.");
		return ERR_FAILURE;
	}
	int32_t tmp_converted_int32 = 0;
	int     tmp_converted_int64 = 0;
	switch(new_bind_parameter->buffer_type)
	{
		case MYSQL_TYPE_TINY:
		case MYSQL_TYPE_SHORT:
		case MYSQL_TYPE_INT24:
		case MYSQL_TYPE_LONG:
			selected_value_len = 4;
			break;
		case MYSQL_TYPE_LONGLONG:
			selected_value_len = 8;
			break;
		case MYSQL_TYPE_FLOAT:
			selected_value_len = 8;
			break;
		case MYSQL_TYPE_DOUBLE:
			selected_value_len = 8;
			break;
		case MYSQL_TYPE_STRING:
		case MYSQL_TYPE_VAR_STRING:
		case MYSQL_TYPE_BLOB:
			selected_value_len = select_where->value_len;
			break;
		case MYSQL_TYPE_DATE:
		case MYSQL_TYPE_TIME:
		case MYSQL_TYPE_DATETIME:
		case MYSQL_TYPE_TIMESTAMP:
		case MYSQL_TYPE_YEAR:
			selected_value_len = sizeof(MYSQL_TIME);
			break;
		default:
			break;
	}
	new_bind_parameter->buffer        = select_where->value;
	new_bind_parameter->buffer_length = select_where->value_len;
	printf("\n Got the Buffer Length at end of addition?: %zu", new_bind_parameter->buffer_length);
	printf("\n Got here with value %u: %s (buffer type: %u)", select_where->value_len, select_where->value, new_bind_parameter->buffer_type);
	BP_DBAddNoticeMsg(syngen->bpdb, "BPDB Syntax generator got here ok?!", NULL);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_DBAddSelectWhereParameterToSelectInfo ( P_BPDB_SQLGEN syngen , P_BPDB_SQLGEN_SELECT select_info , P_BPDB_SELECT_WHERE select_where ) { if ( ! syngen ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! syngen -> bpdb ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! select_info ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! select_where ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } if ( ! select_info -> bind_parameters_tq_allocator ) select_info -> bind_parameters_tq_allocator = BP_CreateLinkL ( " " , BP_TRUE ) ; select_info -> bind_parameters = ( MYSQL_BIND * ) tq_realloc ( select_info -> bind_parameters_tq_allocator , select_info -> bind_parameters , sizeof ( MYSQL_BIND ) * ( select_info -> bind_parameters_n + 1 ) , BPLN ) ; if ( ! select_info -> bind_parameters ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } MYSQL_BIND * new_bind_parameter = & select_info -> bind_parameters [ select_info -> bind_parameters_n ] ; memset ( new_bind_parameter , 0x00 , sizeof ( MYSQL_BIND ) ) ; select_info -> bind_parameters_n ++ ; P_BPDB_SQL_TABLE_COLUMN_METADATA column_metadata = BP_DBLookupTableColumnMetadataFromJoinedFieldName ( syngen -> bpdb , select_where -> field_name ) ; if ( ! column_metadata ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } void * selected_value = NULL ; size_t selected_value_len = 0 ; long int * tmp_long_int_ptr = NULL ; switch ( select_where -> value_type ) { case BPDB_SELECT_WHERE_VALUE_TYPE_UNSET : break ; case BPDB_SELECT_WHERE_VALUE_TYPE_HEX_STRING : case BPDB_SELECT_WHERE_VALUE_TYPE_POSITIVE_INTEGER : case BPDB_SELECT_WHERE_VALUE_TYPE_NEGATIVE_INTEGER : case BPDB_SELECT_WHERE_VALUE_TYPE_QUOTED_LITERAL : case BPDB_SELECT_WHERE_VALUE_TYPE_TABLE_AND_COLUMN : printf ( " \n " , select_where -> value ) ; selected_value = select_where -> value ; new_bind_parameter -> buffer_type = MYSQL_TYPE_BLOB ; break ; default : break ; } if ( ! selected_value ) { BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } int32_t tmp_converted_int32 = 0 ; int tmp_converted_int64 = 0 ; switch ( new_bind_parameter -> buffer_type ) { case MYSQL_TYPE_TINY : case MYSQL_TYPE_SHORT : case MYSQL_TYPE_INT24 : case MYSQL_TYPE_LONG : selected_value_len = 4 ; break ; case MYSQL_TYPE_LONGLONG : selected_value_len = 8 ; break ; case MYSQL_TYPE_FLOAT : selected_value_len = 8 ; break ; case MYSQL_TYPE_DOUBLE : selected_value_len = 8 ; break ; case MYSQL_TYPE_STRING : case MYSQL_TYPE_VAR_STRING : case MYSQL_TYPE_BLOB : selected_value_len = select_where -> value_len ; break ; case MYSQL_TYPE_DATE : case MYSQL_TYPE_TIME : case MYSQL_TYPE_DATETIME : case MYSQL_TYPE_TIMESTAMP : case MYSQL_TYPE_YEAR : selected_value_len = sizeof ( MYSQL_TIME ) ; break ; default : break ; } new_bind_parameter -> buffer = select_where -> value ; new_bind_parameter -> buffer_length = select_where -> value_len ; printf ( " \n " , new_bind_parameter -> buffer_length ) ; printf ( " \n " , select_where -> value_len , select_where -> value , new_bind_parameter -> buffer_type ) ; BP_DBAddNoticeMsg ( syngen -> bpdb , " " , NULL ) ; return ERR_SUCCESS ; }
Adds a select parameter to a select info query.
Adds a select parameter to a select info query .
// run basic parameter checks // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Allocate Memory for Bind %%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Create TQ if necessary // bind parameters // ensure you have a bind parameter allocated // set the bind parameter reference (for more readable code below) // zero out the bind parameter // increment the bind parameter count // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Lookup Column Metadata %%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to lookup column metadata for the field // return indicating failure // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Set Bind Parameter Type from Metadata %% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /*

	// switch on the enum type
	switch(column_metadata->mariadb_column_metadata.data_type_as_enum)
	{

		case BPDB_MARIADB_COLUMN_TYPE_TINYINT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_TINY;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_SMALLINT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_SHORT;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_MEDIUMINT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_INT24;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_INT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_LONG;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_BIGINT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_LONGLONG;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_DECIMAL:
			new_bind_parameter->buffer_type = MYSQL_TYPE_DECIMAL;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_FLOAT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_FLOAT;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_DOUBLE:
			new_bind_parameter->buffer_type = MYSQL_TYPE_DOUBLE;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_BIT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_BIT;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_CHAR:
			new_bind_parameter->buffer_type = MYSQL_TYPE_STRING;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_VARCHAR:
			new_bind_parameter->buffer_type = MYSQL_TYPE_VAR_STRING;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_BINARY:
			new_bind_parameter->buffer_type = MYSQL_TYPE_STRING;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_VARBINARY:
			new_bind_parameter->buffer_type = MYSQL_TYPE_VAR_STRING;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TINYBLOB:
			new_bind_parameter->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_BLOB:
			break;
		case BPDB_MARIADB_COLUMN_TYPE_MEDIUMBLOB:
			new_bind_parameter->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_LONGBLOB:
			new_bind_parameter->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TINYTEXT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TEXT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_MEDIUMTEXT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_LONGTEXT:
			new_bind_parameter->buffer_type = MYSQL_TYPE_BLOB;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_ENUM:
			new_bind_parameter->buffer_type = MYSQL_TYPE_ENUM;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_DATE:
			new_bind_parameter->buffer_type = MYSQL_TYPE_DATE;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TIME:
			new_bind_parameter->buffer_type = MYSQL_TYPE_TIME;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_DATETIME:
			new_bind_parameter->buffer_type = MYSQL_TYPE_DATETIME;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_TIMESTAMP:
			new_bind_parameter->buffer_type = MYSQL_TYPE_TIMESTAMP;
			break;
		case BPDB_MARIADB_COLUMN_TYPE_YEAR:
			new_bind_parameter->buffer_type = MYSQL_TYPE_YEAR;
			break;

		// if we failed a type match, exit with failure
		default:
			BP_DBAddErrorMsg(syngen->bpdb, "BP_DBAddSelectWhereParameterToSelectInfo attempted to lookup metadata type, but failed.  This should never happen.");
			return ERR_FAILURE;

	}

	*/ // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Perform Value Conversions %%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // selected/converted values // temporary long integer pointer used for conversion // switch on the value type /*
		// convert integers
		case BPDB_SELECT_WHERE_VALUE_TYPE_NEGATIVE_INTEGER:
			tmp_long_int_ptr = (long int *) select_where->value;
			selected_value = tmp_long_int_ptr;
			printf("\n [NEGATIVE INT] THIS IS THE FINAL VALUE AS A NEGATIVE INTEGER: %s", tmp_long_int_ptr);
			new_bind_parameter->buffer_type = MYSQL_TYPE_LONG;
			break;

		case BPDB_SELECT_WHERE_VALUE_TYPE_POSITIVE_INTEGER:
			tmp_long_int_ptr = (long int *) select_where->value;

			printf("\n [POSITIVE INT] THIS IS THE FINAL VALUE AS A POSITIVE INTEGER: %s", tmp_long_int_ptr);
			selected_value = tmp_long_int_ptr;
			new_bind_parameter->buffer_type = MYSQL_TYPE_LONG;
			break;
		*/ // hex strings must be converted to // break on default // set selected value // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Convert Parameters %%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // not supported // case MYSQL_TYPE_ENUM: // case MYSQL_TYPE_BIT: // case MYSQL_TYPE_DECIMAL: // 64bit int // add date fields // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Set Parameter Data %%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set value and value_len // return indicating success