* PROCEDURE dbms_sql.parse(c int, stmt varchar) */
| 405 | * PROCEDURE dbms_sql.parse(c int, stmt varchar) |
| 406 | */ |
| 407 | Datum |
| 408 | dbms_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 | { |
nothing calls this directly
no test coverage detected