From 8a7953bb8f3b4075d82acaa192ee8ede8d95d3ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 19 Feb 2018 19:07:30 +0100 Subject: [PATCH] Use proper SQL types - When recreating the table to drop a column, the correct SQL type must be converted by the database. - SQLite uses BOOLEAN as base type for BOOL issue7120 review37001002 --- trytond/backend/sqlite/database.py | 1 + trytond/backend/sqlite/table.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/trytond/backend/sqlite/database.py b/trytond/backend/sqlite/database.py index be0e42facb..66249c6b74 100644 --- a/trytond/backend/sqlite/database.py +++ b/trytond/backend/sqlite/database.py @@ -236,6 +236,7 @@ class Database(DatabaseInterface): TYPES_MAPPING = { 'DATETIME': SQLType('TIMESTAMP', 'TIMESTAMP'), 'BIGINT': SQLType('INTEGER', 'INTEGER'), + 'BOOL': SQLType('BOOLEAN', 'BOOLEAN'), } def __new__(cls, name=':memory:'): diff --git a/trytond/backend/sqlite/table.py b/trytond/backend/sqlite/table.py index f2bab699af..ef97534a05 100644 --- a/trytond/backend/sqlite/table.py +++ b/trytond/backend/sqlite/table.py @@ -291,7 +291,9 @@ class TableHandler(TableHandlerInterface): def drop_column(self, column_name, exception=False): if not self.column_exist(column_name): return - cursor = Transaction().connection.cursor() + transaction = Transaction() + database = transaction.database + cursor = transaction.connection.cursor() temp_table = '_temp_%s' % self.table_name try: TableHandler.table_rename(self.table_name, temp_table) @@ -301,10 +303,12 @@ class TableHandler(TableHandlerInterface): logger.warning('Unable to drop column: Error renaming ' 'table %s to temp!', self.table_name) new_table = TableHandler(self._model, history=self.history) - for name, (notnull, hasdef, size, typname) \ - in self._columns.iteritems(): + for name, values in self._columns.iteritems(): if name != column_name: - new_table._add_raw_column(name, typname, field_size=size) + typname = values['typname'] + size = values['size'] + new_table._add_raw_column( + name, database.sql_type(typname), field_size=size) columns_name = [x for x in new_table._columns.keys()] cursor.execute(('INSERT INTO "%s" (' + ','.join('"%s"' % c for c in columns_name) +