MCPcopy Create free account
hub / github.com/apache/cloudberry / dbms_sql_parse

Function dbms_sql_parse

gpcontrib/orafce/dbms_sql.c:407–495  ·  view source on GitHub ↗

* PROCEDURE dbms_sql.parse(c int, stmt varchar) */

Source from the content-addressed store, hash-verified

405 * PROCEDURE dbms_sql.parse(c int, stmt varchar)
406 */
407Datum
408dbms_sql_parse(PG_FUNCTION_ARGS)
409{
410 char *query,
411 *ptr;
412 char *start;
413 size_t len;
414 orafceTokenType typ;
415 StringInfoData sinfo;
416 CursorData *c;
417 MemoryContext oldcxt;
418
419 c = get_cursor(fcinfo, true);
420
421 if (PG_ARGISNULL(1))
422 ereport(ERROR,
423 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
424 errmsg("parsed query string is NULL")));
425
426 if (c->parsed_query)
427 {
428 int cid = c->cid;
429
430 close_cursor(c);
431 open_cursor(c, cid);
432 }
433
434 query = text_to_cstring(PG_GETARG_TEXT_P(1));
435 ptr = query;
436
437 initStringInfo(&sinfo);
438
439 while (ptr)
440 {
441 char *startsep;
442 char *next_ptr;
443 size_t seplen;
444
445 next_ptr = next_token(ptr, &start, &len, &typ, &startsep, &seplen);
446 if (next_ptr)
447 {
448 if (typ == TOKEN_DOLAR_STR)
449 {
450 appendStringInfo(&sinfo, "%.*s", (int) seplen, startsep);
451 appendStringInfo(&sinfo, "%.*s", (int) len, start);
452 appendStringInfo(&sinfo, "%.*s", (int) seplen, startsep);
453 }
454 else if (typ == TOKEN_BIND_VAR)
455 {
456 char *name = downcase_identifier(start, (int) len, false, true);
457 VariableData *var = get_var(c, name, (int) (ptr - query), true);
458
459 appendStringInfo(&sinfo, "$%d", var->varno);
460
461 pfree(name);
462 }
463 else if (typ == TOKEN_EXT_STR)
464 {

Callers

nothing calls this directly

Calls 14

get_cursorFunction · 0.85
open_cursorFunction · 0.85
text_to_cstringFunction · 0.85
initStringInfoFunction · 0.85
appendStringInfoFunction · 0.85
downcase_identifierFunction · 0.85
get_varFunction · 0.85
MemoryContextSwitchToFunction · 0.85
close_cursorFunction · 0.70
next_tokenFunction · 0.70
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected