Skip to content

Commit aafd78c

Browse files
committed
add the '.separator COL' option
and revert a non-compatible PyPy change along the way
1 parent 80a3ddd commit aafd78c

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

sqlite_bro/sqlite_bro.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def __init__(self):
8181

8282
# defaults for export
8383
self.default_header = True
84+
self.default_separator = ","
8485

8586
def create_menu(self):
8687
"""create the menu of the application"""
@@ -686,7 +687,7 @@ def bip(c):
686687
log.write("\n")
687688
instru = next(self.conn.get_sqlsplit(instruction,
688689
remove_comments=True))
689-
instru = instru.replace(";", "").strip(' \t\n\r')
690+
instru = instru.replace(";", ";").strip(' \t\n\r')
690691
first_line = (instru + "\n").splitlines()[0]
691692
if instru[:5] == "pydef":
692693
pydef = self.conn.createpydef(instru)
@@ -706,6 +707,8 @@ def bip(c):
706707
self.default_header = False
707708
elif shell_list[1].lower() == 'on':
708709
self.default_header = True
710+
if shell_list[0] == '.separator' and len(shell_list) >= 2:
711+
self.default_separator = shell_list[1]
709712
if shell_list[0] == '.import' and len(shell_list) >= 2:
710713
csv_file = shell_list[1]
711714
if (csv_file+"z")[0] == "~":
@@ -757,6 +760,7 @@ def bip(c):
757760
csv_file = os.path.join(self.home , csv_file[1:])
758761
self.conn.export_writer(instruction, csv_file,
759762
header=self.default_header,
763+
delimiter=self.default_separator,
760764
encoding=encode_in)
761765
self.n.add_treeview(tab_tk_id, ('qry', 'file'),
762766
((instruction, csv_file),),
@@ -1634,11 +1638,13 @@ def _main():
16341638
SELECT ItemNo, Description FROM Item; -- see all is back to normal
16351639
RELEASE SAVEPOINT remember_Neo; -- free memory
16361640
\n\n-- '.' commands understood:
1637-
-- .headers on|off Include column headers in next .once exports (default on)
1638-
-- .once [--bom] FILENAME Output of next SQL command to FILENAME [with utf-8 bom]
1641+
-- .headers on|off Include column headers in next .once exports (default on)
1642+
-- .separator COL Set column separator in next .once exports (default ,)
1643+
-- .once [--bom] FILE Output of next SQL command to FILE [with utf-8 bom]
16391644
-- .import FILE TABLE Import data from FILE into TABLE
16401645
-- (create table only if it doesn't exist, keep existing records)
16411646
.headers on
1647+
.separator ;
16421648
.once --bom '~this_file_of_result.txt'
16431649
select ItemNo, Description from item order by ItemNo desc;
16441650
.import '~this_file_of_result.txt' in_this_table

0 commit comments

Comments
 (0)