@@ -32,8 +32,8 @@ class App:
3232 """the GUI graphic application"""
3333 def __init__ (self ):
3434 """create a tkk graphic interface with a main window tk_win"""
35- self .__version__ = '0.9.3 '
36- self ._title = "of 2021-04-25a : 'Hello, World!'"
35+ self .__version__ = '0.10.0 '
36+ self ._title = "of 2021-08-01a : 'Hello, better .scripting World!'"
3737 self .conn = None # Baresql database object
3838 self .database_file = ""
3939 self .tk_win = Tk ()
@@ -82,7 +82,8 @@ def __init__(self):
8282 # defaults for export
8383 self .default_header = True
8484 self .default_separator = ","
85-
85+ self .current_directory = os .getcwd ()
86+
8687 def create_menu (self ):
8788 """create the menu of the application"""
8889 menubar = Menu (self .tk_win )
@@ -246,15 +247,18 @@ def sav_script(self):
246247 f .write ("/*utf-8 tag : 你好 мир Artisou à croute*/\n " )
247248 f .write (script )
248249
249- def attach_db (self , filename = '' ):
250+ def attach_db (self , filename = '' , attach_as = '' ):
250251 """attach an existing database"""
251252 if filename == '' :
252253 filename = filedialog .askopenfilename (
253254 initialdir = self .initialdir , defaultextension = '.db' ,
254255 title = "Choose a database to attach " ,
255256 filetypes = [("default" , "*.db" ), ("other" , "*.db*" ),
256257 ("all" , "*.*" )])
257- attach = os .path .basename (filename ).split ("." )[0 ]
258+ if attach_as == '' :
259+ attach = os .path .basename (filename ).split ("." )[0 ]
260+ else :
261+ attach = attach_as
258262 avoid = {i [1 ]: 0 for i in get_leaves (self .conn , 'attached_databases' )}
259263 att , indice = attach , 0
260264 while attach in avoid :
@@ -704,11 +708,18 @@ def bip(c):
704708 # import FILE TABLE
705709 shell_list = shlex .split (instru ) # magic standard library
706710 try :
707- if shell_list [0 ] == '.attach ' and len (shell_list ) >= 2 :
711+ if shell_list [0 ] == '.cd ' and len (shell_list ) >= 2 :
708712 db_file = shell_list [1 ]
709713 if (db_file + "z" )[0 ] == "~" :
710- db_file = os .path .join (self .home , db_file [1 :])
711- self .attach_db (db_file )
714+ self .current_directory = os .path .join (self .home , db_file [1 :])
715+ elif (db_file + "z" )[:2 ] == ".." :
716+ self .current_directory = os .path .join (self .current_directory , db_file )
717+ elif (db_file + "z" )[:1 ] == "." :
718+ self .current_directory = os .path .join (self .current_directory , db_file [1 :])
719+ else :
720+ self .current_directory = db_file
721+ os .chdir (self .current_directory )
722+ self .current_directory = os .getcwd ()
712723 if shell_list [0 ] == '.headers' and len (shell_list ) >= 2 :
713724 if shell_list [1 ].lower () == 'off' :
714725 self .default_header = False
@@ -1645,7 +1656,7 @@ def _main():
16451656SELECT ItemNo, Description FROM Item; -- see all is back to normal
16461657RELEASE SAVEPOINT remember_Neo; -- free memory
16471658\n \n -- '.' commands understood:
1648- -- .attach DATABASE Attach the given Database DATABASE
1659+ -- .cd DIRECTORY Change the working directory to DIRECTORY
16491660-- .headers on|off Include column headers in next .once exports (default on)
16501661-- .separator COL Set column separator in next .once exports (default ,)
16511662-- .once [--bom] FILE Output of next SQL command to FILE [with utf-8 bom]
@@ -1656,9 +1667,10 @@ def _main():
16561667.once --bom '~this_file_of_result.txt'
16571668select ItemNo, Description from item order by ItemNo desc;
16581669.import '~this_file_of_result.txt' in_this_table
1659- .attach '~test.db'
1660- DROP TABLE IF EXISTS test.new_item;
1661- CREATE TABLE test.new_item as select * from "main"."item"
1670+ .cd ~
1671+ ATTACH 'test.db' as toto;
1672+ DROP TABLE IF EXISTS toto.new_item;
1673+ CREATE TABLE toto.new_item as select * from "main"."item"
16621674"""
16631675 app .n .new_query_tab ("Welcome" , welcome_text )
16641676 app .tk_win .mainloop ()
0 commit comments