ORAEXT void oraImportRDF (OCIExtProcContext *ctx, const char *table_name, short table_name_ind, const char *clob_col_name, short clob_col_ind, const char *other_col_names, short other_col_ind, const char *file_name, short file_name_ind) { logger.initIfClosed(log_filename); ORABLOCK_BEGIN { OracleEnv env(ctx, logger); if (table_name_ind != OCI_IND_NOTNULL) throw BingoError("null table name"); if (clob_col_ind != OCI_IND_NOTNULL) throw BingoError("null table name"); if (clob_col_ind != OCI_IND_NOTNULL) throw BingoError("null file name"); if (other_col_ind != OCI_IND_NOTNULL) other_col_names = 0; _importRDF(env, table_name, clob_col_name, other_col_names, file_name); } ORABLOCK_END }
ORAEXT void oraImportSMILES (OCIExtProcContext *ctx, const char *table_name, short table_name_ind, const char *smiles_col_name, short smiles_col_ind, const char *id_col_name, short id_col_ind, const char *file_name, short file_name_ind) { logger.initIfClosed(log_filename); ORABLOCK_BEGIN { OracleEnv env(ctx, logger); if (table_name_ind != OCI_IND_NOTNULL) throw BingoError("null table name"); if (smiles_col_ind != OCI_IND_NOTNULL) throw BingoError("null SMILES column name"); if (file_name_ind != OCI_IND_NOTNULL) throw BingoError("null file name"); if (id_col_ind != OCI_IND_NOTNULL) id_col_name = 0; _importSMILES(env, table_name, smiles_col_name, id_col_name, file_name); } ORABLOCK_END }
ORAEXT void oraExportSDFZip (OCIExtProcContext *ctx, const char *table_name, short table_name_ind, const char *clob_col_name, short clob_col_ind, const char *other_col_names, short other_col_ind, const char *file_name, short file_name_ind) { logger.initIfClosed(log_filename); ORABLOCK_BEGIN { OracleEnv env(ctx, logger); if (table_name_ind != OCI_IND_NOTNULL) throw BingoError("null table name"); if (clob_col_ind != OCI_IND_NOTNULL) throw BingoError("null CLOB column name"); if (file_name_ind != OCI_IND_NOTNULL) throw BingoError("null file name"); if (other_col_ind != OCI_IND_NOTNULL) other_col_names = 0; FileOutput output(file_name); GZipOutput gzoutput(output, 9); _exportSDF(env, table_name, clob_col_name, other_col_names, gzoutput); } ORABLOCK_END }
ORAEXT void oraImportSDF (OCIExtProcContext *ctx, const char *table_name, short table_name_ind, const char *clob_col_name, short clob_col_ind, const char *other_col_names, short other_col_ind, const char *file_name, short file_name_ind) { logger.initIfClosed(log_filename); ORABLOCK_BEGIN { profTimersReset(); profTimerStart(ttotal, "total"); OracleEnv env(ctx, logger); if (table_name_ind != OCI_IND_NOTNULL) throw BingoError("null table name"); if (clob_col_ind != OCI_IND_NOTNULL) throw BingoError("null table name"); if (clob_col_ind != OCI_IND_NOTNULL) throw BingoError("null file name"); if (other_col_ind != OCI_IND_NOTNULL) other_col_names = 0; _importSDF(env, table_name, clob_col_name, other_col_names, file_name); profTimerStop(ttotal); bingoProfilingPrintStatistics(false); } ORABLOCK_END }
ORAEXT OCIString * oraConfigGetString (OCIExtProcContext *ctx, int context_id, char *key_name, short key_name_indicator, short *return_indicator) { OCIString *result = NULL; ORABLOCK_BEGIN { *return_indicator = OCI_IND_NULL; OracleEnv env(ctx, logger); if (key_name_indicator != OCI_IND_NOTNULL) throw BingoError("Null key is given"); QS_DEF(Array<char>, value); BingoOracleContext &context = BingoOracleContext::get(env, context_id, false, 0); if (!context.configGetString(env, key_name, value)) throw BingoError("Key wasn't found"); env.callOCI(OCIStringAssignText(env.envhp(), env.errhp(), (text *)value.ptr(), value.size() - 1, &result)); *return_indicator = OCI_IND_NOTNULL; } ORABLOCK_END return result; }
ORAEXT OCINumber * oraConfigGetFloat (OCIExtProcContext *ctx, int context_id, char *key_name, short key_name_indicator, short *return_indicator) { OCINumber *result = NULL; ORABLOCK_BEGIN { *return_indicator = OCI_IND_NULL; OracleEnv env(ctx, logger); if (key_name_indicator != OCI_IND_NOTNULL) throw BingoError("Null key is given"); float value; BingoOracleContext &context = BingoOracleContext::get(env, context_id, false, 0); if (!context.configGetFloat(env, key_name, value)) throw BingoError("Key wasn't found"); result = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber)); if (result == NULL) throw BingoError("can't allocate memory for number"); double value_double = value; env.callOCI(OCINumberFromReal(env.errhp(), &value_double, sizeof(value_double), result)); *return_indicator = OCI_IND_NOTNULL; } ORABLOCK_END return result; }
static void _ringoIndexStart (OracleEnv &env, RingoFetchContext &context, const char *oper, const Array<char> &query_buf, OCINumber *p_strt, OCINumber *p_stop, const char *params) { RingoShadowFetch &shadow_fetch = context.shadow_fetch.ref(); RingoFastIndex &fast_index = context.fast_index.ref(); if (strcasecmp(oper, "RSUB") == 0) { if (!context.substructure.parse(params)) throw BingoError("can not parse parameters: %s", params); context.substructure.loadQuery(query_buf); int right = bingoGetExactRightPart(env, p_strt, p_stop, 64); if (right == 1) { fast_index.prepareSubstructure(env); context.fetch_engine = &fast_index; } else // right == 0 { shadow_fetch.prepareNonSubstructure(env); context.fetch_engine = &shadow_fetch; } } else if (strcasecmp(oper, "RSMARTS") == 0) { context.substructure.loadSMARTS(query_buf); int right = bingoGetExactRightPart(env, p_strt, p_stop, 64); if (right == 1) { fast_index.prepareSubstructure(env); context.fetch_engine = &fast_index; } else // right == 0 { shadow_fetch.prepareNonSubstructure(env); context.fetch_engine = &shadow_fetch; } } else if (strcasecmp(oper, "REXACT") == 0) { context.exact.setParameters(params); context.exact.loadQuery(query_buf); int right = bingoGetExactRightPart(env, p_strt, p_stop, 64); shadow_fetch.prepareExact(env, right); context.fetch_engine = &shadow_fetch; } else throw BingoError("unknown operator: %s", oper); }
ORAEXT OCILobLocator *oraLoadFileToBLOB (OCIExtProcContext *ctx, char *filename, short filename_indicator, short *return_indicator) { OCILobLocator *result = 0; ORABLOCK_BEGIN { *return_indicator = OCI_IND_NULL; OracleEnv env(ctx, logger); if (filename_indicator != OCI_IND_NOTNULL) throw BingoError("Null filename given"); FileScanner scanner(filename); QS_DEF(Array<char>, buf); scanner.readAll(buf); OracleLOB lob(env); lob.createTemporaryBLOB(); lob.write(0, buf.ptr(), buf.size()); *return_indicator = OCI_IND_NOTNULL; lob.doNotDelete(); result = lob.get(); } ORABLOCK_END return result; }
void _parseFieldList (const char *str, StringPool &props, StringPool &columns) { QS_DEF(Array<char>, prop); QS_DEF(Array<char>, column); BufferScanner scanner(str); props.clear(); columns.clear(); scanner.skipSpace(); while (!scanner.isEOF()) { scanner.readWord(prop, " ,"); scanner.skipSpace(); scanner.readWord(column, " ,"); scanner.skipSpace(); props.add(prop.ptr()); columns.add(column.ptr()); if (scanner.isEOF()) break; if (scanner.readChar() != ',') throw BingoError("_parseFieldList(): comma expected"); scanner.skipSpace(); } }
ORAEXT OCIString *oraLoadFileToString (OCIExtProcContext *ctx, char *filename, short filename_indicator, short *return_indicator) { OCIString *result = 0; ORABLOCK_BEGIN { OracleEnv env(ctx, logger); *return_indicator = OCI_IND_NULL; if (filename_indicator != OCI_IND_NOTNULL) throw BingoError("Null filename given"); FileScanner scanner(filename); QS_DEF(Array<char>, buf); scanner.readAll(buf); env.callOCI(OCIStringAssignText(env.envhp(), env.errhp(), (text *)buf.ptr(), buf.size(), &result)); *return_indicator = OCI_IND_NOTNULL; } ORABLOCK_END return result; }
ORAEXT OCINumber * oraRingoSub (OCIExtProcContext *ctx, int context_id, OCILobLocator *target_loc, short target_ind, OCILobLocator *query_loc, short query_ind, const char *params, short params_ind, short *return_ind) { OCINumber *result = NULL; ORABLOCK_BEGIN { OracleEnv env(ctx, logger); *return_ind = OCI_IND_NULL; if (query_ind != OCI_IND_NOTNULL) throw BingoError("Null query given"); if (target_ind != OCI_IND_NOTNULL) throw BingoError("Null target given"); if (params_ind != OCI_IND_NOTNULL) params = 0; RingoOracleContext &context = RingoOracleContext::get(env, context_id, false); QS_DEF(Array<char>, query_buf); QS_DEF(Array<char>, target_buf); OracleLOB target_lob(env, target_loc); OracleLOB query_lob(env, query_loc); target_lob.readAll(target_buf, false); query_lob.readAll(query_buf, false); if (!context.substructure.parse(params)) throw BingoError("can not parse parameters: %s", params); result = _ringoSub(env, context, query_buf, target_buf, params); if (result == 0) // This is needed for Oracle 9. Returning NULL drops the extproc. result = OracleExtproc::createInt(env, 0); else *return_ind = OCI_IND_NOTNULL; } ORABLOCK_END return result; }
int bingoGetExactRightPart (OracleEnv &env, OCINumber *p_strt, OCINumber *p_stop, int flags) { if ((flags & 64) == 0) throw BingoError("only exact match allowed"); if (p_strt == 0 || p_stop == 0) throw BingoError("only exact match allowed"); int strt = OracleUtil::numberToInt(env, p_strt); int stop = OracleUtil::numberToInt(env, p_stop); if (strt != stop) throw BingoError("only exact match allowed"); if (strt != 0 && strt != 1) throw BingoError("only =0 and =1 allowed"); return strt; }
ORAEXT OCINumber * oraProfilingGetTime (OCIExtProcContext *ctx, char *key_name, short key_name_indicator, short *return_indicator) { OCINumber *result = NULL; ORABLOCK_BEGIN { *return_indicator = OCI_IND_NULL; OracleEnv env(ctx, logger); if (key_name_indicator != OCI_IND_NOTNULL) throw BingoError("Null key is given"); float value; // Try to find in profiling data ProfilingSystem &inst = ProfilingSystem::getInstance(); if (inst.hasLabel(key_name)) //throw BingoError("Key wasn't found"); value = inst.getLabelExecTime(key_name); else value = 0; result = (OCINumber *)OCIExtProcAllocCallMemory(ctx, sizeof(OCINumber)); if (result == NULL) throw BingoError("can't allocate memory for number"); double value_double = value; env.callOCI(OCINumberFromReal(env.errhp(), &value_double, sizeof(value_double), result)); *return_indicator = OCI_IND_NOTNULL; } ORABLOCK_END return result; }
void bingoGetTauCondition (const char *list_ptr, int &aromaticity, Array<int> &label_list) { if (isdigit(*list_ptr)) { if (*list_ptr == '1') aromaticity = 1; else if (*list_ptr == '0') aromaticity = 0; else throw BingoError("Bad tautomer configuration string format"); list_ptr++; } else { aromaticity = -1; } label_list.clear(); QS_DEF(Array<char>, buf); buf.clear(); while (*list_ptr != 0) { if (isalpha((unsigned)*list_ptr)) buf.push(*list_ptr); else if (*list_ptr == ',') { buf.push(0); label_list.push(Element::fromString(buf.ptr())); buf.clear(); } else throw BingoError("Bad label list format"); list_ptr++; } buf.push(0); label_list.push(Element::fromString(buf.ptr())); }
ORAEXT OCIString *oraBingoGetName (OCIExtProcContext *ctx, OCILobLocator *source_locator, short source_indicator, short *return_indicator) { OCIString *result = NULL; ORABLOCK_BEGIN { OracleEnv env(ctx, logger); if (source_indicator == OCI_IND_NULL) throw BingoError("null source given"); QS_DEF(Array<char>, source); QS_DEF(Array<char>, name); OracleLOB source_lob(env, source_locator); source_lob.readAll(source, false); BufferScanner scanner(source); bingoGetName(scanner, name); if (name.size() < 1) { // This is needed for Oracle 9. Returning NULL drops the extproc. OCIStringAssignText(env.envhp(), env.errhp(), (text *)"nil", 3, &result); *return_indicator = OCI_IND_NULL; } else { name.push(0); OCIStringAssignText(env.envhp(), env.errhp(), (text *)name.ptr(), strlen(name.ptr()), &result); *return_indicator = OCI_IND_NOTNULL; } } ORABLOCK_END return result; }
static void _mangoIndexStart (OracleEnv &env, MangoFetchContext &context, const char *oper, const Array<char> &query_buf, OCINumber *p_strt, OCINumber *p_stop, int flags, const char *params) { MangoShadowFetch &shadow_fetch = context.shadow_fetch.ref(); MangoFastIndex &fast_index = context.fast_index.ref(); if (strcasecmp(oper, "SUB") == 0) { if (context.substructure.parse(params)) { context.substructure.loadQuery(query_buf); int right = bingoGetExactRightPart(env, p_strt, p_stop, flags); if (right == 1) { fast_index.prepareSubstructure(env); context.fetch_engine = &fast_index; } else // right == 0 { shadow_fetch.prepareNonSubstructure(env); context.fetch_engine = &shadow_fetch; } } else if (context.tautomer.parseSub(params)) { context.tautomer.loadQuery(query_buf); int right = bingoGetExactRightPart(env, p_strt, p_stop, flags); if (right == 1) { fast_index.prepareTautomerSubstructure(env); context.fetch_engine = &fast_index; } else // right == 0 { shadow_fetch.prepareNonTautomerSubstructure(env); context.fetch_engine = &shadow_fetch; } } else throw BingoError("can't parse parameters: '%s'", params); } else if (strcasecmp(oper, "SMARTS") == 0) { context.substructure.loadSMARTS(query_buf); int right = bingoGetExactRightPart(env, p_strt, p_stop, flags); if (right == 1) { fast_index.prepareSubstructure(env); context.fetch_engine = &fast_index; } else // right == 0 { shadow_fetch.prepareNonSubstructure(env); context.fetch_engine = &shadow_fetch; } } else if (strcasecmp(oper, "EXACT") == 0) { if (context.tautomer.parseExact(params)) { context.tautomer.loadQuery(query_buf); int right = bingoGetExactRightPart(env, p_strt, p_stop, flags); shadow_fetch.prepareTautomer(env, right); context.fetch_engine = &shadow_fetch; } else if (context.exact.parse(params)) { context.exact.loadQuery(query_buf); int right = bingoGetExactRightPart(env, p_strt, p_stop, flags); shadow_fetch.prepareExact(env, right); context.fetch_engine = &shadow_fetch; } else throw BingoError("can't parse parameters: '%s'", params); } else if (strcasecmp(oper, "SIM") == 0) { context.similarity.setMetrics(params); context.similarity.loadQuery(query_buf); float bottom = -0.1f; float top = 1.1f; if (p_strt == 0 && p_stop == 0) throw BingoError("no bounds for similarity search"); if (p_strt != 0) bottom = OracleUtil::numberToFloat(env, p_strt); if (p_stop != 0) top = OracleUtil::numberToFloat(env, p_stop); if (flags & 64) throw BingoError("exact match not allowed"); context.similarity.include_bottom = ((flags & 16) != 0); context.similarity.include_top = ((flags & 32) != 0); context.similarity.bottom = bottom; context.similarity.top = top; fast_index.prepareSimilarity(env); context.fetch_engine = &fast_index; } else if (strcasecmp(oper, "GROSS") == 0) { int right = bingoGetExactRightPart(env, p_strt, p_stop, flags); MangoGross &instance = context.gross; instance.parseQuery(query_buf); shadow_fetch.prepareGross(env, right); context.fetch_engine = &shadow_fetch; } else if (strcasecmp(oper, "MASS") == 0) { float bottom = 0; float top = 1e10; if (p_strt == 0 && p_stop == 0) throw BingoError("no bounds for molecular mass search"); if (p_strt != 0) bottom = OracleUtil::numberToFloat(env, p_strt); if (p_stop != 0) top = OracleUtil::numberToFloat(env, p_stop); context.mass.bottom = bottom; context.mass.top = top; shadow_fetch.prepareMass(env); context.fetch_engine = &shadow_fetch; } else throw BingoError("unknown operator: %s", oper); }