| 453 | } |
| 454 | |
| 455 | public DescribeResult describe(char type, String portalOrStatement) { |
| 456 | if (LOGGER.isDebugEnabled()) { |
| 457 | LOGGER.debug("method=describe type={} portalOrStatement={}", type, portalOrStatement); |
| 458 | } |
| 459 | switch (type) { |
| 460 | case 'P': |
| 461 | Portal portal = getSafePortal(portalOrStatement); |
| 462 | var analyzedStmt = portal.analyzedStatement(); |
| 463 | return new DescribeResult( |
| 464 | portal.preparedStmt().parameterTypes(), |
| 465 | analyzedStmt.outputs(), |
| 466 | analyzedStmt.outputNames(), |
| 467 | resolveTableFromSelect(analyzedStmt) |
| 468 | ); |
| 469 | case 'S': |
| 470 | /* |
| 471 | * describe might be called without prior bind call. |
| 472 | * |
| 473 | * If the client uses server-side prepared statements this is usually the case. |
| 474 | * |
| 475 | * E.g. the statement is first prepared: |
| 476 | * |
| 477 | * parse stmtName=S_1 query=insert into t (x) values ($1) paramTypes=[integer] |
| 478 | * describe type=S portalOrStatement=S_1 |
| 479 | * sync |
| 480 | * |
| 481 | * and then used with different bind calls: |
| 482 | * |
| 483 | * bind portalName= statementName=S_1 params=[0] |
| 484 | * describe type=P portalOrStatement= |
| 485 | * execute |
| 486 | * |
| 487 | * bind portalName= statementName=S_1 params=[1] |
| 488 | * describe type=P portalOrStatement= |
| 489 | * execute |
| 490 | */ |
| 491 | PreparedStmt preparedStmt = preparedStatements.get(portalOrStatement); |
| 492 | AnalyzedStatement analyzedStatement = preparedStmt.analyzedStatement(); |
| 493 | return new DescribeResult( |
| 494 | preparedStmt.parameterTypes(), |
| 495 | analyzedStatement.outputs(), |
| 496 | analyzedStatement.outputNames(), |
| 497 | resolveTableFromSelect(analyzedStatement) |
| 498 | ); |
| 499 | default: |
| 500 | throw new AssertionError("Unsupported type: " + type); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | @Nullable |
| 505 | private RelationInfo resolveTableFromSelect(AnalyzedStatement stmt) { |