mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-07-11 23:42:22 +08:00
Compare commits
2 Commits
fix/query-
...
fix/oceanb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ba3216fa8 | ||
|
|
fca3f0cffb |
@@ -24,14 +24,6 @@ const sameEditorPosition = (left: any, right: any): boolean => (
|
|||||||
&& Number(left?.column) === Number(right?.column)
|
&& Number(left?.column) === Number(right?.column)
|
||||||
);
|
);
|
||||||
|
|
||||||
const isSelectionEmpty = (selection: any): boolean => (
|
|
||||||
!selection
|
|
||||||
|| (
|
|
||||||
Number(selection.startLineNumber) === Number(selection.endLineNumber)
|
|
||||||
&& Number(selection.startColumn) === Number(selection.endColumn)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const stripSqlIdentifierQuotes = (value: string): string => {
|
const stripSqlIdentifierQuotes = (value: string): string => {
|
||||||
const text = String(value || '').trim();
|
const text = String(value || '').trim();
|
||||||
if (!text) return '';
|
if (!text) return '';
|
||||||
@@ -202,72 +194,6 @@ const patchQueryEditorAiInlineRightArrowFallback = (editor: any, monaco: any) =>
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const installPrintableInputFallback = (editor: any, monaco: any) => {
|
|
||||||
const editorDomNode = editor?.getDomNode?.();
|
|
||||||
if (!editorDomNode || editor.__gonaviPrintableInputFallbackInstalled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const input = editorDomNode.querySelector?.('textarea.inputarea, .inputarea textarea, textarea') as HTMLTextAreaElement | null;
|
|
||||||
if (!(input instanceof HTMLTextAreaElement)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Object.defineProperty(editor, '__gonaviPrintableInputFallbackInstalled', {
|
|
||||||
value: true,
|
|
||||||
configurable: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const isReadOnly = (): boolean => {
|
|
||||||
try {
|
|
||||||
const optionId = monaco?.editor?.EditorOption?.readOnly;
|
|
||||||
return optionId !== undefined ? editor.getOption?.(optionId) === true : false;
|
|
||||||
} catch {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleBeforeInput = (event: InputEvent) => {
|
|
||||||
const text = String(event.data || '');
|
|
||||||
if (
|
|
||||||
event.defaultPrevented
|
|
||||||
|| event.isComposing
|
|
||||||
|| event.inputType !== 'insertText'
|
|
||||||
|| !text
|
|
||||||
|| text.length > 8
|
|
||||||
|| isReadOnly()
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const selectionBefore = editor.getSelection?.();
|
|
||||||
if (!isSelectionEmpty(selectionBefore)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const beforeValue = String(editor.getValue?.() ?? '');
|
|
||||||
const beforePosition = editor.getPosition?.();
|
|
||||||
|
|
||||||
window.setTimeout(() => {
|
|
||||||
const domNode = editor.getDomNode?.();
|
|
||||||
if (!(domNode instanceof HTMLElement) || !domNode.isConnected || isReadOnly()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (document.activeElement && !domNode.contains(document.activeElement)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const afterValue = String(editor.getValue?.() ?? '');
|
|
||||||
const afterPosition = editor.getPosition?.();
|
|
||||||
if (afterValue !== beforeValue || !sameEditorPosition(beforePosition, afterPosition)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
editor.trigger?.('gonavi-printable-input-fallback', 'type', { text });
|
|
||||||
}, 16);
|
|
||||||
};
|
|
||||||
|
|
||||||
input.addEventListener('beforeinput', handleBeforeInput);
|
|
||||||
editor.onDidDispose?.(() => {
|
|
||||||
input.removeEventListener('beforeinput', handleBeforeInput);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const registerGonaviMonacoThemes: BeforeMount = (monaco) => {
|
export const registerGonaviMonacoThemes: BeforeMount = (monaco) => {
|
||||||
if (transparentThemesRegistered) {
|
if (transparentThemesRegistered) {
|
||||||
return;
|
return;
|
||||||
@@ -365,7 +291,6 @@ const MonacoEditor: React.FC<MonacoEditorProps> = ({
|
|||||||
const handleMount: OnMount = useCallback((editor, monaco) => {
|
const handleMount: OnMount = useCallback((editor, monaco) => {
|
||||||
installOceanBaseOracleNavigationFallback(editor);
|
installOceanBaseOracleNavigationFallback(editor);
|
||||||
patchQueryEditorAiInlineRightArrowFallback(editor, monaco);
|
patchQueryEditorAiInlineRightArrowFallback(editor, monaco);
|
||||||
installPrintableInputFallback(editor, monaco);
|
|
||||||
onMount?.(editor, monaco);
|
onMount?.(editor, monaco);
|
||||||
}, [onMount]);
|
}, [onMount]);
|
||||||
|
|
||||||
|
|||||||
@@ -417,9 +417,16 @@ func buildObjectSequenceMetadataQueries(dbType string, dbName string) []objectMe
|
|||||||
switch dbType {
|
switch dbType {
|
||||||
case "oracle", "dameng":
|
case "oracle", "dameng":
|
||||||
if strings.TrimSpace(dbName) == "" {
|
if strings.TrimSpace(dbName) == "" {
|
||||||
return []objectMetadataQuerySpec{{sql: "SELECT SEQUENCE_NAME AS sequence_name FROM USER_SEQUENCES ORDER BY SEQUENCE_NAME"}}
|
return []objectMetadataQuerySpec{
|
||||||
|
{sql: "SELECT * FROM USER_SEQUENCES ORDER BY SEQUENCE_NAME"},
|
||||||
|
{sql: "SELECT OBJECT_NAME AS sequence_name FROM USER_OBJECTS WHERE OBJECT_TYPE = 'SEQUENCE' ORDER BY OBJECT_NAME"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
owner := strings.ToUpper(safeDbName)
|
||||||
|
return []objectMetadataQuerySpec{
|
||||||
|
{sql: fmt.Sprintf("SELECT * FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '%s' ORDER BY SEQUENCE_NAME", owner)},
|
||||||
|
{sql: fmt.Sprintf("SELECT OWNER AS schema_name, OBJECT_NAME AS sequence_name FROM ALL_OBJECTS WHERE OWNER = '%s' AND OBJECT_TYPE = 'SEQUENCE' ORDER BY OBJECT_NAME", owner)},
|
||||||
}
|
}
|
||||||
return []objectMetadataQuerySpec{{sql: fmt.Sprintf("SELECT SEQUENCE_OWNER AS schema_name, SEQUENCE_NAME AS sequence_name FROM ALL_SEQUENCES WHERE SEQUENCE_OWNER = '%s' ORDER BY SEQUENCE_NAME", strings.ToUpper(safeDbName))}}
|
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
39
internal/app/methods_db_objects_sequence_test.go
Normal file
39
internal/app/methods_db_objects_sequence_test.go
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBuildObjectSequenceMetadataQueriesOracleUsesWildcardAndObjectFallback(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
specs := buildObjectSequenceMetadataQueries("oracle", "sbdev")
|
||||||
|
if len(specs) != 2 {
|
||||||
|
t.Fatalf("expected 2 Oracle sequence metadata queries, got %d", len(specs))
|
||||||
|
}
|
||||||
|
if !strings.Contains(specs[0].sql, "SELECT * FROM ALL_SEQUENCES") {
|
||||||
|
t.Fatalf("expected ALL_SEQUENCES wildcard query, got %q", specs[0].sql)
|
||||||
|
}
|
||||||
|
if strings.Contains(specs[0].sql, "LAST_NUMBER") || strings.Contains(specs[0].sql, "ORDER_FLAG") {
|
||||||
|
t.Fatalf("query should not enumerate optional sequence columns: %q", specs[0].sql)
|
||||||
|
}
|
||||||
|
if !strings.Contains(specs[1].sql, "ALL_OBJECTS") || !strings.Contains(specs[1].sql, "OBJECT_TYPE = 'SEQUENCE'") {
|
||||||
|
t.Fatalf("expected ALL_OBJECTS fallback query, got %q", specs[1].sql)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestBuildObjectSequenceMetadataQueriesOracleUserFallbacks(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
specs := buildObjectSequenceMetadataQueries("oracle", "")
|
||||||
|
if len(specs) != 2 {
|
||||||
|
t.Fatalf("expected 2 Oracle user sequence metadata queries, got %d", len(specs))
|
||||||
|
}
|
||||||
|
if specs[0].sql != "SELECT * FROM USER_SEQUENCES ORDER BY SEQUENCE_NAME" {
|
||||||
|
t.Fatalf("unexpected USER_SEQUENCES query: %q", specs[0].sql)
|
||||||
|
}
|
||||||
|
if !strings.Contains(specs[1].sql, "USER_OBJECTS") || !strings.Contains(specs[1].sql, "OBJECT_TYPE = 'SEQUENCE'") {
|
||||||
|
t.Fatalf("expected USER_OBJECTS fallback query, got %q", specs[1].sql)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user