psql: add %o prompt escape for Oracle compatibility mode#1383
psql: add %o prompt escape for Oracle compatibility mode#1383123123213weqw wants to merge 2 commits into
Conversation
Add a new psql prompt escape %o that expands to "[ORA]" when the session is in Oracle compatibility mode (ivorysql.compatible_mode = 'oracle'), and to empty otherwise, so it is easy to tell which mode psql is in. Mark ivorysql.compatible_mode as GUC_REPORT so the server pushes its value to the client, letting the prompt track in-session SET changes in real time. The escape is added to both src/bin/psql/prompt.c and ora_prompt.c. It is off by default; users opt in via \set PROMPT1 '%o%/%R%x%# '. Issue: IvorySQL#1354 Signed-off-by: wangyue789 <1939457790@qq.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (5)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a new ChangesOracle mode prompt escape
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant psql
participant get_prompt
participant PQparameterStatus
participant PromptBuffer
psql->>get_prompt: render prompt string
get_prompt->>get_prompt: encounter %o
get_prompt->>PQparameterStatus: read ivorysql.database_mode
PQparameterStatus-->>get_prompt: return mode value
get_prompt->>PromptBuffer: append "[ORA]" when value is "oracle"
get_prompt-->>psql: return final prompt
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/bin/psql/prompt.c`:
- Around line 281-289: The %o prompt marker in psql relies on
PQparameterStatus("ivorysql.compatible_mode"), but that GUC is not being
reported because it lacks the GUC_REPORT flag. Update the ivy_guc.c entry for
ivorysql.compatible_mode so it includes GUC_REPORT alongside its existing flags,
using the compatible_mode GUC definition as the target symbol to locate the
change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c0656f13-1b19-4d64-b1f8-cc783dbad89f
⛔ Files ignored due to path filters (1)
src/backend/utils/misc/guc_parameters.datis excluded by!**/*.dat
📒 Files selected for processing (2)
src/bin/psql/ora_prompt.csrc/bin/psql/prompt.c
| case 'o': | ||
| if (pset.db) | ||
| { | ||
| const char *cm = PQparameterStatus(pset.db, "ivorysql.compatible_mode"); | ||
|
|
||
| if (cm && strcmp(cm, "oracle") == 0) | ||
| strlcpy(buf, "[ORA]", sizeof(buf)); | ||
| } | ||
| break; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Confirm which GUC table definition is actually compiled and whether GUC_REPORT is present.
rg -n "ivorysql.compatible_mode" -A5 src/backend/utils/misc/ivy_guc.c
rg -n "gen_guc_tables|guc_parameters.dat" -n src/backend/utils/misc/Makefile src/backend/utils/misc/meson.build 2>/dev/nullRepository: IvorySQL/IvorySQL
Length of output: 670
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== build wiring =="
rg -n "guc_parameters\.dat|gen_guc_tables|ivy_guc\.c|guc" src/backend/utils/misc/Makefile src/backend/utils/misc/meson.build src/backend/utils/misc -g '!*.o' -g '!*.a' -g '!*.so'
echo
echo "== dat definition =="
rg -n "ivorysql\.compatible_mode" -A6 -B2 src/backend/utils/misc/guc_parameters.dat
echo
echo "== generated C definition context =="
rg -n "ivorysql\.compatible_mode" -A8 -B2 src/backend/utils/misc/ivy_guc.cRepository: IvorySQL/IvorySQL
Length of output: 24446
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== GUC_REPORT handling =="
rg -n "GUC_REPORT|ParameterStatus|guc_report_list|Report" src/backend/utils/misc/guc.c src/backend/utils/misc/guc_tables.c src/backend/utils/misc/ps_status.c src/include/utils/guc.h
echo
echo "== report-path context =="
sed -n '2440,2510p' src/backend/utils/misc/guc.c
echo
echo "== table inclusion context =="
sed -n '100,140p' src/backend/utils/misc/guc_tables.c
sed -n '796,826p' src/backend/utils/misc/guc_tables.cRepository: IvorySQL/IvorySQL
Length of output: 7190
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== ivy_guc.c macro blocks around compatible_mode =="
sed -n '360,420p' src/backend/utils/misc/ivy_guc.c
echo
echo "== ivy_guc.c macro guards =="
rg -n "IVY_GUC_VAR_DEFINE|IVY_GUC_FUNC_DECLARE|IVY_GUC_FUNC_DEFINE" -A3 -B3 src/backend/utils/misc/ivy_guc.c
echo
echo "== any other compatible_mode definitions =="
rg -n "ivorysql\.compatible_mode|compatible_mode" src/backend/utils/misc src/include -g '!*.o' -g '!*.a' -g '!*.so'Repository: IvorySQL/IvorySQL
Length of output: 3501
Add GUC_REPORT to ivorysql.compatible_mode. guc.c only sends ParameterStatus for GUCs with that flag, and guc_tables.c includes src/backend/utils/misc/ivy_guc.c at build time, where this entry currently lacks it; %o will stay empty otherwise.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/bin/psql/prompt.c` around lines 281 - 289, The %o prompt marker in psql
relies on PQparameterStatus("ivorysql.compatible_mode"), but that GUC is not
being reported because it lacks the GUC_REPORT flag. Update the ivy_guc.c entry
for ivorysql.compatible_mode so it includes GUC_REPORT alongside its existing
flags, using the compatible_mode GUC definition as the target symbol to locate
the change.
|
Welcome to contribute to the IvorySQL community! The regression checks has started and we will review the code soon. |
|
…ases Address review feedback from @bigplaice on PR IvorySQL#1383. 1. Document the %o prompt escape in the Prompting section of psql-ref.sgml, alongside the other escapes, and update the default-prompts note. 2. Show [ORA] by default for Oracle-mode databases. The %o escape previously read ivorysql.compatible_mode, but that GUC defaults to pg even in an initdb -m oracle database, so the indicator never appeared without manual setup. Key %o off ivorysql.database_mode (the db_mode == DB_ORACLE signal) instead, add GUC_REPORT to ivorysql.database_mode so PQparameterStatus() returns it, and include %o in the default PROMPT1/PROMPT2. Verified: an initdb -m oracle cluster shows [ORA]postgres=# by default; an initdb -m pg cluster shows postgres=# (no [ORA]).
…ases Address review feedback from @bigplaice on PR IvorySQL#1383. 1. Document the %o prompt escape in the Prompting section of psql-ref.sgml, alongside the other escapes, and update the default-prompts note. 2. Show [ORA] by default for Oracle-mode databases. The %o escape previously read ivorysql.compatible_mode, but that GUC defaults to pg even in an initdb -m oracle database, so the indicator never appeared without manual setup. Key %o off ivorysql.database_mode (the db_mode == DB_ORACLE signal) instead, add GUC_REPORT to ivorysql.database_mode so PQparameterStatus() returns it, and include %o in the default PROMPT1/PROMPT2. Verified: an initdb -m oracle cluster shows [ORA]postgres=# by default; an initdb -m pg cluster shows postgres=# (no [ORA]).
|
Hi @bigplaice, thanks for the review. Both points are addressed in the latest push. 1. Documentation Added 2.
The reason for switching to Behavior of
Verified end-to-end by building and connecting with the new |
7f44f5c to
d063058
Compare
When database is initialized with -m oracle, the ivory_ora extension is loaded automaticlly and thus user can switch compatible_mode between pg and oracle. While with -m pg, the database will be initialized without ivorysql_ora extension, and user can not switch to oracle mode. The database_mode==oracle (in code: db_mode == DB_ORACLE) means that it is possible to switch to oracle mode(in code: compatible_db == ORA_PARSER). User can switch to oracle mode either by connecting 1521 port, or running "set ivorysql.compatibel_mode=oracle;". This's why I suggest to use compatible_mode instead of database_mode. BTW, if you are using AI, please refer to https://github.com/IvorySQL/IvorySQL/blob/master/coding-assistants_CN.md |
Add a new psql prompt escape
%othat shows whether the current session is in Oracle compatibility mode, so it is easy to tell which mode psql is running in.Changes
ivorysql.compatible_modeasGUC_REPORTso the server pushes its value to the client, letting the prompt track in-sessionSETchanges in real time.%oescape insrc/bin/psql/prompt.candsrc/bin/psql/ora_prompt.c: it expands to[ORA]whenivorysql.compatible_mode = 'oracle', and to empty otherwise.Behavior
[ORA]ivorysql=#in Oracle mode andivorysql=#in PostgreSQL mode, updating live as youSET ivorysql.compatible_mode.Notes
PQparameterStatus("ivorysql.compatible_mode"), so it requires theGUC_REPORTchange above (server recompile + restart) and safely degrades to empty against an older server that does not report it.Verified by building and running locally: in-session
SET ivorysql.compatible_mode = oraclemakes the%oprompt show[ORA]immediately, andSET ... = pgclears it.Closes #1354.
Summary by CodeRabbit
psqlprompt escape (%o) that inserts an[ORA]marker when connected to an IvorySQL server in Oracle database mode; otherwise it outputs nothing.PROMPT1andPROMPT2formats to include%oautomatically.psqlprompt substitution reference to document%obehavior and reflect the updated default prompt strings.