Default repository for execsql.py
Revisão | e8db761fb48fbe89025561edefa5ca12bf64fa00 (tree) |
---|---|
Hora | 2020-02-23 04:12:13 |
Autor | Dreas Nielsen <dreas.nielsen@gmai...> |
Commiter | Dreas Nielsen |
Added EXTEND SCRIPT metacommands for SQL statements, metacommands, and scripts.
@@ -1,6 +1,7 @@ | ||
1 | 1 | ========== ========== ================================================================================= |
2 | 2 | Version Date Features |
3 | 3 | ========== ========== ================================================================================= |
4 | +1.67.0 2020-02-22 Added the EXTEND SCRIPT WITH SQL and EXTEND SCRIPT WITH METACOMMAND metacommands, and aliased the APPEND SCRIPT metacommand to EXTEND SCRIPT...WITH SCRIPT. | |
4 | 5 | 1.66.0 2020-02-22 Added the DISCONNECT metacommand. |
5 | 6 | 1.65.0 2020-02-22 Added CONFIG SCAN_LINES and CONFIG GUI_LEVEL metacommands. |
6 | 7 | 1.64.0 2020-02-22 Added the LOCAL and USER keywords to the DEBUG LOG CONFIG metacommand. |
@@ -58,9 +58,9 @@ | ||
58 | 58 | # built documents. |
59 | 59 | # |
60 | 60 | # The short X.Y version. |
61 | -version = u'1.66' | |
61 | +version = u'1.67' | |
62 | 62 | # The full version, including alpha/beta/rc tags. |
63 | -release = u'1.66' | |
63 | +release = u'1.67' | |
64 | 64 | |
65 | 65 | # A string of reStructuredText that will be included at the beginning of |
66 | 66 | # every source file that is read. |
@@ -1775,6 +1775,38 @@ | ||
1775 | 1775 | EXTEND SCRIPT |
1776 | 1776 | ----------------------------------------- |
1777 | 1777 | |
1778 | +Several forms of the EXTEND SCRIPT metacommand allow a script that has | |
1779 | +previously been created with the :ref:`BEGIN SCRIPT <beginscript>` | |
1780 | +metacommand to be modified by the addition of more commands. | |
1781 | + | |
1782 | +This may be useful, for example, if a cleanup script is named in an | |
1783 | +:ref:`ON ERROR_HALT EXECUTE SCRIPT <error_halt_exec>` or | |
1784 | +:ref:`ON CANCEL_HALT EXECUTE SCRIPT <cancel_halt_exec>` metacommand, and | |
1785 | +additional steps should later be added to the cleanup script based on | |
1786 | +actions taken in the main script. | |
1787 | + | |
1788 | +:: | |
1789 | + | |
1790 | + EXTEND SCRIPT <script> WITH SQL <sql_statement> | |
1791 | + | |
1792 | +Appends the SQL statement to the end of the specified script. | |
1793 | +Substitution variables will be evaluated twice: once when the | |
1794 | +EXTEND SCRIPT metacommand is run, and a second time when the SQL | |
1795 | +statement itself is run. :ref:`Deferred substitution <deferred_substitution>` | |
1796 | +may be needed to ensure that some substitution variables are | |
1797 | +replaced when the SQL statement is run. | |
1798 | + | |
1799 | +:: | |
1800 | + | |
1801 | + EXTEND SCRIPT <script> WITH METACOMMAND <metacommand> | |
1802 | + | |
1803 | +Appends the metacommand statement to the end of the specified script. | |
1804 | +Substitution variables will be evaluated twice: once when the | |
1805 | +EXTEND SCRIPT metacommand is run, and a second time when the metacommand | |
1806 | +statement itself is run. :ref:`Deferred substitution <deferred_substitution>` | |
1807 | +may be needed to ensure that some substitution variables are | |
1808 | +replaced when the metacommand is run. | |
1809 | + | |
1778 | 1810 | :: |
1779 | 1811 | |
1780 | 1812 | EXTEND SCRIPT <script_1> WITH SCRIPT <script_2> |
@@ -1784,11 +1816,6 @@ | ||
1784 | 1816 | :ref:`BEGIN SCRIPT <beginscript>` metacommand. Parameters for *script_2* |
1785 | 1817 | are also added to *script_1*. |
1786 | 1818 | |
1787 | -If a cleanup script is named in an | |
1788 | -:ref:`ON ERROR_HALT EXECUTE SCRIPT <error_halt_exec>` or | |
1789 | -:ref:`ON CANCEL_HALT EXECUTE SCRIPT <cancel_halt_exec>` metacommand, the | |
1790 | -APPEND SCRIPT metacommand allows the cleanup script to be extended as | |
1791 | -appropriate. | |
1792 | 1819 | |
1793 | 1820 | |
1794 | 1821 |
@@ -637,7 +637,8 @@ | ||
637 | 637 | ------------------------------------ |
638 | 638 | |
639 | 639 | The ON ERROR_HALT metacommands, the ON CANCEL_HALT metacommands, the |
640 | -EXECUTE SCRIPT WHILE/UNTIL metacommands, and the LOOP metacommand | |
640 | +EXECUTE SCRIPT WHILE/UNTIL metacommands, the LOOP metacommand, and | |
641 | +two forms of the EXTEND SCRIPT metacommand | |
641 | 642 | all accept clauses or arguments that can contain substitution variables |
642 | 643 | that are meant to be evaluated after the execution of the metacommand |
643 | 644 | itself. For example, in the metacommand line:: |
@@ -658,6 +659,4 @@ | ||
658 | 659 | |
659 | 660 | ON ERROR_HALT WRITE "Error in line: !{$LAST_ERROR}!" |
660 | 661 | |
661 | -Deferred substitution may also be of use in some other circumstances, | |
662 | -such as arguments used with the :ref:`EXECUTE SCRIPT <executescript>` metacommand. | |
663 | 662 |
@@ -27,12 +27,12 @@ | ||
27 | 27 | # |
28 | 28 | # =============================================================================== |
29 | 29 | |
30 | -__version__ = "1.66.1" | |
30 | +__version__ = "1.67.0" | |
31 | 31 | __vdate = "2020-02-22" |
32 | 32 | |
33 | 33 | primary_vno = 1 |
34 | -secondary_vno = 66 | |
35 | -tertiary_vno = 1 | |
34 | +secondary_vno = 67 | |
35 | +tertiary_vno = 0 | |
36 | 36 | |
37 | 37 | import os |
38 | 38 | import os.path |
@@ -10031,6 +10031,29 @@ | ||
10031 | 10031 | |
10032 | 10032 | |
10033 | 10033 | |
10034 | +#**** EXTEND SCRIPT WITH SQL | |
10035 | +def x_extendscript_sql(**kwargs): | |
10036 | + script = kwargs["script"].lower() | |
10037 | + if script not in savedscripts: | |
10038 | + raise ErrInfo("cmd", other_msg="There is no SCRIPT named %s." % script) | |
10039 | + sql = kwargs["sql"] | |
10040 | + savedscripts[script].add(SqlStmt(kwargs["sql"])) | |
10041 | + | |
10042 | +metacommands.append(MetaCommand(r'\s*EXTEND\s+SCRIPT\s+(?P<script>\w+)\s+WITH\s+SQL\s+(?P<sql>.+)\s*$', x_extendscript_sql)) | |
10043 | + | |
10044 | + | |
10045 | + | |
10046 | +#**** EXTEND SCRIPT WITH METACOMMAND | |
10047 | +def x_extendscript_metacommand(**kwargs): | |
10048 | + script = kwargs["script"].lower() | |
10049 | + if script not in savedscripts: | |
10050 | + raise ErrInfo("cmd", other_msg="There is no SCRIPT named %s." % script) | |
10051 | + savedscripts[script].add(MetacommandStmt(kwargs["cmd"])) | |
10052 | + | |
10053 | +metacommands.append(MetaCommand(r'\s*EXTEND\s+SCRIPT\s+(?P<script>\w+)\s+WITH\s+METACOMMAND\s+(?P<cmd>.+)\s*$', x_extendscript_metacommand)) | |
10054 | + | |
10055 | + | |
10056 | + | |
10034 | 10057 | #**** EXECUTE SCRIPT |
10035 | 10058 | def x_executescript(**kwargs): |
10036 | 10059 | ScriptExecSpec(**kwargs).execute() |
@@ -4,7 +4,7 @@ | ||
4 | 4 | long_description = f.read() |
5 | 5 | |
6 | 6 | setuptools.setup(name='execsql', |
7 | - version='1.66.0', | |
7 | + version='1.67.0', | |
8 | 8 | description="Runs a SQL script against a PostgreSQL, MS-Access, SQLite, MS-SQL-Server, MySQL, MariaDB, Firebird, or Oracle database, or an ODBC DSN. Provides metacommands to import and export data, copy data between databases, conditionally execute SQL and metacommands, and dynamically alter SQL and metacommands with substitution variables. Data can be exported in 13 different formats, including CSV, TSV, ODS, HTML, JSON, LaTeX, and Markdown tables, and using custom templates.", |
9 | 9 | author='Dreas Nielsen', |
10 | 10 | author_email='dreas.nielsen@gmail.com', |