Skip to content

Commit d8b4446

Browse files
author
stonebig
committed
sql splitting as a generator
1 parent ab11618 commit d8b4446

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

sqlite_bro/sqlite_bro.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ def bip(c):
670670
log.write(bip(counter))
671671
log.write(instruction)
672672
log.write("\n")
673-
instru = self.conn.get_sqlsplit(instruction,
674-
remove_comments=True)[0]
673+
instru = next(self.conn.get_sqlsplit(instruction,
674+
remove_comments=True))
675675
instru = instru.replace(";", "").strip(' \t\n\r')
676676
first_line = (instru + "\n").splitlines()[0]
677677
if instru[:5] == "pydef":
@@ -1454,9 +1454,8 @@ def get_tokens(self, sql, start=0, shell_tokens=False):
14541454
start = i
14551455

14561456
def get_sqlsplit(self, sql, remove_comments=False):
1457-
"""split an sql file in list of separated sql orders"""
1457+
"""yield a list of separated sql orders from a sql file"""
14581458
trigger_mode = False
1459-
sqls = []
14601459
mysql = [""]
14611460
for tokv, token in self.get_tokens(sql, shell_tokens=True):
14621461
# clear comments option
@@ -1476,15 +1475,14 @@ def get_sqlsplit(self, sql, remove_comments=False):
14761475
trigger_mode = False
14771476
elif (token == 'TK_SEMI' and not trigger_mode):
14781477
# end of a single sql
1479-
sqls.append("".join(mysql))
1478+
yield "".join(mysql)
14801479
mysql = []
14811480
elif (token == 'TK_SHELL'):
14821481
# end of a shell order
1483-
sqls.append("" + tokv)
1482+
yield("" + tokv)
14841483
mysql = []
14851484
if mysql != []:
1486-
sqls.append("".join(mysql))
1487-
return sqls
1485+
yield("".join(mysql))
14881486

14891487
def insert_reader(self, reader, table_name, create_sql=None,
14901488
create_table=True, replace=True, header=False):

0 commit comments

Comments
 (0)