Author: phd
Date: 2006-10-06 10:57:54 -0600 (Fri, 06 Oct 2006)
New Revision: 1989
Modified:
home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_inheritance.py
home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py
Log:
Merged patches from the revisions 1984:1988 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2006-10-06 16:57:00 UTC (rev 1988)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/__init__.py 2006-10-06 16:57:54 UTC (rev 1989)
@@ -1,6 +1,6 @@
from sqlobject import sqlbuilder
from sqlobject import classregistry
-from sqlobject import col
+from sqlobject.col import StringCol, ForeignKey
from sqlobject.main import sqlmeta, SQLObject, SelectResults, True, False, \
makeProperties, getterName, setterName
import iteration
@@ -92,8 +92,13 @@
#DSM: Update each child class if needed and existing (only for new
#DSM: dynamic column as no child classes exists at object creation)
+ if columnDef and hasattr(soClass, "q"):
+ q = getattr(soClass.q, columnDef.name, None)
+ else:
+ q = None
for c in sqlmeta.childClasses.values():
c.sqlmeta.addColumn(columnDef, connection=connection, childUpdate=True)
+ if q: setattr(c.q, columnDef.name, q)
addColumn = classmethod(addColumn)
@@ -101,10 +106,15 @@
soClass = sqlmeta.soClass
super(InheritableSQLMeta, sqlmeta).delColumn(column, changeSchema, connection)
+ if isinstance(column, str):
+ name = column
+ else:
+ name = column.name
+
#DSM: Update each child class if needed
#DSM: and delete properties for this column
for c in sqlmeta.childClasses.values():
- delattr(c, name)
+ delattr(c.q, name)
delColumn = classmethod(delColumn)
@@ -166,7 +176,7 @@
for column in currentClass.sqlmeta.columnDefinitions.values():
if column.name == 'childName':
continue
- if type(column) == col.ForeignKey:
+ if type(column) == ForeignKey:
continue
setattr(cls.q, column.name,
getattr(currentClass.q, column.name))
@@ -259,7 +269,7 @@
% column.name)
# if this class is inheritable, add column for children distinction
if cls._inheritable and (cls.__name__ != 'InheritableSQLObject'):
- sqlmeta.addColumn(col.StringCol(name='childName',
+ sqlmeta.addColumn(StringCol(name='childName',
# limit string length to get VARCHAR and not CLOB
length=255, default=None))
if not sqlmeta.columnList:
Modified: home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_inheritance.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_inheritance.py 2006-10-06 16:57:00 UTC (rev 1988)
+++ home/phd/SQLObject/paramstyles/sqlobject/inheritance/tests/test_inheritance.py 2006-10-06 16:57:54 UTC (rev 1989)
@@ -78,3 +78,39 @@
person = Employee.byLastName("Leader")
assert person.firstName == "Project"
+
+def test_addDelColumn():
+ setup()
+
+ assert hasattr(InheritablePerson, "firstName")
+ assert hasattr(Employee, "firstName")
+ assert hasattr(InheritablePerson.q, "firstName")
+ assert hasattr(Employee.q, "firstName")
+
+ Employee.sqlmeta.addColumn(IntCol('runtime', default=None))
+
+ assert not hasattr(InheritablePerson, 'runtime')
+ assert hasattr(Employee, 'runtime')
+ assert not hasattr(InheritablePerson.q, 'runtime')
+ assert hasattr(Employee.q, 'runtime')
+
+ InheritablePerson.sqlmeta.addColumn(IntCol('runtime2', default=None))
+
+ assert hasattr(InheritablePerson, 'runtime2')
+ assert hasattr(Employee, 'runtime2')
+ assert hasattr(InheritablePerson.q, 'runtime2')
+ assert hasattr(Employee.q, 'runtime2')
+
+ Employee.sqlmeta.delColumn('runtime')
+
+ assert not hasattr(InheritablePerson, 'runtime')
+ assert not hasattr(Employee, 'runtime')
+ assert not hasattr(InheritablePerson.q, 'runtime')
+ assert not hasattr(Employee.q, 'runtime')
+
+ InheritablePerson.sqlmeta.delColumn('runtime2')
+
+ assert not hasattr(InheritablePerson, 'runtime2')
+ assert not hasattr(Employee, 'runtime2')
+ assert not hasattr(InheritablePerson.q, 'runtime2')
+ assert not hasattr(Employee.q, 'runtime2')
Modified: home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py 2006-10-06 16:57:00 UTC (rev 1988)
+++ home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py 2006-10-06 16:57:54 UTC (rev 1989)
@@ -168,7 +168,7 @@
self.query('DESCRIBE %s' % (tableName))
return True
except ProgrammingError, e:
- if e.code == 1146: # ER_NO_SUCH_TABLE
+ if e[0].code == 1146: # ER_NO_SUCH_TABLE
return False
raise
|