library/src/databases/bpdb/BP-DBJSON.cc
// attempt to separate right join string elements into their parts (stored in join_data_in_out)
attempt to separate right join string elements into their parts (stored in join_data_in_out)
attempt to separate right join string elements into their parts ( stored in join_data_in_out )
BP_ERROR_T BP_DBJSONSeparateRightJoinStringIntoParts
(
	P_BPDB_SQLGEN syngen,
	P_BPDB_SELECT_JOIN join_data_in_out,
	char *string_elements
)
{
	if(!syngen)
		return ERR_FAILURE;
	if(!syngen->bpdb)
		return ERR_FAILURE;
	P_BPDB bpdb = syngen->bpdb;
	if(!bpdb)
		return ERR_FAILURE;
	if(!join_data_in_out)
		return ERR_FAILURE;
	if(!string_elements)
		return ERR_FAILURE;
	if(!BP_StringIsReasonablePrintableString(string_elements, bpstrlen(string_elements), BP_FALSE, BP_FALSE))
		return ERR_FAILURE;
	printf("\n Attempting to separate join parts here woo: %s", string_elements);
	size_t string_element_len = bpstrlen(string_elements);
	if(string_element_len < 7)
		return ERR_FAILURE;
    BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config;
    BP_ZERO_STACK(ascii_config);
    ascii_config.count_ascii                      = BP_TRUE;
    ascii_config.count_extended                   = BP_TRUE;
    ascii_config.count_individual_characters      = BP_TRUE;
    P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis
    (
		(unsigned char *) string_elements,
		(size_t) bpstrlen(string_elements),
		&ascii_config
    );
    if(!buff_analysis)
    	return ERR_FAILURE;
    if(buff_analysis->ascii->char_counts['='] != 1)
    {
    	BP_DestroyBufferAnalysis(buff_analysis);
    	return ERR_FAILURE;
    }
    if(buff_analysis->ascii->char_counts['.'] != 2)
    {
    	BP_DestroyBufferAnalysis(buff_analysis);
        return ERR_FAILURE;
    }
    BP_DestroyBufferAnalysis(buff_analysis);
    buff_analysis = NULL;
    char * parse_buff = BP_FindRemoveBin
    (
		string_elements,
		string_element_len,
		" ",
		1,
		BP_KILOBYTE
    );
    if(!parse_buff)
    	return ERR_FAILURE;
    char ** elements = BP_ExplodeBufferBin(parse_buff, bpstrlen(parse_buff), "=", 1, 3);
    if(!elements)
    	return ERR_FAILURE;
    if(BP_CountNullTerminatedPtrArray(elements) != 2)
    {
    	BP_DestroyPointerArrayNullTerminated((void **) elements);
    	bpfree(elements);
    	bpfree(parse_buff);
    	return ERR_FAILURE;
    }
    if
	(
			elements[0][0] == '.' || elements[0][bpstrlen(elements[0])-1] == '.' ||
			elements[1][0] == '.' || elements[1][bpstrlen(elements[1])-1] == '.'
	)
    {
    	BP_DestroyPointerArrayNullTerminated((void **) elements);
		bpfree(elements);
		bpfree(parse_buff);
		return ERR_FAILURE;
    }
    char ** table_col_split = BP_SplitBuffer(elements[0], ".");
    if(!table_col_split)
    {
    	BP_DestroyPointerArrayNullTerminated((void **) elements);
		bpfree(elements);
		bpfree(parse_buff);
		return ERR_FAILURE;
    }
    join_data_in_out->table_name          = ht_strdup(syngen->system_hreg, table_col_split[0]);
    join_data_in_out->front_join          = ht_strdup(syngen->system_hreg, elements[0]);
    join_data_in_out->comparison_operator = ht_strdup(syngen->system_hreg, "=");
    join_data_in_out->tail_join           = ht_strdup(syngen->system_hreg, elements[1]);
    join_data_in_out->join_type           = BPDB_SELECT_JOIN_TYPE_RIGHT_JOIN;
	BP_DestroyPointerArrayNullTerminated((void **) elements);
    BP_DestroyPointerArrayNullTerminated((void **) table_col_split);
	bpfree(elements);
	bpfree(table_col_split);
	bpfree(parse_buff);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_DBJSONSeparateRightJoinStringIntoParts ( P_BPDB_SQLGEN syngen , P_BPDB_SELECT_JOIN join_data_in_out , char * string_elements ) { if ( ! syngen ) return ERR_FAILURE ; if ( ! syngen -> bpdb ) return ERR_FAILURE ; P_BPDB bpdb = syngen -> bpdb ; if ( ! bpdb ) return ERR_FAILURE ; if ( ! join_data_in_out ) return ERR_FAILURE ; if ( ! string_elements ) return ERR_FAILURE ; if ( ! BP_StringIsReasonablePrintableString ( string_elements , bpstrlen ( string_elements ) , BP_FALSE , BP_FALSE ) ) return ERR_FAILURE ; printf ( " \n " , string_elements ) ; size_t string_element_len = bpstrlen ( string_elements ) ; if ( string_element_len < 7 ) return ERR_FAILURE ; BP_BUFFER_ANALYSIS_ASCII_CONFIGURATION ascii_config ; BP_ZERO_STACK ( ascii_config ) ; ascii_config . count_ascii = BP_TRUE ; ascii_config . count_extended = BP_TRUE ; ascii_config . count_individual_characters = BP_TRUE ; P_BP_BUFFER_ANALYSIS buff_analysis = BP_CreateBufferAnalysis ( ( unsigned char * ) string_elements , ( size_t ) bpstrlen ( string_elements ) , & ascii_config ) ; if ( ! buff_analysis ) return ERR_FAILURE ; if ( buff_analysis -> ascii -> char_counts [ ' ' ] != 1 ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return ERR_FAILURE ; } if ( buff_analysis -> ascii -> char_counts [ ' ' ] != 2 ) { BP_DestroyBufferAnalysis ( buff_analysis ) ; return ERR_FAILURE ; } BP_DestroyBufferAnalysis ( buff_analysis ) ; buff_analysis = NULL ; char * parse_buff = BP_FindRemoveBin ( string_elements , string_element_len , " " , 1 , BP_KILOBYTE ) ; if ( ! parse_buff ) return ERR_FAILURE ; char * * elements = BP_ExplodeBufferBin ( parse_buff , bpstrlen ( parse_buff ) , " " , 1 , 3 ) ; if ( ! elements ) return ERR_FAILURE ; if ( BP_CountNullTerminatedPtrArray ( elements ) != 2 ) { BP_DestroyPointerArrayNullTerminated ( ( void * * ) elements ) ; bpfree ( elements ) ; bpfree ( parse_buff ) ; return ERR_FAILURE ; } if ( elements [ 0 ] [ 0 ] == ' ' || elements [ 0 ] [ bpstrlen ( elements [ 0 ] ) - 1 ] == ' ' || elements [ 1 ] [ 0 ] == ' ' || elements [ 1 ] [ bpstrlen ( elements [ 1 ] ) - 1 ] == ' ' ) { BP_DestroyPointerArrayNullTerminated ( ( void * * ) elements ) ; bpfree ( elements ) ; bpfree ( parse_buff ) ; return ERR_FAILURE ; } char * * table_col_split = BP_SplitBuffer ( elements [ 0 ] , " " ) ; if ( ! table_col_split ) { BP_DestroyPointerArrayNullTerminated ( ( void * * ) elements ) ; bpfree ( elements ) ; bpfree ( parse_buff ) ; return ERR_FAILURE ; } join_data_in_out -> table_name = ht_strdup ( syngen -> system_hreg , table_col_split [ 0 ] ) ; join_data_in_out -> front_join = ht_strdup ( syngen -> system_hreg , elements [ 0 ] ) ; join_data_in_out -> comparison_operator = ht_strdup ( syngen -> system_hreg , " " ) ; join_data_in_out -> tail_join = ht_strdup ( syngen -> system_hreg , elements [ 1 ] ) ; join_data_in_out -> join_type = BPDB_SELECT_JOIN_TYPE_RIGHT_JOIN ; BP_DestroyPointerArrayNullTerminated ( ( void * * ) elements ) ; BP_DestroyPointerArrayNullTerminated ( ( void * * ) table_col_split ) ; bpfree ( elements ) ; bpfree ( table_col_split ) ; bpfree ( parse_buff ) ; return ERR_SUCCESS ; }
attempt to separate right join string elements into their parts (stored in join_data_in_out)
attempt to separate right join string elements into their parts ( stored in join_data_in_out )
// set syntax generator // set bpdb // run basic checks // calculate elements length // shortest element is 7 bytes: // t.i=o.i // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Basic Buffer Analysis %%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create ascii configuration // set some flags in the structure (default is BP_FALSE aka 0) // attempt to generate analysis // ensure we created a new buffer analysis // there should always be one equals sign // there should always be two periods // destroy the buffer analysis // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Strip Spaces and Create Buffer %%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create initial parse buffer by stripping strings // ensure the parse buffer was created ok // set elements // ensure that there are only two elements in the array // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Run Element Checks %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // table separator must exist in the middle of the string, not the // front or back. // split the first table since we need to extract the table name // perform assignments // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Cleanup And Exit %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // destroy data // return indicating success