execsql2 2.38.0__py3-none-any.whl → 2.40.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- execsql/cli/lint.py +40 -8
- execsql/cli/run.py +123 -56
- execsql/data/execsql.conf.template +5 -2
- execsql/db/base.py +9 -0
- execsql/db/dsn.py +2 -3
- execsql/db/firebird.py +31 -22
- execsql/db/mysql.py +14 -20
- execsql/db/oracle.py +6 -4
- execsql/db/postgres.py +13 -18
- execsql/exceptions.py +5 -0
- execsql/gui/__init__.py +13 -10
- execsql/gui/base.py +131 -8
- execsql/gui/console.py +77 -30
- execsql/gui/desktop.py +290 -120
- execsql/gui/tui.py +384 -132
- execsql/importers/base.py +6 -12
- execsql/importers/csv.py +3 -5
- execsql/metacommands/control.py +40 -27
- execsql/metacommands/data.py +11 -9
- execsql/metacommands/io_fileops.py +1 -1
- execsql/metacommands/io_write.py +0 -9
- execsql/metacommands/prompt.py +94 -42
- execsql/metacommands/script_ext.py +6 -2
- execsql/metacommands/system.py +0 -2
- execsql/parser.py +118 -8
- execsql/script/engine.py +1 -1
- execsql/script/executor.py +31 -3
- execsql/script/parser.py +31 -0
- execsql/utils/auth.py +11 -6
- execsql/utils/gui.py +162 -53
- {execsql2-2.38.0.dist-info → execsql2-2.40.0.dist-info}/METADATA +2 -2
- {execsql2-2.38.0.dist-info → execsql2-2.40.0.dist-info}/RECORD +49 -49
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/README.md +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/config_settings.sqlite +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/example_config_prompt.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/make_config_db.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/md_compare.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/md_glossary.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/md_upsert.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/pg_compare.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/pg_glossary.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/script_template.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/ss_compare.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/ss_glossary.sql +0 -0
- {execsql2-2.38.0.data → execsql2-2.40.0.data}/data/execsql2_extras/ss_upsert.sql +0 -0
- {execsql2-2.38.0.dist-info → execsql2-2.40.0.dist-info}/WHEEL +0 -0
- {execsql2-2.38.0.dist-info → execsql2-2.40.0.dist-info}/entry_points.txt +0 -0
- {execsql2-2.38.0.dist-info → execsql2-2.40.0.dist-info}/licenses/LICENSE.txt +0 -0
- {execsql2-2.38.0.dist-info → execsql2-2.40.0.dist-info}/licenses/NOTICE +0 -0
execsql/cli/lint.py
CHANGED
|
@@ -52,7 +52,7 @@ import functools
|
|
|
52
52
|
import json
|
|
53
53
|
import re
|
|
54
54
|
from collections import Counter
|
|
55
|
-
from collections.abc import Iterable
|
|
55
|
+
from collections.abc import Callable, Iterable
|
|
56
56
|
from pathlib import Path
|
|
57
57
|
from typing import TYPE_CHECKING, NamedTuple
|
|
58
58
|
|
|
@@ -730,6 +730,21 @@ def _placeholder_forms(text: str) -> list[str]:
|
|
|
730
730
|
return [_with_placeholders(text, value) for value in _PLACEHOLDERS]
|
|
731
731
|
|
|
732
732
|
|
|
733
|
+
def _condition_placeholder(text: str, value: str) -> tuple[str, Callable[[int], tuple[str, int]]]:
|
|
734
|
+
"""Replace variables and retain a map from parsed offsets to original text."""
|
|
735
|
+
pieces: list[str] = []
|
|
736
|
+
offsets: list[int] = []
|
|
737
|
+
start = 0
|
|
738
|
+
for match in _RX_ANY_VAR.finditer(text):
|
|
739
|
+
pieces.extend((text[start : match.start()], value))
|
|
740
|
+
offsets.extend(range(start, match.start()))
|
|
741
|
+
offsets.extend([match.start()] * len(value))
|
|
742
|
+
start = match.end()
|
|
743
|
+
pieces.append(text[start:])
|
|
744
|
+
offsets.extend(range(start, len(text) + 1)) # includes the end-of-input position
|
|
745
|
+
return "".join(pieces), lambda position: (text, offsets[position])
|
|
746
|
+
|
|
747
|
+
|
|
733
748
|
# Named groups that capture a condition in a metacommand's pattern: ASSERT,
|
|
734
749
|
# WAIT_UNTIL, and the WHILE / UNTIL of ON ... EXECUTE SCRIPT.
|
|
735
750
|
_CONDITION_GROUPS = ("condtest", "condition", "loopcond")
|
|
@@ -777,15 +792,32 @@ def _check_condition(condition: str, source: str, line_no: int, issues: list[_Is
|
|
|
777
792
|
from execsql.exceptions import CondParserError
|
|
778
793
|
from execsql.parser import CondParser
|
|
779
794
|
|
|
780
|
-
forms =
|
|
781
|
-
|
|
795
|
+
forms = (
|
|
796
|
+
[_condition_placeholder(condition, value) for value in _PLACEHOLDERS]
|
|
797
|
+
if _RX_ANY_VAR.search(condition)
|
|
798
|
+
else [(condition, None)]
|
|
799
|
+
)
|
|
800
|
+
message = ""
|
|
801
|
+
furthest = -1
|
|
802
|
+
for form, original in forms:
|
|
803
|
+
parser = CondParser(form, _conditional_table(), diagnostic_source=original)
|
|
782
804
|
try:
|
|
783
|
-
|
|
784
|
-
except
|
|
785
|
-
|
|
786
|
-
|
|
805
|
+
parser.parse()
|
|
806
|
+
except CondParserError as exc:
|
|
807
|
+
problem = str(exc)
|
|
808
|
+
except RecursionError:
|
|
809
|
+
problem = "Condition nests too deeply to parse."
|
|
810
|
+
else:
|
|
811
|
+
return
|
|
812
|
+
position = parser.cond_expr.currpos
|
|
813
|
+
if original is not None:
|
|
814
|
+
_, position = original(position)
|
|
815
|
+
# A boolean placeholder can reach a real error after the variable;
|
|
816
|
+
# an identifier placeholder might fail at the variable itself.
|
|
817
|
+
if position > furthest:
|
|
818
|
+
furthest, message = position, problem
|
|
787
819
|
issues.append(
|
|
788
|
-
_issue("P004", source, line_no,
|
|
820
|
+
_issue("P004", source, line_no, message),
|
|
789
821
|
)
|
|
790
822
|
|
|
791
823
|
|
execsql/cli/run.py
CHANGED
|
@@ -14,6 +14,7 @@ import os
|
|
|
14
14
|
import platform
|
|
15
15
|
import sys
|
|
16
16
|
import traceback
|
|
17
|
+
from collections.abc import Callable
|
|
17
18
|
from pathlib import Path
|
|
18
19
|
from typing import TYPE_CHECKING, Any
|
|
19
20
|
|
|
@@ -807,54 +808,54 @@ def _run(
|
|
|
807
808
|
if conf.gui_level > 2:
|
|
808
809
|
gui_console_on()
|
|
809
810
|
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
from execsql.utils.errors import fatal_error
|
|
811
|
+
def initialize() -> None:
|
|
812
|
+
"""Connect and initialize script state on the execution thread."""
|
|
813
|
+
if conf.server is None and conf.db is None and conf.db_file is None:
|
|
814
|
+
if conf.gui_level > 1:
|
|
815
|
+
gui_connect("initial", f"Select the database to use with {script_name or '<inline>'}.")
|
|
816
|
+
db = _state.dbs.current()
|
|
817
|
+
else:
|
|
818
|
+
from execsql.utils.errors import fatal_error
|
|
819
819
|
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
820
|
+
fatal_error(
|
|
821
|
+
"Database not specified in configuration files or command-line arguments, and prompt not requested.",
|
|
822
|
+
)
|
|
823
|
+
else:
|
|
824
|
+
db = _connect_initial_db(conf)
|
|
825
|
+
_state.dbs.add("initial", db)
|
|
826
826
|
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
827
|
+
_state.exec_log.log_db_connect(db)
|
|
828
|
+
if manifest is not None:
|
|
829
|
+
manifest.set_database(db)
|
|
830
|
+
_state.subvars.add_substitution("$CURRENT_DBMS", db.type.dbms_id)
|
|
831
|
+
_state.subvars.add_substitution("$CURRENT_DATABASE", db.name())
|
|
832
|
+
_state.subvars.add_substitution("$DB_SERVER", db.server_name)
|
|
833
|
+
_state.subvars.add_substitution("$SYSTEM_CMD_EXIT_STATUS", "0")
|
|
834
834
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
# ------------------------------------------------------------------
|
|
838
|
-
atexit.register(_state.dbs.closeall)
|
|
839
|
-
_state.dbs.do_rollback = True
|
|
835
|
+
atexit.register(_state.dbs.closeall)
|
|
836
|
+
_state.dbs.do_rollback = True
|
|
840
837
|
|
|
841
|
-
|
|
842
|
-
|
|
838
|
+
if profile:
|
|
839
|
+
_state.profile_data = []
|
|
843
840
|
|
|
844
|
-
|
|
845
|
-
|
|
841
|
+
if debug:
|
|
842
|
+
_state.step_mode = True
|
|
846
843
|
|
|
847
|
-
|
|
848
|
-
|
|
844
|
+
if no_system_cmd:
|
|
845
|
+
conf.allow_system_cmd = False
|
|
849
846
|
|
|
850
|
-
|
|
851
|
-
|
|
847
|
+
if no_rm_file:
|
|
848
|
+
conf.allow_rm_file = False
|
|
852
849
|
|
|
853
|
-
|
|
854
|
-
|
|
850
|
+
if no_serve:
|
|
851
|
+
conf.allow_serve = False
|
|
855
852
|
|
|
856
|
-
if _ast_tree is not None:
|
|
857
|
-
_execute_script_ast(_ast_tree, conf, profile=profile, profile_limit=profile_limit)
|
|
853
|
+
if _ast_tree is not None and _uses_textual_console(conf):
|
|
854
|
+
_execute_script_ast(_ast_tree, conf, profile=profile, profile_limit=profile_limit, initialize=initialize)
|
|
855
|
+
else:
|
|
856
|
+
initialize()
|
|
857
|
+
if _ast_tree is not None:
|
|
858
|
+
_execute_script_ast(_ast_tree, conf, profile=profile, profile_limit=profile_limit)
|
|
858
859
|
if manifest is not None:
|
|
859
860
|
manifest.finish(0)
|
|
860
861
|
|
|
@@ -881,29 +882,37 @@ def _end_run_on_sigterm() -> None:
|
|
|
881
882
|
signal.signal(signal.SIGTERM, terminate)
|
|
882
883
|
|
|
883
884
|
|
|
885
|
+
def _uses_textual_console(conf: ConfigData) -> bool:
|
|
886
|
+
import execsql.utils.gui as _gui
|
|
887
|
+
|
|
888
|
+
if conf.gui_level > 2:
|
|
889
|
+
try:
|
|
890
|
+
from execsql.gui.tui import TextualBackend
|
|
891
|
+
|
|
892
|
+
return isinstance(_gui._active_backend, TextualBackend)
|
|
893
|
+
except ImportError:
|
|
894
|
+
pass
|
|
895
|
+
return False
|
|
896
|
+
|
|
897
|
+
|
|
884
898
|
def _execute_script_ast(
|
|
885
899
|
tree: Any,
|
|
886
900
|
conf: ConfigData,
|
|
887
901
|
*,
|
|
888
902
|
profile: bool = False,
|
|
889
903
|
profile_limit: int = 20,
|
|
904
|
+
initialize: Callable[[], None] | None = None,
|
|
890
905
|
) -> None:
|
|
891
|
-
"""Execute a script
|
|
906
|
+
"""Execute a script, optionally initializing its connections on its owning thread."""
|
|
892
907
|
import execsql.state as _state
|
|
893
|
-
import execsql.utils.gui as _gui
|
|
894
908
|
|
|
895
909
|
from execsql.script.executor import execute
|
|
896
910
|
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
if isinstance(_gui._active_backend, TextualBackend):
|
|
903
|
-
_execute_script_textual_console(tree, conf)
|
|
904
|
-
return
|
|
905
|
-
except ImportError:
|
|
906
|
-
pass
|
|
911
|
+
if _uses_textual_console(conf):
|
|
912
|
+
_execute_script_textual_console(tree, conf, initialize=initialize)
|
|
913
|
+
return
|
|
914
|
+
if initialize is not None:
|
|
915
|
+
initialize()
|
|
907
916
|
|
|
908
917
|
try:
|
|
909
918
|
execute(tree)
|
|
@@ -950,20 +959,73 @@ def _execute_script_ast(
|
|
|
950
959
|
_state.exec_log.log_exit_end()
|
|
951
960
|
|
|
952
961
|
|
|
953
|
-
def _execute_script_textual_console(
|
|
954
|
-
|
|
962
|
+
def _execute_script_textual_console(
|
|
963
|
+
tree: Any,
|
|
964
|
+
conf: ConfigData,
|
|
965
|
+
*,
|
|
966
|
+
initialize: Callable[[], None] | None = None,
|
|
967
|
+
) -> None:
|
|
968
|
+
"""Run the script while ConsoleApp runs on main; own connections when initializing."""
|
|
955
969
|
import execsql.state as _state
|
|
956
970
|
import execsql.utils.gui as _gui
|
|
957
971
|
from execsql.gui.tui import ConsoleApp, _ConsoleDialogQueue
|
|
958
972
|
|
|
959
|
-
from execsql.script.executor import execute
|
|
973
|
+
from execsql.script.executor import _CONTROL_FLOW, _roll_back_after_interrupt, execute
|
|
960
974
|
|
|
961
975
|
dialog_queue = _ConsoleDialogQueue()
|
|
962
976
|
_state.gui_manager_queue = dialog_queue
|
|
963
977
|
|
|
964
978
|
ctx = _state.get_context()
|
|
979
|
+
|
|
980
|
+
def run_script() -> None:
|
|
981
|
+
with _state.active_context(ctx):
|
|
982
|
+
try:
|
|
983
|
+
try:
|
|
984
|
+
if initialize is not None:
|
|
985
|
+
try:
|
|
986
|
+
initialize()
|
|
987
|
+
except ConfigError:
|
|
988
|
+
raise
|
|
989
|
+
except Exception as exc:
|
|
990
|
+
from execsql.utils.errors import exit_now
|
|
991
|
+
|
|
992
|
+
error = exc if isinstance(exc, ErrInfo) else ErrInfo("exception", exception_msg=str(exc))
|
|
993
|
+
exit_now(1, error)
|
|
994
|
+
try:
|
|
995
|
+
execute(tree, ctx=ctx)
|
|
996
|
+
except ConfigError:
|
|
997
|
+
raise
|
|
998
|
+
except Exception as exc:
|
|
999
|
+
from execsql.utils.errors import exit_now
|
|
1000
|
+
|
|
1001
|
+
if isinstance(exc, ErrInfo):
|
|
1002
|
+
error = exc
|
|
1003
|
+
else:
|
|
1004
|
+
strace = traceback.extract_tb(exc.__traceback__)[-1:]
|
|
1005
|
+
lno = strace[0][1] if strace else "?"
|
|
1006
|
+
msg = f"{Path(sys.argv[0]).name}: Uncaught exception {type(exc)} ({exc}) on line {lno}"
|
|
1007
|
+
script, slno = current_script_line()
|
|
1008
|
+
if script is not None:
|
|
1009
|
+
msg += f" in script {script}, line {slno}"
|
|
1010
|
+
error = ErrInfo("exception", exception_msg=msg)
|
|
1011
|
+
# Deferred error scripts need the worker's live connections.
|
|
1012
|
+
exit_now(1, error)
|
|
1013
|
+
_flush_output_files()
|
|
1014
|
+
_state.dbs.do_rollback = False
|
|
1015
|
+
finally:
|
|
1016
|
+
if initialize is not None:
|
|
1017
|
+
_state.dbs.closeall()
|
|
1018
|
+
except (*_CONTROL_FLOW, Exception):
|
|
1019
|
+
raise
|
|
1020
|
+
except BaseException:
|
|
1021
|
+
_roll_back_after_interrupt(ctx)
|
|
1022
|
+
if initialize is not None:
|
|
1023
|
+
# Quit can arrive during closeall itself; finish cleanup on its owner.
|
|
1024
|
+
_state.dbs.closeall()
|
|
1025
|
+
raise
|
|
1026
|
+
|
|
965
1027
|
app = ConsoleApp(
|
|
966
|
-
script_runner=
|
|
1028
|
+
script_runner=run_script,
|
|
967
1029
|
dialog_queue=dialog_queue,
|
|
968
1030
|
wait_on_exit=conf.gui_wait_on_exit,
|
|
969
1031
|
)
|
|
@@ -974,9 +1036,15 @@ def _execute_script_textual_console(tree: Any, conf: ConfigData) -> None:
|
|
|
974
1036
|
try:
|
|
975
1037
|
app.run()
|
|
976
1038
|
finally:
|
|
1039
|
+
app.wait_for_script()
|
|
977
1040
|
_state.output.reset()
|
|
978
1041
|
_gui._active_backend._console_app = None
|
|
979
1042
|
|
|
1043
|
+
if app._quit_requested or isinstance(app._script_exception, KeyboardInterrupt):
|
|
1044
|
+
_state.exec_log.log_exit_interrupted()
|
|
1045
|
+
_state.exec_log.log_status_info(f"{_state.cmds_run} commands run")
|
|
1046
|
+
raise SystemExit(130)
|
|
1047
|
+
|
|
980
1048
|
if app._script_exception is not None:
|
|
981
1049
|
exc = app._script_exception
|
|
982
1050
|
if isinstance(exc, SystemExit):
|
|
@@ -1000,7 +1068,6 @@ def _execute_script_textual_console(tree: Any, conf: ConfigData) -> None:
|
|
|
1000
1068
|
exit_now(1, ErrInfo("exception", exception_msg=msg))
|
|
1001
1069
|
|
|
1002
1070
|
_state.dbs.do_rollback = False
|
|
1003
|
-
_flush_output_files()
|
|
1004
1071
|
_state.exec_log.log_status_info(f"{_state.cmds_run} commands run")
|
|
1005
1072
|
_state.exec_log.log_exit_end()
|
|
1006
1073
|
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
#access_username=
|
|
43
43
|
|
|
44
44
|
# Whether to prompt for a password.
|
|
45
|
+
# Server/DSN usernames are retained when prompting is disabled.
|
|
45
46
|
# Values: Yes or No. Default: Yes.
|
|
46
47
|
#password_prompt=Yes
|
|
47
48
|
|
|
@@ -243,11 +244,13 @@
|
|
|
243
244
|
# 3: open a console window immediately
|
|
244
245
|
#gui_level=0
|
|
245
246
|
|
|
246
|
-
# The height (in lines) of the console
|
|
247
|
+
# The height (in text lines) of the native Tkinter console.
|
|
248
|
+
# Textual/console backends use the host terminal dimensions.
|
|
247
249
|
# Value: An integer >= 5. Default: 25.
|
|
248
250
|
#console_height=25
|
|
249
251
|
|
|
250
|
-
# The width (in characters) of the console
|
|
252
|
+
# The width (in characters) of the native Tkinter console.
|
|
253
|
+
# Textual/console backends use the host terminal dimensions.
|
|
251
254
|
# Value: An integer >= 20. Default: 100.
|
|
252
255
|
#console_width=100
|
|
253
256
|
|
execsql/db/base.py
CHANGED
|
@@ -364,6 +364,15 @@ class Database(ABC):
|
|
|
364
364
|
what was just reported as failed.
|
|
365
365
|
"""
|
|
366
366
|
if self.conn and self.autocommit:
|
|
367
|
+
self.commit_now()
|
|
368
|
+
|
|
369
|
+
def commit_now(self) -> None:
|
|
370
|
+
"""Commit even under AUTOCOMMIT OFF, rolling back a failed commit.
|
|
371
|
+
|
|
372
|
+
Used only where a DBMS requires an immediate DDL commit before the
|
|
373
|
+
next statement can use the change. This commits the whole transaction.
|
|
374
|
+
"""
|
|
375
|
+
if self.conn:
|
|
367
376
|
try:
|
|
368
377
|
self.conn.commit()
|
|
369
378
|
except BaseException:
|
execsql/db/dsn.py
CHANGED
|
@@ -100,10 +100,9 @@ class DsnDatabase(Database):
|
|
|
100
100
|
# so that ``;``, ``=`` and other ODBC delimiters in user-
|
|
101
101
|
# supplied credentials cannot inject additional attributes.
|
|
102
102
|
parts = [f"DSN={_odbc_quote(self.db_name)}"]
|
|
103
|
-
if self.
|
|
104
|
-
assert self.user is not None
|
|
105
|
-
assert self.password is not None
|
|
103
|
+
if self.user:
|
|
106
104
|
parts.append(f"UID={_odbc_quote(self.user)}")
|
|
105
|
+
if self.password is not None:
|
|
107
106
|
parts.append(f"PWD={_odbc_quote(self.password)}")
|
|
108
107
|
connstr = ";".join(parts) + ";"
|
|
109
108
|
kwargs = {"autocommit": autocommit} if autocommit else {}
|
execsql/db/firebird.py
CHANGED
|
@@ -8,7 +8,10 @@ via the ``firebird-driver`` package. Corresponds to ``-t f`` on the CLI.
|
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
from contextlib import ExitStack
|
|
12
|
+
from threading import RLock
|
|
11
13
|
from typing import Any
|
|
14
|
+
from uuid import uuid4
|
|
12
15
|
|
|
13
16
|
from execsql.db.base import Database
|
|
14
17
|
from execsql.types import DataType, DT_Decimal
|
|
@@ -27,11 +30,13 @@ import execsql.state as _state
|
|
|
27
30
|
|
|
28
31
|
__all__ = ["FirebirdDatabase"]
|
|
29
32
|
|
|
33
|
+
_CONFIG_LOCK = RLock()
|
|
34
|
+
|
|
30
35
|
|
|
31
36
|
class FirebirdDatabase(Database):
|
|
32
37
|
"""Firebird adapter using the firebird-driver package."""
|
|
33
38
|
|
|
34
|
-
#:
|
|
39
|
+
#: Live Firebird tests are opt-in; no Firebird server runs in CI.
|
|
35
40
|
support_tier = SupportTier.BEST_EFFORT
|
|
36
41
|
support_tier_name = "Firebird"
|
|
37
42
|
|
|
@@ -61,7 +66,7 @@ class FirebirdDatabase(Database):
|
|
|
61
66
|
super().__init__(
|
|
62
67
|
server_name=str(server_name),
|
|
63
68
|
db_name=str(db_name),
|
|
64
|
-
user_name=str(user_name),
|
|
69
|
+
user_name=str(user_name) if user_name is not None else None,
|
|
65
70
|
need_passwd=need_passwd,
|
|
66
71
|
port=port if port else 3050,
|
|
67
72
|
)
|
|
@@ -92,24 +97,27 @@ class FirebirdDatabase(Database):
|
|
|
92
97
|
connect_timeout = 30
|
|
93
98
|
|
|
94
99
|
def db_conn():
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
100
|
+
# firebird-driver takes connection options through named configs,
|
|
101
|
+
# not connect(host=, port=, timeout=). Private configs leave the
|
|
102
|
+
# process-wide defaults and other concurrent connections alone.
|
|
103
|
+
config_name = f"execsql_{uuid4().hex}"
|
|
104
|
+
config = firebird_lib.driver_config
|
|
105
|
+
with _CONFIG_LOCK, ExitStack() as cleanup:
|
|
106
|
+
server = config.register_server(config_name)
|
|
107
|
+
cleanup.callback(config.servers.value.remove, server)
|
|
108
|
+
server.host.value = self.server_name
|
|
109
|
+
server.port.value = str(self.port)
|
|
110
|
+
database = config.register_database(config_name)
|
|
111
|
+
cleanup.callback(config.databases.value.remove, database)
|
|
112
|
+
database.server.value = config_name
|
|
113
|
+
database.database.value = self.db_name
|
|
114
|
+
database.timeout.value = connect_timeout
|
|
115
|
+
credentials = {}
|
|
116
|
+
if self.user:
|
|
117
|
+
credentials["user"] = self.user
|
|
118
|
+
if self.password is not None:
|
|
119
|
+
credentials["password"] = self.password
|
|
120
|
+
return firebird_lib.connect(config_name, charset=self.encoding, **credentials)
|
|
113
121
|
|
|
114
122
|
if self.conn is None:
|
|
115
123
|
try:
|
|
@@ -189,7 +197,8 @@ class FirebirdDatabase(Database):
|
|
|
189
197
|
other_msg=f"Failed test for existence of Firebird table {table_name}",
|
|
190
198
|
) from e
|
|
191
199
|
rows = curs.fetchall()
|
|
192
|
-
self.
|
|
200
|
+
if not self.holding():
|
|
201
|
+
self.commit()
|
|
193
202
|
return len(rows) > 0
|
|
194
203
|
|
|
195
204
|
def column_exists(
|
|
@@ -268,4 +277,4 @@ class FirebirdDatabase(Database):
|
|
|
268
277
|
"""Drop *tablename*, schema-qualified and quoted by the caller."""
|
|
269
278
|
# Firebird will thrown an error if there are foreign keys into the table.
|
|
270
279
|
self.execute(f"DROP TABLE {tablename};")
|
|
271
|
-
self.
|
|
280
|
+
self.commit_now()
|
execsql/db/mysql.py
CHANGED
|
@@ -270,26 +270,20 @@ class MySQLDatabase(Database):
|
|
|
270
270
|
connect_timeout = 30
|
|
271
271
|
|
|
272
272
|
def db_conn():
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
database=self.db_name,
|
|
288
|
-
port=self.port,
|
|
289
|
-
charset=self.encoding,
|
|
290
|
-
local_infile=True,
|
|
291
|
-
connect_timeout=connect_timeout,
|
|
292
|
-
)
|
|
273
|
+
credentials = {}
|
|
274
|
+
if self.user:
|
|
275
|
+
credentials["user"] = self.user
|
|
276
|
+
if self.password is not None:
|
|
277
|
+
credentials["password"] = self.password
|
|
278
|
+
return mysql_lib.connect(
|
|
279
|
+
host=self.server_name,
|
|
280
|
+
database=self.db_name,
|
|
281
|
+
port=self.port,
|
|
282
|
+
charset=self.encoding,
|
|
283
|
+
local_infile=True,
|
|
284
|
+
connect_timeout=connect_timeout,
|
|
285
|
+
**credentials,
|
|
286
|
+
)
|
|
293
287
|
|
|
294
288
|
if self.conn is None:
|
|
295
289
|
try:
|
execsql/db/oracle.py
CHANGED
|
@@ -131,10 +131,12 @@ class OracleDatabase(Database):
|
|
|
131
131
|
|
|
132
132
|
def db_conn(db: OracleDatabase, db_name: str):
|
|
133
133
|
dsn = driver.makedsn(db.server_name, db.port, service_name=db_name)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
credentials = {}
|
|
135
|
+
if db.user:
|
|
136
|
+
credentials["user"] = db.user
|
|
137
|
+
if db.password is not None:
|
|
138
|
+
credentials["password"] = db.password
|
|
139
|
+
return driver.connect(dsn=dsn, **credentials)
|
|
138
140
|
|
|
139
141
|
if self.conn is None:
|
|
140
142
|
try:
|
execsql/db/postgres.py
CHANGED
|
@@ -90,24 +90,19 @@ class PostgresDatabase(Database):
|
|
|
90
90
|
# between runs; a cached plan whose result type then changes triggers
|
|
91
91
|
# PostgreSQL's "cached plan must not change result type" error. psycopg2
|
|
92
92
|
# never auto-prepared, so this preserves backwards-compatible behavior.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
dbname=db_name,
|
|
107
|
-
port=db.port,
|
|
108
|
-
connect_timeout=db.connect_timeout,
|
|
109
|
-
prepare_threshold=None,
|
|
110
|
-
)
|
|
93
|
+
credentials = {}
|
|
94
|
+
if db.user:
|
|
95
|
+
credentials["user"] = db.user
|
|
96
|
+
if db.password is not None:
|
|
97
|
+
credentials["password"] = db.password
|
|
98
|
+
return psycopg.connect(
|
|
99
|
+
host=str(db.server_name),
|
|
100
|
+
dbname=db_name,
|
|
101
|
+
port=db.port,
|
|
102
|
+
connect_timeout=db.connect_timeout,
|
|
103
|
+
prepare_threshold=None,
|
|
104
|
+
**credentials,
|
|
105
|
+
)
|
|
111
106
|
except Exception as e:
|
|
112
107
|
msg = (
|
|
113
108
|
f"Failed to open PostgreSQL database {self.db_name} on {self.server_name}; "
|
execsql/exceptions.py
CHANGED
|
@@ -108,6 +108,8 @@ class ErrInfo(ExecSqlError):
|
|
|
108
108
|
|
|
109
109
|
``eval_err()`` / ``write()`` remain available for the full formatted
|
|
110
110
|
message including script location, timestamp, and command context.
|
|
111
|
+
``always_halt`` makes a metacommand failure stop execution regardless
|
|
112
|
+
of the metacommand-error setting, such as an unevaluable condition.
|
|
111
113
|
"""
|
|
112
114
|
|
|
113
115
|
def __repr__(self) -> str:
|
|
@@ -122,6 +124,8 @@ class ErrInfo(ExecSqlError):
|
|
|
122
124
|
command_text: str | None = None,
|
|
123
125
|
exception_msg: str | None = None,
|
|
124
126
|
other_msg: str | None = None,
|
|
127
|
+
*,
|
|
128
|
+
always_halt: bool = False,
|
|
125
129
|
) -> None:
|
|
126
130
|
self.type: str = type
|
|
127
131
|
self.command: str | None = command_text
|
|
@@ -132,6 +136,7 @@ class ErrInfo(ExecSqlError):
|
|
|
132
136
|
self.cmd: str | None = None
|
|
133
137
|
self.cmdtype: str | None = None
|
|
134
138
|
self.error_message: str | None = None
|
|
139
|
+
self.always_halt = always_halt
|
|
135
140
|
# Pass a concise message to Exception so str(e), e.args, and
|
|
136
141
|
# standard loggers produce useful output.
|
|
137
142
|
super().__init__(self.other or self.exception or self.type)
|
execsql/gui/__init__.py
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""GUI backend dispatch and the terminal fallback's manager loop.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
-----
|
|
5
|
-
Call ``enable_gui()`` (via ``execsql.utils.gui``) to initialise the backend
|
|
6
|
-
and start the manager thread. All dialog requests are then placed on
|
|
7
|
-
``_state.gui_manager_queue`` as ``GuiSpec`` objects and dispatched by
|
|
8
|
-
``gui_manager_loop()``.
|
|
3
|
+
``execsql.utils.gui.enable_gui()`` selects a backend by configured framework::
|
|
9
4
|
|
|
10
|
-
|
|
5
|
+
tkinter -> TkinterBackend -> TextualBackend -> ConsoleBackend
|
|
6
|
+
textual -> TextualBackend -> ConsoleBackend
|
|
11
7
|
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
Native Tk and ordinary Textual dialogs use synchronous queue adapters that run
|
|
9
|
+
in the calling thread. Only the ConsoleBackend fallback starts
|
|
10
|
+
``gui_manager_loop()`` on a daemon manager thread. The persistent Textual CLI
|
|
11
|
+
console instead runs its UI on the main thread and its script on a worker,
|
|
12
|
+
with ``_ConsoleDialogQueue`` carrying modal requests and responses.
|
|
13
|
+
|
|
14
|
+
Every request contains a return queue. Script-side consumers receive checked
|
|
15
|
+
results through ``get_gui_response()`` and own error/cancellation policy. See
|
|
16
|
+
``docs/dev/architecture.md`` for execution modes and shutdown ownership.
|
|
14
17
|
"""
|
|
15
18
|
|
|
16
19
|
from __future__ import annotations
|