Author: phd
Date: 2006-02-13 05:30:18 -0700 (Mon, 13 Feb 2006)
New Revision: 1597
Modified:
home/phd/SQLObject/paramstyles/sqlobject/col.py
home/phd/SQLObject/paramstyles/sqlobject/events.py
home/phd/SQLObject/paramstyles/sqlobject/main.py
home/phd/SQLObject/paramstyles/sqlobject/manager/command.py
home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_SQLMultipleJoin.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_cache.py
home/phd/SQLObject/paramstyles/sqlobject/tests/test_string_id.py
Log:
Merged patches from the revisions 1589:1596 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/col.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/col.py 2006-02-11 10:39:57 UTC (rev 1596)
+++ home/phd/SQLObject/paramstyles/sqlobject/col.py 2006-02-13 12:30:18 UTC (rev 1597)
@@ -752,8 +752,8 @@
'sTName': sTName})
return constraint
- def mysqlCreateSQL(self):
- sql = SOKeyCol.mysqlCreateSQL(self)
+ def mysqlCreateReferenceConstraint(self):
+ sTName = self.soClass.sqlmeta.table
other = findClass(self.foreignKey, self.soClass.sqlmeta.registry)
tName = other.sqlmeta.table
idName = other.sqlmeta.idName
@@ -766,18 +766,46 @@
action = 'ON DELETE RESTRICT'
else:
action = ''
- constraint = ('CONSTRAINT %(colName)s_exists '
+ constraint = ('ALTER TABLE %(sTName)s ADD CONSTRAINT %(sTName)s_%(colName)s_exists '
'FOREIGN KEY (%(colName)s) '
'REFERENCES %(tName)s (%(idName)s) '
'%(action)s' %
{'tName': tName,
'colName': self.dbName,
'idName': idName,
- 'action': action})
- sql = ', '.join([sql, constraint])
- return sql
+ 'action': action,
+ 'sTName': sTName})
+ return constraint
def mysqlCreateReferenceConstraint(self):
+ sTName = self.soClass.sqlmeta.table
+ other = findClass(self.foreignKey, self.soClass.sqlmeta.registry)
+ tName = other.sqlmeta.table
+ idName = other.sqlmeta.idName
+ if self.cascade is not None:
+ if self.cascade == 'null':
+ action = 'ON DELETE SET NULL'
+ elif self.cascade:
+ action = 'ON DELETE CASCADE'
+ else:
+ action = 'ON DELETE RESTRICT'
+ else:
+ action = ''
+ constraint = ('ALTER TABLE %(sTName)s ADD CONSTRAINT %(sTName)s_%(colName)s_to_%(tName)s '
+ 'FOREIGN KEY (%(colName)s) '
+ 'REFERENCES %(tName)s (%(idName)s) '
+ '%(action)s' %
+ {'tName': tName,
+ 'colName': self.dbName,
+ 'idName': idName,
+ 'action': action,
+ 'sTName': sTName})
+ return constraint
+
+ def mysqlCreateSQL(self):
+ return SOKeyCol.mysqlCreateSQL(self)
+
+ def mysqlCreateReferenceConstraint(self):
return None
def sybaseCreateSQL(self):
Modified: home/phd/SQLObject/paramstyles/sqlobject/events.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/events.py 2006-02-11 10:39:57 UTC (rev 1596)
+++ home/phd/SQLObject/paramstyles/sqlobject/events.py 2006-02-13 12:30:18 UTC (rev 1597)
@@ -79,7 +79,18 @@
Note: this is not called when an instance is created from an
existing database row.
"""
+class RowCreatedSignal(Signal):
+ """
+ Called after an instance is created, with the class as the
+ sender. Called with the arguments ``(kwargs, post_funcs)``.
+ There may be a ``connection`` argument. ``kwargs``may be usefully
+ modified. ``post_funcs`` is a list of callbacks, intended to have
+ functions appended to it, and are called with the arguments
+ ``(new_instance)``.
+ Note: this is not called when an instance is created from an
+ existing database row.
+ """
# @@: An event for getting a row? But for each row, when doing a
# select? For .sync, .syncUpdate, .expire?
Modified: home/phd/SQLObject/paramstyles/sqlobject/main.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/main.py 2006-02-11 10:39:57 UTC (rev 1596)
+++ home/phd/SQLObject/paramstyles/sqlobject/main.py 2006-02-13 12:30:18 UTC (rev 1597)
@@ -1273,7 +1273,11 @@
cache = self._connection.cache
cache.created(id, self.__class__, self)
self._init(id)
+ post_funcs = []
+ kw = dict([('class',self.__class__),('id',id)])
+ self.sqlmeta.send(events.RowCreatedSignal, kw, post_funcs)
+
def _SO_getID(self, obj):
return getID(obj)
Modified: home/phd/SQLObject/paramstyles/sqlobject/manager/command.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/manager/command.py 2006-02-11 10:39:57 UTC (rev 1596)
+++ home/phd/SQLObject/paramstyles/sqlobject/manager/command.py 2006-02-13 12:30:18 UTC (rev 1597)
@@ -1073,7 +1073,11 @@
if self.options.upgrade_to:
version_to = self.options.upgrade_to
else:
- version_to = os.path.basename(self.find_last_version())
+ fname = self.find_last_version()
+ if fname is None:
+ print "No version exists, use 'record' command to create one"
+ return
+ version_to = os.path.basename(fname)
current = self.current_version()
if v:
print 'Current version: %s' % current
Modified: home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py 2006-02-11 10:39:57 UTC (rev 1596)
+++ home/phd/SQLObject/paramstyles/sqlobject/mysql/mysqlconnection.py 2006-02-13 12:30:18 UTC (rev 1597)
@@ -18,6 +18,10 @@
self.db = db
self.user = user
self.password = password
+ if kw.has_key('client_encoding'):
+ self.client_encoding = col.popKey(kw, 'client_encoding')
+ else:
+ self.client_encoding = None
self.kw = {}
for key in ("unix_socket", "named_pipe", "init_command",
"read_default_file", "read_default_group"):
@@ -47,6 +51,8 @@
if hasattr(conn, 'autocommit'):
conn.autocommit(bool(self.autoCommit))
+ if self.client_encoding:
+ conn.query('SET NAMES ' + self.client_encoding)
return conn
@@ -98,9 +104,15 @@
def createColumn(self, soClass, col):
return col.mysqlCreateSQL()
+ def createReferenceConstraint(self, soClass, col):
+ return col.mysqlCreateReferenceConstraint()
+
def createIndexSQL(self, soClass, index):
return index.mysqlCreateIndexSQL(soClass)
+ def createReferenceConstraint(self, soClass, col):
+ return col.mysqlCreateReferenceConstraint()
+
def createIDColumn(self, soClass):
if soClass.sqlmeta.idType == str:
return '%s TEXT PRIMARY KEY' % soClass.sqlmeta.idName
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_SQLMultipleJoin.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_SQLMultipleJoin.py 2006-02-11 10:39:57 UTC (rev 1596)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_SQLMultipleJoin.py 2006-02-13 12:30:18 UTC (rev 1597)
@@ -40,4 +40,4 @@
assert saiyajin.fightersAsSResult.max('power') == 10
assert trunks in hibrid.fightersAsSResult
assert picollo not in hibrid.fightersAsSResult
- assert hibrid.fightersAsSResult.sum('power') == 23
+ assert str(hibrid.fightersAsSResult.sum('power')) == '23'
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_cache.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_cache.py 2006-02-11 10:39:57 UTC (rev 1596)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_cache.py 2006-02-13 12:30:18 UTC (rev 1597)
@@ -24,7 +24,7 @@
class CacheTest(SQLObject):
- name = StringCol(alternateID=True)
+ name = StringCol(alternateID=True, length=100)
def test_cache():
setupClass(CacheTest)
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/test_string_id.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/test_string_id.py 2006-02-11 10:39:57 UTC (rev 1596)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/test_string_id.py 2006-02-13 12:30:18 UTC (rev 1597)
@@ -5,7 +5,7 @@
class sqlmeta(sqlmeta):
idType = str
idName = 'test_id_here'
- name = StringCol()
+ name = StringCol(length=100)
def test_string_id():
conn = getConnection()
|