|
57 | 57 | INSERT INTO item values('T','Ford',1000); |
58 | 58 | INSERT INTO item select 'A','Merced',1250 union all select 'W','Wheel',9 ; |
59 | 59 | INSERT INTO part select ItemNo,'W','needed',Kg/250 from item where Kg>250; |
60 | | -""" |
61 | | - |
62 | | -WELCOME_DUCKDB = """-- DuckDB Memo (Demo = click on green "->" icon) |
63 | | --- (this database uses the DuckDB engine : SQL is stricter than SQLite) |
64 | | -\n-- to CREATE tables : column types are mandatory |
65 | | -""" + WELCOME_CREATE + """\n-- to CREATE a Python embedded function (needs numpy installed), |
| 60 | +\n-- to CREATE a Python embedded function, |
66 | 61 | -- enclose it by "pydef" and ";" : |
67 | 62 | pydef py_hello(): |
68 | 63 | "hello world" |
|
71 | 66 | "fibonacci : example with function call (may only be internal) " |
72 | 67 | fib = lambda n: n if n < 2 else fib(n-1) + fib(n-2) |
73 | 68 | return("%s" % fib(n*1)); |
74 | | -pydef py_fib_typed(n: int) -> int: |
75 | | - "type-annotated pydef : registered natively (faster, typed) " |
76 | | - fib = lambda n: n if n < 2 else fib(n-1) + fib(n-2) |
77 | | - return fib(n); |
78 | | -\n-- to USE a python embedded function : |
79 | | -select py_hello(), py_fib(6) as fibonacci, py_fib_typed(7) as fib_typed, |
80 | | - version() as duckdb_version, |
81 | | - current_localtime() t, current_localtimestamp() dt; |
82 | | -\n-- some DuckDB goodies : |
83 | | -DESCRIBE item; |
84 | | -SUMMARIZE item; |
85 | | -select * from duckdb_tables(); |
86 | | -\n-- to use COMMIT and ROLLBACK (DuckDB does not support SAVEPOINT) : |
| 69 | +""" |
| 70 | + |
| 71 | +WELCOME_END = """\n-- to EXPORT : |
| 72 | +-- a TABLE, select TABLE, then click on icon 'SQL->CSV' |
| 73 | +-- a QUERY RESULT, select the SCRIPT text, then click on icon '???->CSV', |
| 74 | +-- example : select the end of this line: SELECT SQLITE_VERSION() |
| 75 | +\n\n-- to use COMMIT and ROLLBACK : |
87 | 76 | BEGIN TRANSACTION; |
88 | 77 | UPDATE item SET Kg = Kg + 1; |
89 | 78 | COMMIT; |
|
92 | 81 | select Kg, Description from Item; |
93 | 82 | ROLLBACK; |
94 | 83 | select Kg, Description from Item; |
95 | | -\n-- '.' commands understood (same as in SQLite mode, see sqlite demo) : |
| 84 | +
|
| 85 | +\n\n-- '.' commands understood: |
| 86 | +-- .backup FILE Backup DB (default "main") to FILE (if Python>=3.7) |
| 87 | +-- .cd DIRECTORY Change the working directory to DIRECTORY |
| 88 | +-- .dump ?FILE? Render database content as SQL (to FILE if specified) |
| 89 | +-- .excel Display the output of next command in spreadsheet |
| 90 | +-- .headers on|off Turn display of headers on or off |
| 91 | +-- .import FILE TABLE Import data from FILE into TABLE |
| 92 | +-- (create TABLE only if it doesn't exist, keep existing records) |
| 93 | +-- .once [--bom] FILE Output of next SQL command to FILE [with utf-8 bom] |
| 94 | +-- .open ?FILE? Close existing database and reopen FILE |
| 95 | +-- .output ?FILE? Send output to FILE or stdout if FILE is omitted |
| 96 | +-- .print STRING... Print literal STRING |
| 97 | +-- .read FILE Read input from FILE |
| 98 | +-- .restore FILE Restore DB (default "main") from FILE (if Python>=3.7) |
| 99 | +-- .separator COL Set column separator in next .once exports (default ,) |
| 100 | +-- .shell CMD ARGS... Run CMD ARGS... in a system shell |
| 101 | +
|
96 | 102 | .headers on |
97 | 103 | .separator ; |
98 | 104 | .once --bom '~this_file_of result.txt' |
99 | 105 | select ItemNo, Description from item order by ItemNo desc; |
100 | 106 | .import '~this_file_of result.txt' in_this_table |
101 | 107 | .cd ~ |
102 | | -ATTACH 'test.duckdb' as toto; |
| 108 | +ATTACH 'test.db' as toto; |
103 | 109 | DROP TABLE IF EXISTS toto.new_item; |
104 | 110 | CREATE TABLE toto.new_item as select * from "main"."item"; |
105 | 111 | .dump |
106 | 112 | """ |
107 | 113 |
|
| 114 | +WELCOME_DUCKDB = """-- DuckDB Memo (Demo = click on green "->" icon) |
| 115 | +-- (this database uses the DuckDB engine : SQL is stricter than SQLite) |
| 116 | +\n-- to CREATE tables : column types are mandatory |
| 117 | +""" + WELCOME_CREATE + """ |
| 118 | +pydef py_fib_typed(n: int) -> int: |
| 119 | + "type-annotated pydef : registered natively (faster, typed) " |
| 120 | + fib = lambda n: n if n < 2 else fib(n-1) + fib(n-2) |
| 121 | + return fib(n); |
| 122 | +\n-- to USE a python embedded function (require numpy installed for DuckDb): |
| 123 | +select py_hello(),py_fib_typed(7) as fib_typed, version() as duckdb_version; |
| 124 | +
|
| 125 | +\n-- some DuckDB goodies : |
| 126 | +DESCRIBE item; |
| 127 | +SUMMARIZE item; |
| 128 | +select * from duckdb_tables(); |
| 129 | +
|
| 130 | +""" + WELCOME_END.replace('test.db', 'test.duckdb') |
| 131 | + |
108 | 132 |
|
109 | 133 | class App: |
110 | 134 | """the GUI graphic application""" |
@@ -2901,67 +2925,18 @@ def _main(): |
2901 | 2925 | welcome_text = """-- SQLite Memo (Demo = click on green "->" and "@" icons) |
2902 | 2926 | -- (tip : open or create a '.duckdb' file to use the DuckDB engine instead) |
2903 | 2927 | \n-- to CREATE a table 'item' and a table 'part' : |
2904 | | -""" + WELCOME_CREATE + """\n-- to CREATE a Python embedded function, enclose them by "py" and ";" : |
2905 | | -pydef py_hello(): |
2906 | | - "hello world" |
2907 | | - return ("Hello, World !"); |
2908 | | -pydef py_fib(n): |
2909 | | - "fibonacci : example with function call (may only be internal) " |
2910 | | - fib = lambda n: n if n < 2 else fib(n-1) + fib(n-2) |
2911 | | - return("%s" % fib(n*1)); |
2912 | | -
|
2913 | | --- to USE a python embedded function and nesting of embedded functions: |
| 2928 | +""" + WELCOME_CREATE + """ |
| 2929 | +\n-- to USE a python embedded function : |
2914 | 2930 | select py_hello(), py_fib(6) as fibonacci, sqlite_version(), |
2915 | 2931 | time('now', 'localtime') t, datetime('now', 'localtime') dt; |
2916 | | -\n-- to EXPORT : |
2917 | | --- a TABLE, select TABLE, then click on icon 'SQL->CSV' |
2918 | | --- a QUERY RESULT, select the SCRIPT text, then click on icon '???->CSV', |
2919 | | --- example : select the end of this line: SELECT SQLITE_VERSION() |
2920 | | -\n\n-- to use COMMIT and ROLLBACK : |
2921 | | -BEGIN TRANSACTION; |
2922 | | -UPDATE item SET Kg = Kg + 1; |
2923 | | -COMMIT; |
2924 | | -BEGIN TRANSACTION; |
2925 | | -UPDATE item SET Kg = 0; |
2926 | | -select Kg, Description from Item; |
2927 | | -ROLLBACK; |
2928 | | -select Kg, Description from Item; |
2929 | | -\n\n-- to use SAVEPOINT : |
| 2932 | +\n-- to use SAVEPOINT : |
2930 | 2933 | SAVEPOINT remember_Neo; -- create a savepoint |
2931 | 2934 | UPDATE item SET Description = 'Smith'; -- do things |
2932 | 2935 | SELECT ItemNo, Description FROM Item; -- see things done |
2933 | 2936 | ROLLBACK TO SAVEPOINT remember_Neo; -- go back to savepoint state |
2934 | 2937 | SELECT ItemNo, Description FROM Item; -- see all is back to normal |
2935 | 2938 | RELEASE SAVEPOINT remember_Neo; -- free memory |
2936 | | -
|
2937 | | -\n\n-- '.' commands understood: |
2938 | | --- .backup FILE Backup DB (default "main") to FILE (if Python>=3.7) |
2939 | | --- .cd DIRECTORY Change the working directory to DIRECTORY |
2940 | | --- .dump ?FILE? Render database content as SQL (to FILE if specified) |
2941 | | --- .excel Display the output of next command in spreadsheet |
2942 | | --- .headers on|off Turn display of headers on or off |
2943 | | --- .import FILE TABLE Import data from FILE into TABLE |
2944 | | --- (create TABLE only if it doesn't exist, keep existing records) |
2945 | | --- .once [--bom] FILE Output of next SQL command to FILE [with utf-8 bom] |
2946 | | --- .open ?FILE? Close existing database and reopen FILE |
2947 | | --- .output ?FILE? Send output to FILE or stdout if FILE is omitted |
2948 | | --- .print STRING... Print literal STRING |
2949 | | --- .read FILE Read input from FILE |
2950 | | --- .restore FILE Restore DB (default "main") from FILE (if Python>=3.7) |
2951 | | --- .separator COL Set column separator in next .once exports (default ,) |
2952 | | --- .shell CMD ARGS... Run CMD ARGS... in a system shell |
2953 | | -
|
2954 | | -.headers on |
2955 | | -.separator ; |
2956 | | -.once --bom '~this_file_of result.txt' |
2957 | | -select ItemNo, Description from item order by ItemNo desc; |
2958 | | -.import '~this_file_of result.txt' in_this_table |
2959 | | -.cd ~ |
2960 | | -ATTACH 'test.db' as toto; |
2961 | | -DROP TABLE IF EXISTS toto.new_item; |
2962 | | -CREATE TABLE toto.new_item as select * from "main"."item"; |
2963 | | -.dump |
2964 | | -""" |
| 2939 | +"""+ WELCOME_END |
2965 | 2940 |
|
2966 | 2941 | parser = argparse.ArgumentParser( |
2967 | 2942 | description="sqlite_bro : a graphic SQLite and DuckDB browser" |
|
0 commit comments