@@ -78,6 +78,9 @@ def __init__(self):
7878
7979 # define default home directory
8080 self .home = expanduser ("~" )
81+
82+ # defaults for export
83+ self .default_header = True
8184
8285 def create_menu (self ):
8386 """create the menu of the application"""
@@ -698,6 +701,11 @@ def bip(c):
698701 # import FILE TABLE
699702 shell_list = shlex .split (instru ) # magic standard library
700703 try :
704+ if shell_list [0 ] == '.headers' and len (shell_list ) >= 2 :
705+ if shell_list [1 ].lower () == 'off' :
706+ self .default_header = False
707+ elif shell_list [1 ].lower () == 'on' :
708+ self .default_header = True
701709 if shell_list [0 ] == '.import' and len (shell_list ) >= 2 :
702710 csv_file = shell_list [1 ]
703711 if (csv_file + "z" )[0 ] == "~" :
@@ -748,6 +756,7 @@ def bip(c):
748756 if (csv_file + "z" )[0 ] == "~" :
749757 csv_file = os .path .join (self .home , csv_file [1 :])
750758 self .conn .export_writer (instruction , csv_file ,
759+ header = self .default_header ,
751760 encoding = encode_in )
752761 self .n .add_treeview (tab_tk_id , ('qry' , 'file' ),
753762 ((instruction , csv_file ),),
@@ -1479,7 +1488,7 @@ def get_tokens(self, sql, start=0, shell_tokens=False):
14791488 yield sql [start :i ], token
14801489 if token == 'TK_SEMI' : # a new sql order can be a new shell token
14811490 can_be_shell_command = True
1482- elif token not in ('TK_COM' , 'TK_SP' ): # can't be a shell token
1491+ elif token not in ('TK_COM' , 'TK_SP' , 'TK_SHELL' ): # can't be a shell token
14831492 can_be_shell_command = False
14841493 start = i
14851494
@@ -1625,9 +1634,11 @@ def _main():
16251634SELECT ItemNo, Description FROM Item; -- see all is back to normal
16261635RELEASE SAVEPOINT remember_Neo; -- free memory
16271636\n \n -- '.' commands understood:
1637+ -- .headers on|off Include column headers in next .once exports (default on)
16281638-- .once [--bom] FILENAME Output of next SQL command to FILENAME [with utf-8 bom]
16291639-- .import FILE TABLE Import data from FILE into TABLE
16301640-- (create table only if it doesn't exist, keep existing records)
1641+ .headers on
16311642.once --bom '~this_file_of_result.txt'
16321643select ItemNo, Description from item order by ItemNo desc;
16331644.import '~this_file_of_result.txt' in_this_table
0 commit comments