Skip to content

Commit

Permalink
avoid encoding problems when handling unicode strings from sqlite db
Browse files Browse the repository at this point in the history
  • Loading branch information
mir06 committed Oct 25, 2016
1 parent a34f81b commit ecb4145
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dbbackup/db/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def _write_dump(self, fileobj):
# Make SQL commands in 1 line
sql = sql.replace('\n ', '')
sql = sql.replace('\n)', ')')
fileobj.write("{};\n".format(sql).encode('UTF-8'))
fileobj.write(u"{};\n".format(sql).encode('UTF-8'))
else:
fileobj.write("{};\n".format(sql))
fileobj.write(u"{};\n".format(sql))
table_name_ident = table_name.replace('"', '""')
res = cursor.execute('PRAGMA table_info("{0}")'.format(table_name_ident))
column_names = [str(table_info[1]) for table_info in res.fetchall()]
Expand All @@ -46,12 +46,12 @@ def _write_dump(self, fileobj):
for col in column_names))
query_res = cursor.execute(q)
for row in query_res:
fileobj.write("{};\n".format(row[0]).encode('UTF-8'))
fileobj.write(u"{};\n".format(row[0]).encode('UTF-8'))
schema_res = cursor.execute(DUMP_ETC)
for name, type, sql in schema_res.fetchall():
if sql.startswith("CREATE INDEX"):
sql = sql.replace('CREATE INDEX', 'CREATE INDEX IF NOT EXISTS')
fileobj.write('{};\n'.format(sql).encode('UTF-8'))
fileobj.write(u'{};\n'.format(sql).encode('UTF-8'))
cursor.close()

def create_dump(self):
Expand Down

0 comments on commit ecb4145

Please sign in to comment.