Merge pull request #769 from virgosgod-maker/fix/issue-762

This commit is contained in:
Syngnat
2026-07-28 19:31:01 +08:00
2 changed files with 38 additions and 1 deletions

View File

@@ -4564,6 +4564,32 @@ describe('QueryEditor external SQL save', () => {
expect(messageApi.success).toHaveBeenCalledWith('已还原到美化前 SQL');
});
it('formats OceanBase Oracle SQL with parameter placeholders', async () => {
let renderer!: ReactTestRenderer;
storeState.connections[0].config.type = 'oceanbase';
(storeState.connections[0].config as any).oceanBaseProtocol = 'oracle';
const oracleSql = 'select * from users where id = #{id,jdbcType=NUMBER} and tenant = ${tenant} and status = :status and code = ?';
await act(async () => {
renderer = create(<QueryEditor tab={createTab({ query: oracleSql, dbName: 'main' })} />);
});
const formatButton = findButton(renderer, '美化');
await act(async () => {
await formatButton.props.onClick();
});
expect(messageApi.error).not.toHaveBeenCalled();
expect(editorState.editor.executeEdits).toHaveBeenCalledWith(
'gonavi-format-sql',
expect.arrayContaining([
expect.objectContaining({
text: expect.stringMatching(/#\{id,jdbcType=NUMBER\}[\s\S]*\$\{tenant\}[\s\S]*:status[\s\S]*\?/),
}),
]),
);
});
it('formats postgres window-function SQL with cast syntax through Monaco edits', async () => {
let renderer!: ReactTestRenderer;
storeState.connections[0].config.type = 'postgres';

View File

@@ -221,6 +221,13 @@ const QUERY_EDITOR_MAC_FIND_WITH_SELECTION_GUARD_ACTION_ID = 'gonavi.suppressMac
const QUERY_EDITOR_AI_INLINE_DEBOUNCE_MS = 220;
const QUERY_EDITOR_AI_INLINE_CONTEXT_KEY = 'gonaviAiInlineSuggestionVisible';
const QUERY_EDITOR_IME_FALLBACK_DELAY_MS = 80;
const QUERY_EDITOR_FORMAT_PARAM_TYPES = {
positional: true,
custom: [
{ regex: String.raw`#\{[^{}]+\}` },
{ regex: String.raw`\$\{[^{}]+\}` },
],
};
const EMPTY_QUERY_EDITOR_SQL_LOGS: SqlLog[] = [];
const isOceanBaseOracleConnection = (config: any): boolean => {
@@ -6182,7 +6189,11 @@ const QueryEditor: React.FC<{ tab: TabData; isActive?: boolean }> = ({ tab, isAc
const formatSelection = !!selection && !!selectedRaw.trim();
const fullQuery = getCurrentQuery();
const sourceSql = formatSelection ? selectedRaw : fullQuery;
const formatted = format(sourceSql, { language: formatterLanguage, keywordCase: sqlFormatOptions.keywordCase });
const formatted = format(sourceSql, {
language: formatterLanguage,
keywordCase: sqlFormatOptions.keywordCase,
paramTypes: QUERY_EDITOR_FORMAT_PARAM_TYPES,
});
if (sourceSql === formatted) {
return;
}