library/src/databases/bpdb/BP-DBSQLSyntaxGenerators.cc
// Attempts to update the json result registry.
Attempts to update the json result registry.
Attempts to update the json result registry .
BP_ERROR_T BP_DBSGUpdateJSONResultRegistry
(
	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_DBSGUpdateJSONResultRegistry reports that it was run with a NULL select_info parameter.");
		return ERR_FAILURE;
	}
	if(!select_info->fetched_record_hreg)
		return ERR_FAILURE;
	if(!select_info->fetched_record_n)
		return ERR_FAILURE;
	if(select_info->fetched_record_json_hreg)
	{
		BP_DestroyHashTableRegistry(select_info->fetched_record_json_hreg);
	}
	select_info->fetched_record_json_hreg = BP_CreateHashTableRegistry();
	P_BPDB_SQL_TABLE_COLUMN_METADATA col_metadata_iter = NULL;
	char record_buff[128];
	BP_ZERO_STACK(record_buff);
	sprintf(record_buff, "res_idx_%u", select_info->fetched_record_n-1);
	char *top_add_path[4];
	BP_ZERO_STACK(top_add_path);
	top_add_path[0] = (char *) &record_buff;
	if(!BP_HashRegAddTableByPath(select_info->fetched_record_json_hreg, (char **) &top_add_path))
	{
		BP_DestroyHashTableRegistry(select_info->fetched_record_json_hreg);
		BP_DBAddErrorMsg(syngen->bpdb, "BP_DBSGUpdateJSONResultRegistry reports that it failed to add a new top path.");
		return ERR_FAILURE;
	}
	char *lookup_stack[10];
	BP_ZERO_STACK(lookup_stack);
	P_BP_HASH_TABLE_KEYED_ENTRY data_lookup_entry = NULL;
	BP_HASH_ITER_OPEN(select_info->fetched_record_hreg->hive, result_iter)
	{
		top_add_path[1] = result_iter->key;
		BP_HashRegAddTableByPath(select_info->fetched_record_json_hreg, (char **) &top_add_path);
		col_metadata_iter = BP_DBLookupTableColumnMetadataFromJoinedFieldName(syngen->bpdb, result_iter->key);
		if(col_metadata_iter)
		{
			char * col_type = BP_DBMariadbColumnTypeToString(col_metadata_iter->mariadb_column_metadata.data_type_as_enum);
			BP_HashRegAddDataToTableByPath
			(
				select_info->fetched_record_json_hreg,
				top_add_path,
				"type",
				BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING,
				col_type,
				bpstrlen(col_type)
			);
			bpfree(col_type);
		}
		%
		%
		MYSQL_BIND * col_bind_info = BP_DBSGLookupResultByFieldName(syngen, select_info, result_iter->key);
		if(col_bind_info)
		{
			char * out_val = BP_DBMariadbConvertColumnResultDataToJSONData
			(
				col_bind_info,
				col_metadata_iter->mariadb_column_metadata.data_type_as_enum
			);
			BP_HashRegAddDataToTableByPath
			(
				select_info->fetched_record_json_hreg,
				top_add_path,
				"value",
				BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING,
				out_val,
				bpstrlen(out_val)
			);
			switch(col_metadata_iter->mariadb_column_metadata.data_type_as_enum)
			{
				case BPDB_MARIADB_COLUMN_TYPE_CHAR:
				case BPDB_MARIADB_COLUMN_TYPE_VARCHAR:
				case BPDB_MARIADB_COLUMN_TYPE_BINARY:
				case BPDB_MARIADB_COLUMN_TYPE_VARBINARY:
				case BPDB_MARIADB_COLUMN_TYPE_TINYBLOB:
				case BPDB_MARIADB_COLUMN_TYPE_BLOB:
				case BPDB_MARIADB_COLUMN_TYPE_MEDIUMBLOB:
				case BPDB_MARIADB_COLUMN_TYPE_LONGBLOB:
				case BPDB_MARIADB_COLUMN_TYPE_TINYTEXT:
				case BPDB_MARIADB_COLUMN_TYPE_TEXT:
				case BPDB_MARIADB_COLUMN_TYPE_MEDIUMTEXT:
				case BPDB_MARIADB_COLUMN_TYPE_LONGTEXT:
					BP_HashRegAddDataToTableByPath
					(
						select_info->fetched_record_json_hreg,
						top_add_path,
						"is_base64",
						BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING,
						(char *) "true",
						bpstrlen("true")
					);
					break;
				default:
					break;
			}
			bpfree(out_val);
		}
	} BP_HASH_ITER_CLOSE;
	return ERR_SUCCESS;
}
BP_ERROR_T BP_DBSGUpdateJSONResultRegistry ( 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 -> fetched_record_hreg ) return ERR_FAILURE ; if ( ! select_info -> fetched_record_n ) return ERR_FAILURE ; if ( select_info -> fetched_record_json_hreg ) { BP_DestroyHashTableRegistry ( select_info -> fetched_record_json_hreg ) ; } select_info -> fetched_record_json_hreg = BP_CreateHashTableRegistry ( ) ; P_BPDB_SQL_TABLE_COLUMN_METADATA col_metadata_iter = NULL ; char record_buff [ 128 ] ; BP_ZERO_STACK ( record_buff ) ; sprintf ( record_buff , " " , select_info -> fetched_record_n - 1 ) ; char * top_add_path [ 4 ] ; BP_ZERO_STACK ( top_add_path ) ; top_add_path [ 0 ] = ( char * ) & record_buff ; if ( ! BP_HashRegAddTableByPath ( select_info -> fetched_record_json_hreg , ( char * * ) & top_add_path ) ) { BP_DestroyHashTableRegistry ( select_info -> fetched_record_json_hreg ) ; BP_DBAddErrorMsg ( syngen -> bpdb , " " ) ; return ERR_FAILURE ; } char * lookup_stack [ 10 ] ; BP_ZERO_STACK ( lookup_stack ) ; P_BP_HASH_TABLE_KEYED_ENTRY data_lookup_entry = NULL ; BP_HASH_ITER_OPEN ( select_info -> fetched_record_hreg -> hive , result_iter ) { top_add_path [ 1 ] = result_iter -> key ; BP_HashRegAddTableByPath ( select_info -> fetched_record_json_hreg , ( char * * ) & top_add_path ) ; col_metadata_iter = BP_DBLookupTableColumnMetadataFromJoinedFieldName ( syngen -> bpdb , result_iter -> key ) ; if ( col_metadata_iter ) { char * col_type = BP_DBMariadbColumnTypeToString ( col_metadata_iter -> mariadb_column_metadata . data_type_as_enum ) ; BP_HashRegAddDataToTableByPath ( select_info -> fetched_record_json_hreg , top_add_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , col_type , bpstrlen ( col_type ) ) ; bpfree ( col_type ) ; } MYSQL_BIND * col_bind_info = BP_DBSGLookupResultByFieldName ( syngen , select_info , result_iter -> key ) ; if ( col_bind_info ) { char * out_val = BP_DBMariadbConvertColumnResultDataToJSONData ( col_bind_info , col_metadata_iter -> mariadb_column_metadata . data_type_as_enum ) ; BP_HashRegAddDataToTableByPath ( select_info -> fetched_record_json_hreg , top_add_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , out_val , bpstrlen ( out_val ) ) ; switch ( col_metadata_iter -> mariadb_column_metadata . data_type_as_enum ) { case BPDB_MARIADB_COLUMN_TYPE_CHAR : case BPDB_MARIADB_COLUMN_TYPE_VARCHAR : case BPDB_MARIADB_COLUMN_TYPE_BINARY : case BPDB_MARIADB_COLUMN_TYPE_VARBINARY : case BPDB_MARIADB_COLUMN_TYPE_TINYBLOB : case BPDB_MARIADB_COLUMN_TYPE_BLOB : case BPDB_MARIADB_COLUMN_TYPE_MEDIUMBLOB : case BPDB_MARIADB_COLUMN_TYPE_LONGBLOB : case BPDB_MARIADB_COLUMN_TYPE_TINYTEXT : case BPDB_MARIADB_COLUMN_TYPE_TEXT : case BPDB_MARIADB_COLUMN_TYPE_MEDIUMTEXT : case BPDB_MARIADB_COLUMN_TYPE_LONGTEXT : BP_HashRegAddDataToTableByPath ( select_info -> fetched_record_json_hreg , top_add_path , " " , BP_HASH_TABLE_KEYED_ENTRY_TYPE_UTF8_STRING , ( char * ) " " , bpstrlen ( " " ) ) ; break ; default : break ; } bpfree ( out_val ) ; } } BP_HASH_ITER_CLOSE ; return ERR_SUCCESS ; }
Attempts to update the json result registry.
Attempts to update the json result registry .
// ensure we have a syngen // ensure we have select info // ensure we have a record registry // If a hreg already exists we have to destroy/recreate it. // destroy the registry // --- create new registry and translate record data ---------- // create new registry // column metadata iterator // create some stack to hold a potential record // fill in the buffer // -- attempt to add top path -- // create the top add path // set the record buff as the top path // add result header // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Utility Macros %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create lookup stack // set lookup entry to null // iterate through the hashes // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Top Level Path %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // set the add path from the key // add new table // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Lookup Metadata and Set Type %%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to lookup column data from bpdb // get column type from bin type (since type is sent in json) // add data to table by path query // destroy column type // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add Data From Bind (based on type) %%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // get column type from bin type (since type is sent in json) // char * col_type = BP_DBMariadbColumnTypeToString(col_metadata_iter->mariadb_column_metadata.data_type_as_enum); // attempt to retrieve bind info // attempt to autoconvert data to json format // add data to table by path query // switch on column type // all blob types are base64, mark json as such // mark record as base64 // all other types are unmarked as base64 // destroy column type // return indicating success