OLD | NEW |
1 #This file is part of Tryton. The COPYRIGHT file at the top level of | 1 #This file is part of Tryton. The COPYRIGHT file at the top level of |
2 #this repository contains the full copyright notices and license terms. | 2 #this repository contains the full copyright notices and license terms. |
3 | 3 |
4 from trytond.backend.table import TableHandlerInterface | 4 from trytond.backend.table import TableHandlerInterface |
5 import logging | 5 import logging |
6 import re | 6 import re |
7 | 7 |
8 | 8 |
9 class TableHandler(TableHandlerInterface): | 9 class TableHandler(TableHandlerInterface): |
10 def __init__(self, cursor, model, module_name=None, history=False): | 10 def __init__(self, cursor, model, module_name=None, history=False): |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 self.cursor.execute(('ALTER TABLE "%s" ADD COLUMN "%s" %s' + default) % | 184 self.cursor.execute(('ALTER TABLE "%s" ADD COLUMN "%s" %s' + default) % |
185 (self.table_name, column_name, column_type)) | 185 (self.table_name, column_name, column_type)) |
186 | 186 |
187 if column_format: | 187 if column_format: |
188 # check if table is non-empty: | 188 # check if table is non-empty: |
189 self.cursor.execute('SELECT 1 FROM "%s" limit 1' % self.table_name) | 189 self.cursor.execute('SELECT 1 FROM "%s" limit 1' % self.table_name) |
190 if self.cursor.fetchone(): | 190 if self.cursor.fetchone(): |
191 # Populate column with default values: | 191 # Populate column with default values: |
192 default = None | 192 default = None |
193 if default_fun is not None: | 193 if default_fun is not None: |
194 default = default_fun(self.cursor, 0, {}) | 194 default = default_fun() |
195 self.cursor.execute('UPDATE "' + self.table_name + '" '\ | 195 self.cursor.execute('UPDATE "' + self.table_name + '" '\ |
196 'SET "' + column_name + '" = %s', | 196 'SET "' + column_name + '" = %s', |
197 (column_format(default),)) | 197 (column_format(default),)) |
198 | 198 |
199 self._update_definitions() | 199 self._update_definitions() |
200 | 200 |
201 def add_fk(self, column_name, reference, on_delete=None): | 201 def add_fk(self, column_name, reference, on_delete=None): |
202 logging.getLogger('init').warning( | 202 logging.getLogger('init').warning( |
203 'Unable to add foreign key on table %s!' % \ | 203 'Unable to add foreign key on table %s!' % \ |
204 (self.table_name,)) | 204 (self.table_name,)) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 267 |
268 @staticmethod | 268 @staticmethod |
269 def drop_table(cursor, model, table, cascade=False): | 269 def drop_table(cursor, model, table, cascade=False): |
270 cursor.execute('DELETE from ir_model_data where '\ | 270 cursor.execute('DELETE from ir_model_data where '\ |
271 'model = \'%s\'' % model) | 271 'model = \'%s\'' % model) |
272 | 272 |
273 query = 'DROP TABLE "%s"' % table | 273 query = 'DROP TABLE "%s"' % table |
274 if cascade: | 274 if cascade: |
275 query = query + ' CASCADE' | 275 query = query + ' CASCADE' |
276 cursor.execute(query) | 276 cursor.execute(query) |
OLD | NEW |