This commit is contained in:
Bertrand Chenal committed 2009-03-12 16:04:37 +01:00
commit 4e71443fac
2 files changed
+16 -12

No files matched your search

+11 -10
View File
@@ -183,16 +183,17 @@ class TableHandler(TableHandlerInterface):
self.cursor.execute('ALTER TABLE "%s" ADD COLUMN "%s" %s' %
(self.table_name, column_name, column_type))
# check if table is non-empty:
self.cursor.execute('SELECT 1 FROM "%s" limit 1' % self.table_name)
if self.cursor.rowcount:
# Populate column with default values:
default = None
if default_fun is not None:
default = default_fun(self.cursor, 0, {})
self.cursor.execute('UPDATE "' + self.table_name + '" '\
'SET "' + column_name + '" = %s',
(column_format(default),))
if column_format:
# check if table is non-empty:
self.cursor.execute('SELECT 1 FROM "%s" limit 1' % self.table_name)
if self.cursor.rowcount:
# Populate column with default values:
default = None
if default_fun is not None:
default = default_fun(self.cursor, 0, {})
self.cursor.execute('UPDATE "' + self.table_name + '" '\
'SET "' + column_name + '" = %s',
(column_format(default),))
self._update_definitions()
+5 -2
View File
@@ -133,8 +133,7 @@ class ModelSQL(ModelStorage):
hasattr(field, 'size') and field.size or None)
if self._history:
history_table.add_raw_column(field_name,
FIELDS[field._type].sql_type(field),
FIELDS[field._type].sql_format)
FIELDS[field._type].sql_type(field), None)
if isinstance(field, (fields.Integer, fields.Float)):
table.db_default(field_name, 0)
@@ -170,6 +169,10 @@ class ModelSQL(ModelStorage):
table.add_constraint(ident, constraint)
if self._history:
for column_name in table._columns:
if not history_table.column_exist(column_name):
history_table.add_raw_column(column_name,
table._columns[column_name], None)
cursor.execute('SELECT id FROM "' + self._table + '"')
if cursor.rowcount:
cursor.execute('SELECT id FROM "' + self._table + '__history"')