diff --git a/dbbackup/db/sqlite.py b/dbbackup/db/sqlite.py index 04b89580..6d38e211 100644 --- a/dbbackup/db/sqlite.py +++ b/dbbackup/db/sqlite.py @@ -67,13 +67,25 @@ def restore_dump(self, dump): if not self.connection.is_usable(): self.connection.connect() cursor = self.connection.cursor() + sql_command = b"" + sql_is_complete = True for line in dump.readlines(): - try: - cursor.execute(line.decode('UTF-8')) - except OperationalError as err: - warnings.warn("Error in db restore: {}".format(err)) - except IntegrityError as err: - warnings.warn("Error in db restore: {}".format(err)) + sql_command = sql_command + line + line_str = line.decode('UTF-8') + if line_str.startswith("INSERT") and not line_str.endswith(");\n"): + sql_is_complete = False + continue + if not sql_is_complete and line_str.endswith(");\n"): + sql_is_complete = True + + if sql_is_complete: + try: + cursor.execute(sql_command.decode('UTF-8')) + except OperationalError as err: + warnings.warn("Error in db restore: {}".format(err)) + except IntegrityError as err: + warnings.warn("Error in db restore: {}".format(err)) + sql_command = b"" class SqliteCPConnector(BaseDBConnector): diff --git a/dbbackup/tests/test_connectors/test_sqlite.py b/dbbackup/tests/test_connectors/test_sqlite.py index 6f4dea95..92765924 100644 --- a/dbbackup/tests/test_connectors/test_sqlite.py +++ b/dbbackup/tests/test_connectors/test_sqlite.py @@ -6,7 +6,7 @@ from django.utils.six import BytesIO from dbbackup.db.sqlite import SqliteConnector, SqliteCPConnector -from dbbackup.tests.testapp.models import CharModel +from dbbackup.tests.testapp.models import CharModel, TextModel class SqliteConnectorTest(TestCase):