static void gen_compile( qli_req* request) { /************************************** * * g e n _ c o m p i l e * ************************************** * * Functional description * Finish off BLR generation for a request, and get it compiled. * **************************************/ qli_rlb* rlb = CHECK_RLB(request->req_blr); STUFF(blr_end); STUFF(blr_eoc); const USHORT length = rlb->rlb_data - rlb->rlb_base; if (QLI_blr) fb_print_blr(rlb->rlb_base, length, 0, 0, 0); qli_dbb* dbb = request->req_database; ISC_STATUS_ARRAY status_vector; if (isc_compile_request(status_vector, &dbb->dbb_handle, &request->req_handle, length, (const char*) rlb->rlb_base)) { GEN_rlb_release (rlb); ERRQ_database_error(dbb, status_vector); } #ifdef DEV_BUILD SCHAR explain_buffer[512]; if (QLI_explain && !isc_request_info(status_vector, &request->req_handle, 0, sizeof(explain_info), explain_info, sizeof(explain_buffer), explain_buffer)) { explain(dbb, (UCHAR*) explain_buffer); } #endif GEN_rlb_release (rlb); }
static bool sleuth( qli_nod* node, const dsc* desc1, const dsc* desc2, const dsc* desc3) { /************************************** * * s l e u t h * ************************************** * * Functional description * Return true if a string (p1, l1) matches a given pattern (p2, l2), * using a pattern language defined in p3, l3. * **************************************/ // Get operator definition string (control string) Firebird::VaryStr<TEMP_STR_LENGTH> temp1; const TEXT* p1; SSHORT l1 = MOVQ_get_string(desc3, &p1, &temp1, TEMP_STR_LENGTH); // Get address and length of search string Firebird::VaryStr<TEMP_STR_LENGTH> temp2; const TEXT* p2; SSHORT l2 = MOVQ_get_string(desc2, &p2, &temp2, TEMP_STR_LENGTH); // Merge search and control strings UCHAR control[256]; l2 = sleuth_merge((const UCHAR*) p2, (const UCHAR*) p1, (const UCHAR*) (p1 + l1), control); // If source is not a blob, do a simple search if (desc1->dsc_dtype != dtype_blob) { l1 = MOVQ_get_string(desc1, &p1, &temp1, TEMP_STR_LENGTH); return sleuth_check(0, (const UCHAR*) p1, (const UCHAR*) (p1 + l1), control, control + l2); } // Source string is a blob, things get interesting bool result = false; FB_API_HANDLE blob = EXEC_open_blob(node->nod_arg[0]); TEXT fixed_buffer[512]; USHORT buffer_length = sizeof(fixed_buffer); TEXT* buffer = make_blob_buffer( blob, &buffer_length); if (!buffer) buffer = fixed_buffer; ISC_STATUS_ARRAY status_vector; while (!isc_get_segment(status_vector, &blob, (USHORT*) &l1, buffer_length, buffer)) if (sleuth_check(0, (UCHAR*) buffer, (UCHAR*) (buffer + l1), control, control + l2)) { result = true; break; } if (buffer != fixed_buffer) gds__free(buffer); if (isc_close_blob(status_vector, &blob)) { qli_ctx* context = (qli_ctx*) node->nod_arg[e_fld_context]; qli_req* request = context->ctx_request; qli_dbb* dbb = request->req_database; ERRQ_database_error(dbb, status_vector); } return result; }
static bool string_boolean( qli_nod* node) { /************************************** * * s t r i n g _ b o o l e a n * ************************************** * * Functional description * Perform one of the complex string functions CONTAINING, MATCHES, * or STARTS WITH. * **************************************/ const DSC *desc1, *desc2, *desc3; if (!(desc1 = EVAL_value(node->nod_arg[0])) || (desc1->dsc_missing & DSC_missing) || !(desc2 = EVAL_value(node->nod_arg[1])) || (desc2->dsc_missing & DSC_missing) || (node->nod_arg[2] && (!(desc3 = EVAL_value(node->nod_arg[2])) || (desc3->dsc_missing & DSC_missing)))) { return false; } if (node->nod_type == nod_sleuth) return sleuth(node, desc1, desc2, desc3); // Get address and length of strings const TEXT* p2; Firebird::VaryStr<TEMP_STR_LENGTH> temp2; SSHORT l2 = MOVQ_get_string(desc2, &p2, &temp2, TEMP_STR_LENGTH); // If source is not a blob, do a simple search if (desc1->dsc_dtype != dtype_blob) { Firebird::VaryStr<TEMP_STR_LENGTH> temp1; const TEXT* p1; SSHORT l1 = MOVQ_get_string(desc1, &p1, &temp1, TEMP_STR_LENGTH); return string_function(node, l1, p1, l2, p2); } // Source string is a blob, things get interesting bool result = false; FB_API_HANDLE blob = EXEC_open_blob(node->nod_arg[0]); TEXT fixed_buffer[512]; USHORT buffer_length = sizeof(fixed_buffer); TEXT* buffer = make_blob_buffer( blob, &buffer_length); if (!buffer) buffer = fixed_buffer; ISC_STATUS_ARRAY status_vector; SSHORT l3 = 0; while (!isc_get_segment(status_vector, &blob, (USHORT*) &l3, buffer_length, buffer)) { if (string_function(node, l3, buffer, l2, p2)) { result = true; break; } } if (buffer != fixed_buffer) gds__free(buffer); if (isc_close_blob(status_vector, &blob)) { qli_ctx* context = (qli_ctx*) node->nod_arg[e_fld_context]; qli_req* request = context->ctx_request; qli_dbb* database = request->req_database; ERRQ_database_error(database, status_vector); } return result; }