sqlobject-cvs Mailing List for SQLObject (Page 103)
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
(9) |
Apr
(74) |
May
(29) |
Jun
(16) |
Jul
(28) |
Aug
(10) |
Sep
(57) |
Oct
(9) |
Nov
(29) |
Dec
(12) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
(7) |
Feb
(14) |
Mar
(6) |
Apr
(3) |
May
(12) |
Jun
(34) |
Jul
(9) |
Aug
(29) |
Sep
(22) |
Oct
(2) |
Nov
(15) |
Dec
(52) |
| 2005 |
Jan
(47) |
Feb
(78) |
Mar
(14) |
Apr
(35) |
May
(33) |
Jun
(16) |
Jul
(26) |
Aug
(63) |
Sep
(40) |
Oct
(96) |
Nov
(96) |
Dec
(123) |
| 2006 |
Jan
(159) |
Feb
(144) |
Mar
(64) |
Apr
(31) |
May
(88) |
Jun
(48) |
Jul
(16) |
Aug
(64) |
Sep
(87) |
Oct
(92) |
Nov
(56) |
Dec
(76) |
| 2007 |
Jan
(94) |
Feb
(103) |
Mar
(126) |
Apr
(123) |
May
(85) |
Jun
(11) |
Jul
(130) |
Aug
(47) |
Sep
(65) |
Oct
(70) |
Nov
(12) |
Dec
(11) |
| 2008 |
Jan
(30) |
Feb
(55) |
Mar
(88) |
Apr
(20) |
May
(50) |
Jun
|
Jul
(38) |
Aug
(1) |
Sep
(9) |
Oct
(5) |
Nov
(6) |
Dec
(39) |
| 2009 |
Jan
(8) |
Feb
(16) |
Mar
(3) |
Apr
(33) |
May
(44) |
Jun
(1) |
Jul
(10) |
Aug
(33) |
Sep
(74) |
Oct
(22) |
Nov
|
Dec
(15) |
| 2010 |
Jan
(28) |
Feb
(22) |
Mar
(46) |
Apr
(29) |
May
(1) |
Jun
(1) |
Jul
(27) |
Aug
(8) |
Sep
(5) |
Oct
(33) |
Nov
(24) |
Dec
(41) |
| 2011 |
Jan
(4) |
Feb
(12) |
Mar
(35) |
Apr
(29) |
May
(19) |
Jun
(16) |
Jul
(32) |
Aug
(25) |
Sep
(5) |
Oct
(11) |
Nov
(21) |
Dec
(12) |
| 2012 |
Jan
(3) |
Feb
(4) |
Mar
(20) |
Apr
(4) |
May
(25) |
Jun
(13) |
Jul
|
Aug
|
Sep
(2) |
Oct
(25) |
Nov
(9) |
Dec
(1) |
| 2013 |
Jan
(6) |
Feb
(8) |
Mar
|
Apr
(10) |
May
(31) |
Jun
(7) |
Jul
(18) |
Aug
(33) |
Sep
(4) |
Oct
(16) |
Nov
|
Dec
(27) |
| 2014 |
Jan
(2) |
Feb
|
Mar
|
Apr
(11) |
May
(39) |
Jun
(8) |
Jul
(11) |
Aug
(4) |
Sep
|
Oct
(27) |
Nov
|
Dec
(71) |
| 2015 |
Jan
(17) |
Feb
(47) |
Mar
(33) |
Apr
|
May
|
Jun
(9) |
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(8) |
| 2016 |
Jan
(4) |
Feb
(4) |
Mar
|
Apr
|
May
(12) |
Jun
(7) |
Jul
(9) |
Aug
(31) |
Sep
(8) |
Oct
(3) |
Nov
(15) |
Dec
(1) |
| 2017 |
Jan
(13) |
Feb
(7) |
Mar
(14) |
Apr
(8) |
May
(10) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
|
Oct
(8) |
Nov
(4) |
Dec
(5) |
| 2018 |
Jan
(2) |
Feb
(8) |
Mar
|
Apr
(4) |
May
|
Jun
(6) |
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2019 |
Jan
(1) |
Feb
(16) |
Mar
(1) |
Apr
(3) |
May
(5) |
Jun
(1) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
(3) |
| 2020 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(2) |
Nov
|
Dec
(2) |
| 2021 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(1) |
Dec
|
| 2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(6) |
Oct
(1) |
Nov
(1) |
Dec
(4) |
| 2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(3) |
Sep
(2) |
Oct
(2) |
Nov
(4) |
Dec
|
| 2024 |
Jan
|
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(9) |
| 2025 |
Jan
|
Feb
(4) |
Mar
(2) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(2) |
Dec
(2) |
|
From: <sub...@co...> - 2007-02-23 17:21:19
|
Author: luke
Date: 2007-02-23 10:21:12 -0700 (Fri, 23 Feb 2007)
New Revision: 2349
Modified:
SQLObject/branches/sqlbuilder-views/sqlobject/conftest.py
SQLObject/branches/sqlbuilder-views/sqlobject/converters.py
SQLObject/branches/sqlbuilder-views/sqlobject/dbconnection.py
SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py
SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_views.py
SQLObject/branches/sqlbuilder-views/sqlobject/views.py
Log:
More compact View aggregate handling, sqlrepr/tablesUsedDict caching (experimental)
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/conftest.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/conftest.py 2007-02-23 15:09:12 UTC (rev 2348)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/conftest.py 2007-02-23 17:21:12 UTC (rev 2349)
@@ -16,7 +16,7 @@
except ImportError: # Python 2.2
pass
else:
- pkg_resources.require('SQLObject')
+ pass #pkg_resources.require('SQLObject')
connectionShortcuts = {
'mysql': 'mysql://test@localhost/test',
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/converters.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/converters.py 2007-02-23 15:09:12 UTC (rev 2348)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/converters.py 2007-02-23 17:21:12 UTC (rev 2349)
@@ -227,6 +227,7 @@
registerConverter(Decimal, DecimalConverter)
def sqlrepr(obj, db=None):
+ import sqlbuilder
try:
reprFunc = obj.__sqlrepr__
except AttributeError:
@@ -236,4 +237,17 @@
(type(obj), repr(obj))
return converter(obj, db)
else:
- return reprFunc(db)
+# return reprFunc(db)
+ cache = getattr(obj, '_sqlreprCache', {})
+ if not isinstance(cache, dict):
+ #Alias etc
+ cache = {}
+ ret = cache.get(db, None)
+ if ret is None:
+ ret = reprFunc(db)
+ try:
+ cache[db] = ret
+ obj._sqlreprCache = cache
+ except TypeError:
+ pass
+ return ret
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/dbconnection.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/dbconnection.py 2007-02-23 15:09:12 UTC (rev 2348)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/dbconnection.py 2007-02-23 17:21:12 UTC (rev 2349)
@@ -495,7 +495,7 @@
def _SO_selectOneAlt(self, so, columnNames, condition):
if columnNames:
- columns = (isinstance(x, (str, unicode)) and sqlbuilder.SQLConstant(x) or x for x in columnNames)
+ columns = [isinstance(x, (str, unicode)) and sqlbuilder.SQLConstant(x) or x for x in columnNames]
else:
columns = None
return self.queryOne(self.sqlrepr(sqlbuilder.Select(columns,
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py 2007-02-23 15:09:12 UTC (rev 2348)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py 2007-02-23 17:21:12 UTC (rev 2349)
@@ -188,13 +188,16 @@
def tablesUsed(self, db):
return self.tablesUsedDict(db).keys()
def tablesUsedDict(self, db):
- tables = {}
- for table in self.tablesUsedImmediate():
- if hasattr(table, '__sqlrepr__'):
- table = sqlrepr(table, db)
- tables[table] = 1
- for component in self.components():
- tables.update(tablesUsedDict(component, db))
+ tables = getattr(db, 'tableCache', {}).get(id(self), None)
+ if tables is None:
+ tables = {}
+ for table in self.tablesUsedImmediate():
+ if hasattr(table, '__sqlrepr__'):
+ table = sqlrepr(table, db)
+ tables[table] = 1
+ for component in self.components():
+ tables.update(tablesUsedDict(component, db))
+ getattr(db, 'tableCache', {})[id(self)] = tables
return tables
def tablesUsedImmediate(self):
return []
@@ -434,7 +437,7 @@
def __init__(self, table, alias=None):
if hasattr(table, "sqlmeta"):
tableName = SQLConstant(table.sqlmeta.table)
- elif isinstance(table, Select):
+ elif isinstance(table, (Select,Union)):
assert alias is not None, "Alias name cannot be constructed from Select instances, please provide 'alias' kw."
tableName = Subquery('', table)
table = None
@@ -473,6 +476,24 @@
return [self.q]
+class Union(SQLExpression):
+ def __init__(self, *tables):
+ tabs = []
+ for t in tables:
+ if not isinstance(t, SQLExpression) and hasattr(t, 'sqlmeta'):
+ t = t.sqlmeta.table
+ if isinstance(t, Alias):
+ t = t.q
+ if isinstance(t, Table):
+ t = t.tableName
+ if not isinstance(t, SQLExpression):
+ t = SQLConstant(t.sqlmeta.table)
+ tabs.append(t)
+ self.tables = tabs
+
+ def __sqlrepr__(self, db):
+ return " UNION ".join([str(sqlrepr(t, db)) for t in self.tables])
+
########################################
## SQL Statements
########################################
@@ -1175,6 +1196,12 @@
val = sqlrepr(val, db)
return val
+ def tablesUsedImmediate(self):
+ return getattr(self._resolve(), 'tablesUsedImmediate', lambda: [])()
+
+ def components(self):
+ return getattr(self._resolve(), 'components', lambda: [])()
+
def _resolve(self):
return getattr(self.proxy, self.attr)
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_views.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_views.py 2007-02-23 15:09:12 UTC (rev 2348)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_views.py 2007-02-23 17:21:12 UTC (rev 2349)
@@ -42,6 +42,8 @@
number = StringCol(dbName=ViewPhone.q.number)
timesCalled = IntCol(dbName=func.COUNT(PhoneCall.q.toID))
+ timesCalledLong = IntCol(dbName=func.COUNT(PhoneCall.q.toID))
+ timesCalledLong.aggregateClause = PhoneCall.q.minutes>10
minutesCalled = IntCol(dbName=func.SUM(PhoneCall.q.minutes))
class ViewPhoneMore2(ViewPhoneMore):
@@ -49,6 +51,9 @@
table = 'vpm'
+class ViewPhoneInnerAggregate(ViewPhone):
+ twiceMinutes = IntCol(dbName=func.SUM(PhoneCall.q.minutes)*2)
+
def setup_module(mod):
setupClass([mod.PhoneNumber,mod.PhoneCall])
mod.ViewPhoneCall._connection = mod.PhoneNumber._connection
@@ -59,7 +64,8 @@
'number')
calls = inserts(mod.PhoneCall, [(phones[0], phones[1], 5),
(phones[0], phones[1], 20),
- (phones[1], phones[0], 10)],
+ (phones[1], phones[0], 10),
+ (phones[1], phones[0], 25)],
'phoneNumber to minutes')
mod.phones = phones
mod.calls = calls
@@ -100,6 +106,7 @@
checkAttr(ViewPhoneMore, phones[0].id, 'number', phones[0].number)
checkAttr(ViewPhoneMore, phones[0].id, 'minutesCalled', phones[0].incoming.sum(PhoneCall.q.minutes))
checkAttr(ViewPhoneMore, phones[0].id, 'timesCalled', phones[0].incoming.count())
+ checkAttr(ViewPhoneMore, phones[0].id, 'timesCalledLong', phones[0].incoming.filter(PhoneCall.q.minutes>10).count())
def testJoinView():
p = ViewPhone.get(phones[0].id)
@@ -107,6 +114,9 @@
assert p.vCalls.count() == 2
assert p.vCalls[0] == ViewPhoneCall.get(calls[0].id)
+def testInnerAggregate():
+ checkAttr(ViewPhoneInnerAggregate, phones[0].id, 'twiceMinutes', phones[0].calls.sum(PhoneCall.q.minutes)*2)
+
def testSelect():
s = ViewPhone.select()
assert s.count() == len(phones)
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/views.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-23 15:09:12 UTC (rev 2348)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-23 17:21:12 UTC (rev 2349)
@@ -78,18 +78,27 @@
SQLObject.__classinit__(cls, new_attrs)
# like is_base
if cls.__name__ != 'ViewSQLObject':
+ dbName = hasattr(cls,'_connection') and cls._connection.dbName or None
+
if getattr(cls.sqlmeta, 'table', None):
cls.sqlmeta.alias = cls.sqlmeta.table
else:
cls.sqlmeta.alias = cls.sqlmeta.style.pythonClassToDBTable(cls.__name__)
alias = cls.sqlmeta.alias
columns = [ColumnAS(cls.sqlmeta.idName, 'id')]
- aggregates = []
+ # {sqlrepr-key: [restriction, *aggregate-column]}
+ aggregates = {'':[None]}
for n,col in cls.sqlmeta.columns.iteritems():
- if isinstance(col.dbName, SQLCall):
- aggregates.append(ColumnAS(col.dbName, n))
+ ascol = ColumnAS(col.dbName, n)
+ if isAggregate(col.dbName):
+ restriction = getattr(col, 'aggregateClause',None)
+ if restriction:
+ restrictkey = sqlrepr(restriction, dbName)
+ aggregates[restrictkey] = aggregates.get(restrictkey, [restriction]) + [ascol]
+ else:
+ aggregates[''].append(ascol)
else:
- columns.append(ColumnAS(col.dbName, n))
+ columns.append(ascol)
metajoin = getattr(cls.sqlmeta, 'join', NoDefault)
clause = getattr(cls.sqlmeta, 'clause', NoDefault)
@@ -99,7 +108,9 @@
join=metajoin,
clause=clause)
- if aggregates:
+ aggregates = aggregates.values()
+
+ if len(aggregates) > 1:
join = []
last_alias = "%s_base" % alias
last_id = "id"
@@ -107,22 +118,28 @@
columns = [SQLConstant("%s.%s"%(last_alias,x.expr2)) for x in columns]
for i, agg in enumerate(aggregates):
+ restriction = agg[0]
+ if restriction is None:
+ restriction = clause
+ else:
+ restriction = AND(clause, restriction)
+ agg = agg[1:]
agg_alias = "%s_%s" % (alias, i)
agg_id = '%s_id'%agg_alias
if not last.q.alias.endswith('base'):
last = None
- new_alias = Alias(
- Select([ColumnAS(cls.sqlmeta.idName, agg_id), agg],
- groupBy=cls.sqlmeta.idName,
- join=metajoin,
- clause=clause),
+ new_alias = Alias(Select([ColumnAS(cls.sqlmeta.idName, agg_id)]+agg,
+ groupBy=cls.sqlmeta.idName,
+ join=metajoin,
+ clause=restriction),
agg_alias)
agg_join = LEFTJOINOn(last,
new_alias,
"%s.%s = %s.%s" % (last_alias, last_id, agg_alias, agg_id))
join.append(agg_join)
- columns.append(SQLConstant("%s.%s"%(agg_alias, agg.expr2)))
+ for col in agg:
+ columns.append(SQLConstant("%s.%s"%(agg_alias, col.expr2)))
last = new_alias
last_alias = agg_alias
@@ -134,6 +151,12 @@
cls.q = ViewSQLObjectTable(cls)
for n,col in cls.sqlmeta.columns.iteritems():
col.dbName = getattr(cls.q, n)
+
+def isAggregate(expr):
+ if isinstance(expr, SQLCall):
+ return True
+ if isinstance(expr, SQLOp):
+ return isAggregate(expr.expr1) or isAggregate(expr.expr2)
+ return False
-
######
|
|
From: SourceForge.net <no...@so...> - 2007-02-23 13:22:12
|
Bugs item #1665322, was opened at 2007-02-21 12:30 Message generated for change (Comment added) made by llucax You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Closed Resolution: Wont Fix Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: InheritableSQLObject childName column in sqlmeta.columns Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() print j.Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} I think 'childName' should not be "listed" in sqlmeta.columns because it's a SQLObject "artifact" (just like 'id' column). This complicate automatic conversion from SQLObject to other types (like TurboJson's jsonify_sqlobject() function). ---------------------------------------------------------------------- >Comment By: Leandro Lucarella (llucax) Date: 2007-02-23 10:22 Message: Logged In: YES user_id=240225 Originator: YES Because it doesn't behave like a real column (1665328 is an example, a regular column is inherited to all it's descendant, and the "None" behavior is another example too) and it's not user data. But I understand you don't see a great advantage on fixing it, i'll try to work on it when I have some time if you agree something is wrong and are interested in patches for this... (and don't want to work on a patch that it will not be accepted). ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-23 09:35 Message: Logged In: YES user_id=4799 Originator: NO Why is it a bug? It works as advertised. It is a real column, and it presents in .columns. In any case it would be so hard to fix, and fixing it gives so little advantage - I am not going to work on it. But I can test a patch if one appears. ---------------------------------------------------------------------- Comment By: Leandro Lucarella (llucax) Date: 2007-02-23 09:08 Message: Logged In: YES user_id=240225 Originator: YES Ok, it should be hard to fix, but don't you agree it's a bug? Shouldn't be emulated like the "id" column? It's not user data. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 16:41 Message: Logged In: YES user_id=4799 Originator: NO SQLObject emulates "id" columns. Unlike that fictional column childName is a real column. There is no way to remove it from .columns. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-23 13:17:13
|
Bugs item #1665328, was opened at 2007-02-21 12:36 Message generated for change (Comment added) made by llucax You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: childName column broken on leaf InheritableSQLObjects Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() class Derived(Base): derived = IntCol() Derived.createTable() class Derived2(Derived): _inheritable = False derived2 = IntCol() Derived2.createTable() Base(base=1) Derived(base=2, derived=2) Derived2(base=3, derived=3, derived2=3) print Base.get(1).childName # ok (None) print Base.get(2).childName # ok (None) print Base.get(3).childName Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1, in <lambda> File "sqlobject/main.py", line 987, in _SO_loadValue result = getattr(self, attrName) AttributeError: 'Derived2' object has no attribute '_SO_val_childName' Besides the bug, what's the idea of having a 'childName' attribute if it always return None? ---------------------------------------------------------------------- >Comment By: Leandro Lucarella (llucax) Date: 2007-02-23 10:17 Message: Logged In: YES user_id=240225 Originator: YES Yes, sorry about that one, I've just realized I was using Base and not Derived2 :S Anyways, it's an odd behavior, when trying to reconstruct an InheritableSQLObject, finding the parents and obtaining it's sqlmeta.columns, one have to be careful to see if the _intheritable flag is set in the leaf to check if the childName is really present or not. I'm more, and more convinced that childName should be treated specially, like the "id" column since it's such an special case (a SQLObject artifact, and not user data). I hope you reconsider reopening 1665322. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-23 09:38 Message: Logged In: YES user_id=4799 Originator: NO But it is not listed in Derived2.sqlmeta.columns: <class '__main__.Derived2'> {'derived2': <SOIntCol derived2>} This is exactly what "_inheritable=False" does - it removes childName from the leaf class(es). ---------------------------------------------------------------------- Comment By: Leandro Lucarella (llucax) Date: 2007-02-23 09:12 Message: Logged In: YES user_id=240225 Originator: YES But it's listed into the sqlmeta.columns: print Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 16:50 Message: Logged In: YES user_id=4799 Originator: NO Oops, sorry, I reproduced the traceback. It is not a bug. You have disabled childName column by setting _inheritable = False. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 16:48 Message: Logged In: YES user_id=4799 Originator: NO I cannot reproduce the bug. The program print 3 None's for me. SQLObject 0.7.3. As for the None's... I have to think about it... ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-23 12:38:56
|
Bugs item #1665328, was opened at 2007-02-21 18:36 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: childName column broken on leaf InheritableSQLObjects Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() class Derived(Base): derived = IntCol() Derived.createTable() class Derived2(Derived): _inheritable = False derived2 = IntCol() Derived2.createTable() Base(base=1) Derived(base=2, derived=2) Derived2(base=3, derived=3, derived2=3) print Base.get(1).childName # ok (None) print Base.get(2).childName # ok (None) print Base.get(3).childName Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1, in <lambda> File "sqlobject/main.py", line 987, in _SO_loadValue result = getattr(self, attrName) AttributeError: 'Derived2' object has no attribute '_SO_val_childName' Besides the bug, what's the idea of having a 'childName' attribute if it always return None? ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2007-02-23 15:38 Message: Logged In: YES user_id=4799 Originator: NO But it is not listed in Derived2.sqlmeta.columns: <class '__main__.Derived2'> {'derived2': <SOIntCol derived2>} This is exactly what "_inheritable=False" does - it removes childName from the leaf class(es). ---------------------------------------------------------------------- Comment By: Leandro Lucarella (llucax) Date: 2007-02-23 15:12 Message: Logged In: YES user_id=240225 Originator: YES But it's listed into the sqlmeta.columns: print Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 22:50 Message: Logged In: YES user_id=4799 Originator: NO Oops, sorry, I reproduced the traceback. It is not a bug. You have disabled childName column by setting _inheritable = False. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 22:48 Message: Logged In: YES user_id=4799 Originator: NO I cannot reproduce the bug. The program print 3 None's for me. SQLObject 0.7.3. As for the None's... I have to think about it... ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-23 12:36:10
|
Bugs item #1665322, was opened at 2007-02-21 18:30 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Closed Resolution: Wont Fix Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: InheritableSQLObject childName column in sqlmeta.columns Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() print j.Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} I think 'childName' should not be "listed" in sqlmeta.columns because it's a SQLObject "artifact" (just like 'id' column). This complicate automatic conversion from SQLObject to other types (like TurboJson's jsonify_sqlobject() function). ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2007-02-23 15:35 Message: Logged In: YES user_id=4799 Originator: NO Why is it a bug? It works as advertised. It is a real column, and it presents in .columns. In any case it would be so hard to fix, and fixing it gives so little advantage - I am not going to work on it. But I can test a patch if one appears. ---------------------------------------------------------------------- Comment By: Leandro Lucarella (llucax) Date: 2007-02-23 15:08 Message: Logged In: YES user_id=240225 Originator: YES Ok, it should be hard to fix, but don't you agree it's a bug? Shouldn't be emulated like the "id" column? It's not user data. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 22:41 Message: Logged In: YES user_id=4799 Originator: NO SQLObject emulates "id" columns. Unlike that fictional column childName is a real column. There is no way to remove it from .columns. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-23 12:12:31
|
Bugs item #1665328, was opened at 2007-02-21 12:36 Message generated for change (Comment added) made by llucax You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: childName column broken on leaf InheritableSQLObjects Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() class Derived(Base): derived = IntCol() Derived.createTable() class Derived2(Derived): _inheritable = False derived2 = IntCol() Derived2.createTable() Base(base=1) Derived(base=2, derived=2) Derived2(base=3, derived=3, derived2=3) print Base.get(1).childName # ok (None) print Base.get(2).childName # ok (None) print Base.get(3).childName Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1, in <lambda> File "sqlobject/main.py", line 987, in _SO_loadValue result = getattr(self, attrName) AttributeError: 'Derived2' object has no attribute '_SO_val_childName' Besides the bug, what's the idea of having a 'childName' attribute if it always return None? ---------------------------------------------------------------------- >Comment By: Leandro Lucarella (llucax) Date: 2007-02-23 09:12 Message: Logged In: YES user_id=240225 Originator: YES But it's listed into the sqlmeta.columns: print Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 16:50 Message: Logged In: YES user_id=4799 Originator: NO Oops, sorry, I reproduced the traceback. It is not a bug. You have disabled childName column by setting _inheritable = False. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 16:48 Message: Logged In: YES user_id=4799 Originator: NO I cannot reproduce the bug. The program print 3 None's for me. SQLObject 0.7.3. As for the None's... I have to think about it... ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-23 12:08:52
|
Bugs item #1665322, was opened at 2007-02-21 12:30 Message generated for change (Comment added) made by llucax You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Closed Resolution: Wont Fix Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: InheritableSQLObject childName column in sqlmeta.columns Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() print j.Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} I think 'childName' should not be "listed" in sqlmeta.columns because it's a SQLObject "artifact" (just like 'id' column). This complicate automatic conversion from SQLObject to other types (like TurboJson's jsonify_sqlobject() function). ---------------------------------------------------------------------- >Comment By: Leandro Lucarella (llucax) Date: 2007-02-23 09:08 Message: Logged In: YES user_id=240225 Originator: YES Ok, it should be hard to fix, but don't you agree it's a bug? Shouldn't be emulated like the "id" column? It's not user data. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 16:41 Message: Logged In: YES user_id=4799 Originator: NO SQLObject emulates "id" columns. Unlike that fictional column childName is a real column. There is no way to remove it from .columns. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-22 19:50:24
|
Bugs item #1665328, was opened at 2007-02-21 18:36 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: childName column broken on leaf InheritableSQLObjects Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() class Derived(Base): derived = IntCol() Derived.createTable() class Derived2(Derived): _inheritable = False derived2 = IntCol() Derived2.createTable() Base(base=1) Derived(base=2, derived=2) Derived2(base=3, derived=3, derived2=3) print Base.get(1).childName # ok (None) print Base.get(2).childName # ok (None) print Base.get(3).childName Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1, in <lambda> File "sqlobject/main.py", line 987, in _SO_loadValue result = getattr(self, attrName) AttributeError: 'Derived2' object has no attribute '_SO_val_childName' Besides the bug, what's the idea of having a 'childName' attribute if it always return None? ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2007-02-22 22:50 Message: Logged In: YES user_id=4799 Originator: NO Oops, sorry, I reproduced the traceback. It is not a bug. You have disabled childName column by setting _inheritable = False. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-22 22:48 Message: Logged In: YES user_id=4799 Originator: NO I cannot reproduce the bug. The program print 3 None's for me. SQLObject 0.7.3. As for the None's... I have to think about it... ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-22 19:48:16
|
Bugs item #1665328, was opened at 2007-02-21 18:36 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: childName column broken on leaf InheritableSQLObjects Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() class Derived(Base): derived = IntCol() Derived.createTable() class Derived2(Derived): _inheritable = False derived2 = IntCol() Derived2.createTable() Base(base=1) Derived(base=2, derived=2) Derived2(base=3, derived=3, derived2=3) print Base.get(1).childName # ok (None) print Base.get(2).childName # ok (None) print Base.get(3).childName Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1, in <lambda> File "sqlobject/main.py", line 987, in _SO_loadValue result = getattr(self, attrName) AttributeError: 'Derived2' object has no attribute '_SO_val_childName' Besides the bug, what's the idea of having a 'childName' attribute if it always return None? ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2007-02-22 22:48 Message: Logged In: YES user_id=4799 Originator: NO I cannot reproduce the bug. The program print 3 None's for me. SQLObject 0.7.3. As for the None's... I have to think about it... ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-22 19:43:17
|
Bugs item #1665322, was opened at 2007-02-21 18:30 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Wont Fix Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Oleg Broytmann (phd) Summary: InheritableSQLObject childName column in sqlmeta.columns Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() print j.Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} I think 'childName' should not be "listed" in sqlmeta.columns because it's a SQLObject "artifact" (just like 'id' column). This complicate automatic conversion from SQLObject to other types (like TurboJson's jsonify_sqlobject() function). ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2007-02-22 22:41 Message: Logged In: YES user_id=4799 Originator: NO SQLObject emulates "id" columns. Unlike that fictional column childName is a real column. There is no way to remove it from .columns. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-22 19:37:43
|
Bugs item #1665328, was opened at 2007-02-21 18:36 Message generated for change (Settings changed) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) >Assigned to: Oleg Broytmann (phd) Summary: childName column broken on leaf InheritableSQLObjects Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() class Derived(Base): derived = IntCol() Derived.createTable() class Derived2(Derived): _inheritable = False derived2 = IntCol() Derived2.createTable() Base(base=1) Derived(base=2, derived=2) Derived2(base=3, derived=3, derived2=3) print Base.get(1).childName # ok (None) print Base.get(2).childName # ok (None) print Base.get(3).childName Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1, in <lambda> File "sqlobject/main.py", line 987, in _SO_loadValue result = getattr(self, attrName) AttributeError: 'Derived2' object has no attribute '_SO_val_childName' Besides the bug, what's the idea of having a 'childName' attribute if it always return None? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665328&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-22 19:37:34
|
Bugs item #1665322, was opened at 2007-02-21 18:30 Message generated for change (Settings changed) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) >Assigned to: Oleg Broytmann (phd) Summary: InheritableSQLObject childName column in sqlmeta.columns Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() print j.Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} I think 'childName' should not be "listed" in sqlmeta.columns because it's a SQLObject "artifact" (just like 'id' column). This complicate automatic conversion from SQLObject to other types (like TurboJson's jsonify_sqlobject() function). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1665322&group_id=74338 |
|
From: <sub...@co...> - 2007-02-22 15:08:53
|
Author: phd
Date: 2007-02-22 08:08:41 -0700 (Thu, 22 Feb 2007)
New Revision: 2346
Modified:
home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py
Log:
Merged patches from the revisions 2343:2345 from the trunk
Modified: home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2007-02-22 15:05:54 UTC (rev 2345)
+++ home/phd/SQLObject/paramstyles/sqlobject/dbconnection.py 2007-02-22 15:08:41 UTC (rev 2346)
@@ -4,6 +4,7 @@
import threading
from util.threadinglocal import local as threading_local
+import sys
import re
import warnings
import atexit
@@ -32,15 +33,39 @@
if conn is not None:
conn.close()
+class ConsoleWriter:
+ def __init__(self, loglevel):
+ self.loglevel = loglevel
+ self.logfile = getattr(sys, loglevel or "stdout")
+ def write(self, text):
+ self.logfile.write(text + '\n')
+
+class LogWriter:
+ def __init__(self, logger, loglevel):
+ self.logger = logger
+ self.loglevel = loglevel
+ self.logmethod = getattr(logger, loglevel)
+ def write(self, text):
+ self.logmethod(text)
+
+def makeDebugWriter(loggerName, loglevel):
+ if not loggerName:
+ return ConsoleWriter(loglevel)
+ import logging
+ logger = logging.getLogger(loggerName)
+ return LogWriter(logger, loglevel)
+
class DBConnection:
def __init__(self, name=None, debug=False, debugOutput=False,
cache=True, style=None, autoCommit=True,
- debugThreading=False, registry=None):
+ debugThreading=False, registry=None,
+ logger=None, loglevel=None):
self.name = name
self.debug = debug
self.debugOutput = debugOutput
self.debugThreading = debugThreading
+ self.debugWriter = makeDebugWriter(logger, loglevel)
self.cache = CacheSet(cache=cache)
self.doCache = cache
self.style = style
@@ -301,7 +326,8 @@
threadName = (':' + threadName + ' '*(8-len(threadName)))
else:
threadName = ''
- print '%(n)2i%(threadName)s/%(name)s%(spaces)s%(sep)s %(s)s' % locals()
+ msg = '%(n)2i%(threadName)s/%(name)s%(spaces)s%(sep)s %(s)s' % locals()
+ self.debugWriter.write(msg)
def _executeRetry(self, conn, cursor, query):
if isinstance(query, str):
@@ -573,7 +599,7 @@
if isinstance(tableCreateSQLs, tuple):
tableCreateSQLs = list(tableCreateSQLs)
assert isinstance(tableCreateSQLs,list), (
- 'Unable to create a list from %s.sqlmeta.createSQL' %
+ 'Unable to create a list from %s.sqlmeta.createSQL' %
(soClass.__name__))
return tableCreateSQLs or []
Modified: home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py
===================================================================
--- home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py 2007-02-22 15:05:54 UTC (rev 2345)
+++ home/phd/SQLObject/paramstyles/sqlobject/tests/dbtest.py 2007-02-22 15:08:41 UTC (rev 2346)
@@ -10,6 +10,12 @@
import sqlobject
import sqlobject.conftest as conftest
+try:
+ import logging
+ loggingModuleAvailable = True
+except ImportError:
+ loggingModuleAvailable = False
+
if sys.platform[:3] == "win":
def getcwd():
return os.getcwd().replace(':', '|')
@@ -306,6 +312,17 @@
sqlobject.main.warnings_level = None
sqlobject.main.exception_level = 0
+def setupLogging():
+ if not loggingModuleAvailable:
+ return
+ fmt = '[%(asctime)s] %(name)s %(levelname)s: %(message)s'
+ formatter = logging.Formatter(fmt)
+ hdlr = logging.StreamHandler(sys.stderr)
+ hdlr.setFormatter(formatter)
+ hdlr.setLevel(logging.NOTSET)
+ logger = logging.getLogger()
+ logger.addHandler(hdlr)
+
__all__ = ['getConnection', 'getConnectionURI', 'setupClass', 'Dummy', 'raises',
'd', 'inserts', 'supports', 'deprecated_module',
- 'setup_module', 'teardown_module']
+ 'setup_module', 'teardown_module', 'setupLogging']
|
|
From: <sub...@co...> - 2007-02-22 15:06:14
|
Author: phd Date: 2007-02-22 08:05:54 -0700 (Thu, 22 Feb 2007) New Revision: 2345 Modified: SQLObject/docs/News.txt SQLObject/docs/SQLObject.txt Log: Use logging if it's available and is configured via DB URI. Modified: SQLObject/docs/News.txt =================================================================== --- SQLObject/docs/News.txt 2007-02-22 15:03:43 UTC (rev 2344) +++ SQLObject/docs/News.txt 2007-02-22 15:05:54 UTC (rev 2345) @@ -39,6 +39,8 @@ * MySQLConnection got new keyword "conv" - a list of custom converters. +* Use logging if it's available and is configured via DB URI. + Small Features -------------- Modified: SQLObject/docs/SQLObject.txt =================================================================== --- SQLObject/docs/SQLObject.txt 2007-02-22 15:03:43 UTC (rev 2344) +++ SQLObject/docs/SQLObject.txt 2007-02-22 15:05:54 UTC (rev 2345) @@ -161,7 +161,8 @@ Parameters are: ``debug`` (default: False), ``debugOutput`` (default: False), ``cache`` (default: True), ``autoCommit`` (default: True), -``debugThreading`` (default: False). +``debugThreading`` (default: False), +``logger`` (default: None), ``loglevel`` (default: None). If you want to pass True value in a connection URI - pass any non-empty string; an empty string for False. @@ -1523,6 +1524,16 @@ true, then any SQL sent to the database will also be printed to the console. +You can additionally pass `logger` keyword argument which should be a name +of the logger to use. If specified and `debug` is ``True``, SQLObject will +write debug print statements via that logger instead of printing directly +to console. Note that this options requires logging module which is +available starting from Python 2.3. The argument `loglevel` allows to +choose the logging level - it can be "debug", "info", "warning", "error", +"critical" or "exception". In case `logger` is empty or absent SQLObject +uses prints instead of logging; `loglevel` can be "stdout" or "stderr" in +this case; default is "stdout". + MySQL ----- |
|
From: SourceForge.net <no...@so...> - 2007-02-22 15:05:24
|
Patches item #1417339, was opened at 2006-01-28 14:51 Message generated for change (Comment added) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1417339&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Accepted Priority: 5 Private: No Submitted By: Maxim F. Ischenko (mfi) >Assigned to: Oleg Broytmann (phd) Summary: debug SQL queries recorded through logging module Initial Comment: The patch adds support for standard logging module for DBConnection classes which is crucial for using sqlobject in cgi scripts -- you can't use STDOUT because it is sent to the browser. Logging is activated if user specifies logger key, the key also serves as a logger name to be used. This is a duplicate of the previous ticket, only with a file attacheed (hope so). ---------------------------------------------------------------------- >Comment By: Oleg Broytmann (phd) Date: 2007-02-22 18:05 Message: Logged In: YES user_id=4799 Originator: NO It's finally applied to the trunk in the revision 2344. Thank you for the job and patience! I extended the patch and docs a bit - add 'loglevel'. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-03 22:02 Message: Logged In: YES user_id=4799 Can I remove setupLogging() from dbtest.py? PS. What's the problem with tests? ---------------------------------------------------------------------- Comment By: Maxim F. Ischenko (mfi) Date: 2006-02-03 19:52 Message: Logged In: YES user_id=113894 Oleg, I spent half an hour the other day trying to create/run a test but haven't succeed. So, no, I cannot provide a test. I you're not willing to submit the patch in the current form, well, so be it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-03 19:27 Message: Logged In: YES user_id=4799 I see you patch sqlobject/tests/dbtest.py but do not create any test. If it's not too hard can you also add a test that at least call setupLogging() and run a few SQL queries to make sure logging works. Even better - log to a file and test if the file contains what is expected. ---------------------------------------------------------------------- Comment By: Maxim F. Ischenko (mfi) Date: 2006-02-01 11:36 Message: Logged In: YES user_id=113894 Here is new patch ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-31 19:57 Message: Logged In: YES user_id=4799 Aha, that's better. Can you aslo add a test that sets up a logger (logging to a stderr or a separate file) and a patch for documentation (describe the "logger" keyword in a DB URI)? ---------------------------------------------------------------------- Comment By: Maxim F. Ischenko (mfi) Date: 2006-01-31 19:04 Message: Logged In: YES user_id=113894 Oleg, I was considered checking for logging module but then decided that if a person specifies 'logger' parameter to db connection then he should know what he's doing. If you insist, I can add some way of handling this error but please elaborate how exactly do you want me to handle it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-31 18:39 Message: Logged In: YES user_id=4799 Module logging is only available in Python 2.3. SQLObject is supposed to work with Python 2.2. You have to catch ImportError and provide a graceful fallback. After 0.8 I'd like to deprecate support for Python 2.2. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1417339&group_id=74338 |
|
From: <sub...@co...> - 2007-02-22 15:03:48
|
Author: phd
Date: 2007-02-22 08:03:43 -0700 (Thu, 22 Feb 2007)
New Revision: 2344
Modified:
SQLObject/trunk/sqlobject/dbconnection.py
SQLObject/trunk/sqlobject/tests/dbtest.py
Log:
A patch 1417339: debug SQL queries recorded through logging module.
Modified: SQLObject/trunk/sqlobject/dbconnection.py
===================================================================
--- SQLObject/trunk/sqlobject/dbconnection.py 2007-02-22 06:33:21 UTC (rev 2343)
+++ SQLObject/trunk/sqlobject/dbconnection.py 2007-02-22 15:03:43 UTC (rev 2344)
@@ -4,6 +4,7 @@
import threading
from util.threadinglocal import local as threading_local
+import sys
import re
import warnings
import atexit
@@ -31,15 +32,39 @@
if conn is not None:
conn.close()
+class ConsoleWriter:
+ def __init__(self, loglevel):
+ self.loglevel = loglevel
+ self.logfile = getattr(sys, loglevel or "stdout")
+ def write(self, text):
+ self.logfile.write(text + '\n')
+
+class LogWriter:
+ def __init__(self, logger, loglevel):
+ self.logger = logger
+ self.loglevel = loglevel
+ self.logmethod = getattr(logger, loglevel)
+ def write(self, text):
+ self.logmethod(text)
+
+def makeDebugWriter(loggerName, loglevel):
+ if not loggerName:
+ return ConsoleWriter(loglevel)
+ import logging
+ logger = logging.getLogger(loggerName)
+ return LogWriter(logger, loglevel)
+
class DBConnection:
def __init__(self, name=None, debug=False, debugOutput=False,
cache=True, style=None, autoCommit=True,
- debugThreading=False, registry=None):
+ debugThreading=False, registry=None,
+ logger=None, loglevel=None):
self.name = name
self.debug = debug
self.debugOutput = debugOutput
self.debugThreading = debugThreading
+ self.debugWriter = makeDebugWriter(logger, loglevel)
self.cache = CacheSet(cache=cache)
self.doCache = cache
self.style = style
@@ -300,7 +325,8 @@
threadName = (':' + threadName + ' '*(8-len(threadName)))
else:
threadName = ''
- print '%(n)2i%(threadName)s/%(name)s%(spaces)s%(sep)s %(s)s' % locals()
+ msg = '%(n)2i%(threadName)s/%(name)s%(spaces)s%(sep)s %(s)s' % locals()
+ self.debugWriter.write(msg)
def _executeRetry(self, conn, cursor, query):
if self.debug:
@@ -564,7 +590,7 @@
if isinstance(tableCreateSQLs, tuple):
tableCreateSQLs = list(tableCreateSQLs)
assert isinstance(tableCreateSQLs,list), (
- 'Unable to create a list from %s.sqlmeta.createSQL' %
+ 'Unable to create a list from %s.sqlmeta.createSQL' %
(soClass.__name__))
return tableCreateSQLs or []
Modified: SQLObject/trunk/sqlobject/tests/dbtest.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/dbtest.py 2007-02-22 06:33:21 UTC (rev 2343)
+++ SQLObject/trunk/sqlobject/tests/dbtest.py 2007-02-22 15:03:43 UTC (rev 2344)
@@ -10,6 +10,12 @@
import sqlobject
import sqlobject.conftest as conftest
+try:
+ import logging
+ loggingModuleAvailable = True
+except ImportError:
+ loggingModuleAvailable = False
+
if sys.platform[:3] == "win":
def getcwd():
return os.getcwd().replace(':', '|')
@@ -306,6 +312,17 @@
sqlobject.main.warnings_level = None
sqlobject.main.exception_level = 0
+def setupLogging():
+ if not loggingModuleAvailable:
+ return
+ fmt = '[%(asctime)s] %(name)s %(levelname)s: %(message)s'
+ formatter = logging.Formatter(fmt)
+ hdlr = logging.StreamHandler(sys.stderr)
+ hdlr.setFormatter(formatter)
+ hdlr.setLevel(logging.NOTSET)
+ logger = logging.getLogger()
+ logger.addHandler(hdlr)
+
__all__ = ['getConnection', 'getConnectionURI', 'setupClass', 'Dummy', 'raises',
'd', 'inserts', 'supports', 'deprecated_module',
- 'setup_module', 'teardown_module']
+ 'setup_module', 'teardown_module', 'setupLogging']
|
|
From: SourceForge.net <no...@so...> - 2007-02-22 14:01:15
|
Patches item #1353728, was opened at 2005-11-11 10:20 Message generated for change (Settings changed) made by phd You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None >Status: Closed >Resolution: Out of Date Priority: 5 Private: No Submitted By: Pau Aliagas (linux4u) Assigned to: Oleg Broytmann (phd) Summary: define foreign keys in Style Initial Comment: I don't like to use attrID all along the code to access related tables, I want to be able use the nomeclature I like taking advantage of the nice Style idea. This is especially true when you create RelatedJoins when you use a nomeclature like I do (table.id_table), but it's the same for all the nomeclatures you can imagine. In styles.py it warns: def instanceAttrToIDAttr(self, attr): # @@: Right now, because of how names are created for foreign # keys, you can't really change this style. return attr + "ID" With this patch you can define how you want the foreign keys generated, they won't be mandatorily generated as attrID. Example: class LongStyle(Style): """ This style is derived from Style, that does not do any translation, but constructs the table ids like id_table. """ def instanceAttrToIDAttr(self, attr): return "id_" + attr def tableReference(self, table): # str.rsplit is python 2.4+ only if version_info >= (2, 4): return "id_" + table.rsplit(".", 1)[-1] else: return "id_" + rsplit(table, ".", 1)[-1] class mm_server(SQLObject): class sqlmeta: table = "smsarena.mm_server" style = LongStyle(longID = True) _connection = conn_smsarena server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") tz = StringCol(length = 20, default = 'CET', notNone = True) conutry_code = StringCol(length = 2, varchar = False, default = '', notNone = True) # until now I had to do this # mm_server_aliases = SQLMultipleJoin("mm_server_alias", joinColumn = "mm_serverID", orderBy = "server") # now it's perfect! mm_server_aliases = SQLMultipleJoin("mm_server_alias", orderBy = "server") class mm_server_alias(SQLObject): class sqlmeta: table = "smsarena.mm_server_alias" style = LongStyle(longID = True) _connection = conn_smsarena # until now I had to do this # mm_server = ForeignKey("mm_server", dbName = "id_mm_server") mm_server = ForeignKey("mm_server") server = StringCol(alternateID = True, varchar = True, length = 255, alternateMethodName = "by_server") I hope it's clear :) Pau ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-20 17:54 Message: Logged In: YES user_id=4799 Doesn't work in 0.7. First, you've mixed tabs and spaces and used the name 's' instead of 'attr'. These two are easy to fix. But unpatched test_auto.py and test_auto_old.py fail: def test_dynamicJoin(self): col = KeyCol('oldPersonID', foreignKey='OldPerson') OldPhone.addColumn(col, changeSchema=True) join = MultipleJoin('OldPhone') OldPerson.addJoin(join) for phone in OldPhone.select('all'): if phone.phone.startswith('555'): phone.oldPerson = OldPerson.selectBy(name='tim')[0] else: phone.oldPerson = OldPerson.selectBy(name='bob')[0] l = [p.phone for p in OldPerson.selectBy(name='tim')[0].oldPhones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] You can work on it further. Or you can abandon it and it will not be applied in 0.7 branch. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 20:11 Message: Logged In: YES user_id=140558 Ok, this is the patch for keeping the exact behaviour in 0.7. For 0.7, as you say, don't patch the tests. Please do not apply it to 0.8 :) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:58 Message: Logged In: YES user_id=4799 Please do. I reopened the patch. Instead of one-line patch for Style IWBN to make a smaller (than the original) patch that avoids patching .addColumn() in tests, isn't it? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:39 Message: Logged In: YES user_id=140558 This can be solve with a onliner in default style: if not name.endswith("ID")... IMHO doing addColumn(fieldID, ForeignKey..) is a mistake You should do addColumn(field, ForeignKey..) and style takes care of it. If you want I can submit this oneliner for 0.7 only and you reconsider ading it to 0.7. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:29 Message: Logged In: YES user_id=4799 Even that's a big change, too big for 0.7 bugfix. Don't hesitate to post patches or at least bug reports for other issues. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 19:12 Message: Logged In: YES user_id=140558 Answering your concerns about the API... The only change is the one I have explained when using addColumn(fieldID, ForeignKey..). If you put ID, the current default style rules would add it too, so you'd get fieldIDID. We could change the style rules and look at this case, but I think that the current behaviour (as it is now with the patch) is completly orthogonal and always acts the same way, no black magic required. For the rest this is a HUGE addition!! You don't need to worry anymore about namning styles, nothing is written in stone. the ID thing was everywhere in the code Combined with the other patch (select using the object, not the id), you can almost always avoid referring directly to foreign field names. I really feel much more comfortable with these changes applied, seeign fieldID in the code maed me feel that something was not competely right. Avoiding it makes the code look beautiful. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 19:06 Message: Logged In: YES user_id=4799 SUM() should return whtaver the DB returns. I think summing an INT column returns an int, summing a FLOAT column returns a float. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:59 Message: Logged In: YES user_id=140558 Ok, another test mistery solved: This is the culprit that test_SQLMultipleJoin.py fails: assert str(hibrid.fightersAsSResult.sum('power')) == '23' In pgsql hibrid.fightersAsSResult.sum('power') returns 23. In sqlite-3.1.2 and mysql-4.1 it returns 23.0. So we should either fix the test or the sum function. Fixing the test could be as easy as casting the float to int: assert str(int(hibrid.fightersAsSResult.sum('power'))) == '23' but I'mn not sure if this would hide a bug. Should sum return float or int? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 18:55 Message: Logged In: YES user_id=4799 Yes, it works finally! Applied in the revision 1607. Thank you for the job! How much does it change the API? Does it have meaning to be applied to 0.7 branch? I actually applied it and it passed all tests, but I don't want to break API for 0.7.1. Will all old programs work? ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 18:49 Message: Logged In: YES user_id=140558 After fixing my patch (I'm sure it works now!!) I'm reviewing the tests that fail. See the attached file "failed tests 2006-01-17 version 1" for the tests an the detailed explanations. In summary: test_ForeignKey.py: you know about it, it fails in all the databases test_SQLMultipleJoin.py: I don't see why it fails, it fails in sqlite and mysql, not in pgsql * sqlite * my problem is that sqlite-3.1.2 does not support alter tabble ad column, so no problem. * mysql * test_datetime.py ---------------- to_python does not seem to work as expected. test_enum.py ------------ BLOB/TEXT column indexes require length in mysql I hope that this makes clear the current status. If you accept the current patch, maybe we could open another ticket with the current bugs in mysql and sqlite, as these are clearly separate issues. Thanks ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:26 Message: Logged In: YES user_id=140558 I've fixed the problems with addColumns and delColum, now it passes the tests (not the ones that fail I do not why). I've fixed the tests too: I think we should NOT add the columns with ID at the end as the style add it for you. Otherwise I should modify the sytle functions to conditionally check if they end in ID.... I don't think that it is ok, if we want that, we define anthjer style that removes double ID at the end. This is internal to the style and so should be kept. Hope it's ok now :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 16:01 Message: Logged In: YES user_id=140558 These are my versions (ignore my comment in the other patch ticket, my misake): mysql-4.1.16-1.FC4.1 postgresql-8.0.7-1.FC4.1 python-psycopg-1.1.21-1.fc4 python-sqlite-1.1.6-1 sqlite-3.1.2-3 ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 15:38 Message: Logged In: YES user_id=4799 Except for the problem i test_ForeignKey.py that I know about... others look pretty strange. Let look at the environment. What DB versions? MySQL, PgSQL, SQLite? Drivers versions? MySQLdb, psycopg, PySQLite? MyPostgres is 7.4, psycopg 1.1.21 and 2.0b5. PySQLite 1.1.7 and 2.1.3. A week ago I upgarded to SQLite 3.3.3 and PySQLite 2.1.3; that eliminated some minor problems with patches I have had with SQLIte 2.8.0 and PySQLite 2.1.0. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 15:11 Message: Logged In: YES user_id=140558 Ok, plain SQLObject from SVN now, no patch. There are tests that fail for me in current SQLObject in mysql, postgres and sqlite. I attach them all. This is a fully updated Fedora 4. I've made the tests in mysql and there are some thet do not pass. I enclose the results and a file where I comment why the fail and a possible solution. The tests that fail in postgres and sqlite are the ones I've already reported (mnore or less). Any help? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-17 12:22 Message: Logged In: YES user_id=4799 No, the latest SQLObject passes all tests (how would I commit your other patch if a test fail?) except for minor glitch in test_ForeignKey.py which I'm going to resolve RSN. test_auto.py certainly pass. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-17 12:13 Message: Logged In: YES user_id=140558 I've run the test with the latest SQLObject (no extra patches) and the tests fail too, at least they fail when I run them. As I explained before, there's something wrong when adding columns to sqlite, it fails and all the tests that depend on the added columns fail too. Does it happen to you too? ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-16 18:16 Message: Logged In: YES user_id=4799 These tests fail in both Postgres and SQLite. Two major backends (of 3) for SQLObject. If the problem is in tests you can patch tests, too... test_auto.py: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] > l = [p.phone for p in Person.selectBy(name='tim')[0].phones] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/test_auto.py:59] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > [failure to get at sourcelines from <TracebackEntry /home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1>] [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/tests/<string>:1] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def performJoin(self, inst): ids = inst._connection._SO_selectJoin( self.otherClass, self.joinColumn, > inst.id) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/joins.py:144] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _SO_selectJoin(self, soClass, column, value): return self.queryAll("SELECT %s FROM %s WHERE %s = %s" % (soClass.sqlmeta.idName, soClass.sqlmeta.table, column, > self.sqlrepr(value))) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:652] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def queryAll(self, s): > return self._runWithConnection(self._queryAll, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:327] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _runWithConnection(self, meth, *args): conn = self.getConnection() try: > val = meth(conn, *args) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:228] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _queryAll(self, conn, s): if self.debug: self.printDebug(conn, s, 'QueryAll') c = conn.cursor() > self._executeRetry(conn, c, s) [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:320] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _executeRetry(self, conn, cursor, query): if self.debug: self.printDebug(conn, query, 'QueryR') E return cursor.execute(query) > OperationalError: no such column: person_id [/home/phd/work/SQLObject/SQLObject-rlike/sqlobject/dbconnection.py:306] - - - - - - - - - - - test_dynamicJoin: recorded stdout - - - - - - - - - - - 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/Query : DELETE FROM person 1/QueryR : DELETE FROM person 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'person' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/Query : DELETE FROM phone 1/QueryR : DELETE FROM phone 1/COMMIT : auto 1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND tbl_name = 'phone' 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jane') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 1 1/QueryR : SELECT name_col FROM person WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('tim') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 2 1/QueryR : SELECT name_col FROM person WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('bob') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 3 1/QueryR : SELECT name_col FROM person WHERE id = 3 1/COMMIT : auto 1/QueryIns: INSERT INTO person (name_col) VALUES ('jake') 1/COMMIT : auto 1/QueryOne: SELECT name_col FROM person WHERE id = 4 1/QueryR : SELECT name_col FROM person WHERE id = 4 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-555-5555') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 1 1/QueryR : SELECT phone FROM phone WHERE id = 1 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('555-394-2930') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 2 1/QueryR : SELECT phone FROM phone WHERE id = 2 1/COMMIT : auto 1/QueryIns: INSERT INTO phone (phone) VALUES ('444-382-4854') 1/COMMIT : auto 1/QueryOne: SELECT phone FROM phone WHERE id = 3 1/QueryR : SELECT phone FROM phone WHERE id = 3 1/COMMIT : auto 1/Query : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/QueryR : ALTER TABLE phone ADD COLUMN person_i_d_id INT 1/COMMIT : auto 1/Select : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/QueryR : SELECT phone.id, phone.phone, phone.person_i_d_id FROM phone WHERE 1 = 1 ORDER BY phone 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'bob' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/Select : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/QueryR : SELECT person.id, person.name_col FROM person WHERE name_col = 'tim' ORDER BY name_col LIMIT 1 1/COMMIT : auto 1/QueryAll: SELECT id FROM phone WHERE person_id = 2 1/QueryR : SELECT id FROM phone WHERE person_id = 2 1/COMMIT : auto ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-15 18:54 Message: Logged In: YES user_id=140558 Ok, here I go again. I've fixed a small bug: the name of the field was not porperly set when using Key(foreignKey... instead of ForeignKey. This fixes test_basic. And I think that there is nothing else to fix, I'm probably wrong, but I'll explain it hera. test_auto_old.py... FAIL test_auto.py... FAIL test_foreignKey.py... FAIL These tests fail because sqlite is failing when adding columns. In mysql it does not fail. I do not think it's this patch fault. And finally: test_SQLMultipleJoin.py... FAIL E assert str(hibrid.fightersAsSResult.sum('power')) == '23' > assert '23.0' == '23' + where '23.0' = str(23.0) + where 23.0 = <Race 3 name="'hibrid (human wi...'">.fightersAsSResult.sum('power') Again this is an error in the test. Please let me know if it can go in now :) If you can have a quick look at it better, it takes time to restart ths tests, I'd rather do it before I move on to another thing. Thanks Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-14 12:05 Message: Logged In: YES user_id=140558 Oleg, I've posted to the list because I run the tests and pass. I'm sure I'm doing something wrong but I don't see what. I lost more than 3 hours yesterday just trying to run te tests :( I printed things in dbtest.py and say that TESTDB did not change anything. I chenged manually conftest.py because I ahd a message that yoiu need sqlite2 for memory databases, but still I'm not sure everything works becasue I pass al the tests. Can you help me, I want to close this patch soon and move to other improvements but this is being much more difficult than it should. Thanks a lot Pau ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-02-09 19:42 Message: Logged In: YES user_id=140558 I'm very busy but again will try to find some time to fix it. I'm using it every day without a glitch, even using the clause attributes like in the Complex example (new type of joins *toMany). I'll update it to latest SVN just in case this is the problem, I did it with that day's current. Please do not close it, I really intend to pass the tests, I'm already using it. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-02-09 19:11 Message: Logged In: YES user_id=4799 test_auto.py, for example fails: def test_dynamicJoin(self): col = KeyCol('personID', foreignKey='Person') Phone.sqlmeta.addColumn(col, changeSchema=True) join = MultipleJoin('Phone') Person.sqlmeta.addJoin(join) for phone in Phone.select('all'): if phone.phone.startswith('555'): phone.person = Person.selectBy(name='tim')[0] else: phone.person = Person.selectBy(name='bob')[0] l = [p.phone for p in Person.selectBy(name='tim')[0].phones] l.sort() E assert l == ['555-394-2930', '555-555-5555'] > assert [] == ['555-394-2930', '555-555-5555'] [sqlobject/tests/test_auto.py:61] ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:10 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-30 21:07 Message: Logged In: YES user_id=140558 I'll recheck it, it really passed all the tests applied to the latest svn. I tell you something tomorrow. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-30 20:57 Message: Logged In: YES user_id=4799 test_auto.py, test_auto_old.py and test_basic.py failed. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 19:04 Message: Logged In: YES user_id=140558 This is the final patch against latest svn, it includes everything in one single patch. It passes the tests. ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-18 16:17 Message: Logged In: YES user_id=140558 Ok, I have taken my time to understand pydist, test, etc, and here I am back with the working solution :) Now the resulting SQLobject passes all the tests. I attach an incremental patch so that you can see more clearly the changes done to fix the previous one. I've needed a new method in the Style class, instanceIDAttrToAttr, that is the complementary to the already known instanceAttrToIDAttr. If you need to transform back and forth field names, you need them both. I haven't tried to port it to the latest svn yet, this is against the same release than the first patch, but it should apply more or less clearly as this are very isolated areas in the code. When I do it I'll post it here. Sorry for the delay, it has not been easy for me to understand more deeply the code and, even less, to know how the tests work :) ---------------------------------------------------------------------- Comment By: Pau Aliagas (linux4u) Date: 2006-01-03 15:18 Message: Logged In: YES user_id=140558 It fails because the test is not right, it still has the ID postfix hardcoded. My fault, I did no send a patch for tests. This is the piece that fails: # Select by usual way s = TestWorkKey.selectBy(composerID=c.id, title='Symphony No. 9') I have not looked at tests until now, but it looks like there should be tests for the different provides styles, in this case, if you accept the patch, at least a test for the LongStyle provided and for the current naming styles. I'll try to cook up something, but it can take a little time. Any guidelines will be appreciated (I've just read the docs ;) ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2006-01-03 14:23 Message: Logged In: YES user_id=4799 test_selectBy_foreignKey.py fails: def test1(): setupClass([TestComposerKey, TestWorkKey]) c = TestComposerKey(name='Mahler, Gustav') > w1 = TestWorkKey(composer=c, title='Symphony No. 9') [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/tests/test_selectBy_foreignKey.py:19] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def __init__(self, **kw): # The get() classmethod/constructor uses a magic keyword # argument when it wants an empty object, fetched from the # database. So we have nothing more to do in that case: if kw.has_key('_SO_fetch_no_create'): return post_funcs = [] self.sqlmeta.send(events.RowCreateSignal, kw, post_funcs) # Pass the connection object along if we were given one. if kw.has_key('connection'): self._connection = kw['connection'] self.sqlmeta._perConnection = True del kw['connection'] self._SO_writeLock = threading.Lock() if kw.has_key('id'): id = self.sqlmeta.idType(kw['id']) del kw['id'] else: id = None > self._create(id, **kw) [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1210] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ def _create(self, id, **kw): self.sqlmeta._creating = True self._SO_createValues = {} self._SO_validatorState = SQLObjectState(self) # First we do a little fix-up on the keywords we were # passed: for column in self.sqlmeta.columnList: # Then we check if the column wasn't passed in, and # if not we try to get the default. if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default = column.default # If we don't get it, it's an error: if default is NoDefault: E raise TypeError, "%s() did not get expected keyword argument %s" % (self.__class__.__name__, column.name) > TypeError: TestWorkKey() did not get expected keyword argument composerID [/home/phd/work/SQLObject/SQLObject-patches/sqlobject/main.py:1231] - - - - - - - - - - - - - test1: recorded stdout - - - - - - - - - - - - - - 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_composer_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/QueryR : CREATE TABLE test_composer_key ( id SERIAL PRIMARY KEY, name TEXT ) 1/COMMIT : auto 1/QueryOne: SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/QueryR : SELECT COUNT(relname) FROM pg_class WHERE relname = 'test_work_key' 1/COMMIT : auto 1/Query : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/QueryR : CREATE TABLE test_work_key ( work_id SERIAL PRIMARY KEY, composer_id INT, title TEXT ) 1/COMMIT : auto 1/Query : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/QueryR : ALTER TABLE test_work_key ADD CONSTRAINT composer_id_exists FOREIGN KEY (composer_id) REFERENCES test_composer_key (id) 1/COMMIT : auto 1/QueryIns: INSERT INTO test_composer_key (id, name) VALUES (1, 'Mahler, Gustav') 1/COMMIT : auto 1/QueryOne: SELECT name FROM test_composer_key WHERE id = 1 1/QueryR : SELECT name FROM test_composer_key WHERE id = 1 1/COMMIT : auto ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1353728&group_id=74338 |
|
From: <sub...@co...> - 2007-02-21 21:57:45
|
Author: luke
Date: 2007-02-21 14:57:38 -0700 (Wed, 21 Feb 2007)
New Revision: 2341
Modified:
SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py
SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_views.py
SQLObject/branches/sqlbuilder-views/sqlobject/views.py
Log:
View alias-renaming using sqlmeta.table works in subclass situations now, and COUNT DISTINCT over views now sqlrepr's the id field
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py 2007-02-21 21:39:09 UTC (rev 2340)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py 2007-02-21 21:57:38 UTC (rev 2341)
@@ -211,9 +211,7 @@
# COUNT(DISTINCT column) is supported by MySQL and PostgreSQL,
# but not by SQLite. Perhaps more portable would be subquery:
# SELECT COUNT(*) FROM (SELECT DISTINCT id FROM table)
- count = self.accumulate('COUNT(DISTINCT %s.%s)' % (
- self.sourceClass.sqlmeta.table,
- self.sourceClass.sqlmeta.idName))
+ count = self.accumulate('COUNT(DISTINCT %s)' % self._getConnection().sqlrepr(self.sourceClass.q.id))
else:
count = self.accumulate('COUNT(*)')
if self.ops.get('start'):
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_views.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_views.py 2007-02-21 21:39:09 UTC (rev 2340)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_views.py 2007-02-21 21:57:38 UTC (rev 2341)
@@ -43,7 +43,10 @@
number = StringCol(dbName=ViewPhone.q.number)
timesCalled = IntCol(dbName=func.COUNT(PhoneCall.q.toID))
minutesCalled = IntCol(dbName=func.SUM(PhoneCall.q.minutes))
-
+
+class ViewPhoneMore2(ViewPhoneMore):
+ class sqlmeta:
+ table = 'vpm'
def setup_module(mod):
@@ -74,6 +77,9 @@
assert q.count('phone_call.minutes AS minutes')
assert q.count('phone_number.number AS number')
+def testAliasOverride():
+ assert str(sqlrepr(ViewPhoneMore2.q.id)) == 'vpm.id'
+
def checkAttr(cls, id, attr, value):
assert getattr(cls.get(id), attr) == value
@@ -109,4 +115,9 @@
def testSelect2():
s = ViewPhone.select(ViewPhone.q.number==phones[0].number)
- assert s.getOne().phoneNumber == phones[0]
\ No newline at end of file
+ assert s.getOne().phoneNumber == phones[0]
+
+def testDistinctCount():
+ # This test is for SelectResults non-* based count when distinct
+ # We're really just checking this doesn't raise anything due to lack of sqlrepr'ing
+ assert ViewPhone.select(distinct=True).count() == 2
\ No newline at end of file
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/views.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-21 21:39:09 UTC (rev 2340)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-21 21:57:38 UTC (rev 2341)
@@ -67,7 +67,7 @@
and sqlmeta should specify:
idName as a SQLBuilder construction
clause as SQLBuilder clause for specifying join conditions or other restrictions
- alias as an optional alternate name (as table is typically used for SQLObjects)
+ table as an optional alternate name for the class alias
See test_views.py for simple examples.
'''
@@ -78,7 +78,9 @@
SQLObject.__classinit__(cls, new_attrs)
# like is_base
if cls.__name__ != 'ViewSQLObject':
- if not getattr(cls.sqlmeta, 'alias', None):
+ if getattr(cls.sqlmeta, 'table', None):
+ cls.sqlmeta.alias = cls.sqlmeta.table
+ else:
cls.sqlmeta.alias = cls.sqlmeta.style.pythonClassToDBTable(cls.__name__)
alias = cls.sqlmeta.alias
columns = [ColumnAS(cls.sqlmeta.idName, 'id')]
|
|
From: <sub...@co...> - 2007-02-21 21:39:15
|
Author: luke
Date: 2007-02-21 14:39:09 -0700 (Wed, 21 Feb 2007)
New Revision: 2340
Modified:
SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py
Log:
SelectResults.throughTo use select's connection
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py 2007-02-21 21:26:44 UTC (rev 2339)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py 2007-02-21 21:39:09 UTC (rev 2340)
@@ -304,7 +304,8 @@
otherClass = getattr(self.sourceClass, "_SO_class_"+col.foreignKey)
query = sqlbuilder.Alias(self.queryForSelect(), "%s_%s" % (self.sourceClass.__name__, col.name))
return otherClass.select(otherClass.q.id==getattr(query.q, getattr(self.sourceClass.q, col.name).fieldName),
- distinct=True)
+ distinct=True,
+ connection=self._getConnection())
def _throughToMultipleJoin(self, join):
otherClass = join.otherClass
@@ -313,7 +314,8 @@
joinColumn = getattr(otherClass.q, join.soClass.sqlmeta.style.dbColumnToPythonAttr(join.joinColumn))
return otherClass.select(joinColumn == getattr(query.q, self.sourceClass.q.id.fieldName),
distinct=True,
- orderBy=join.orderBy)
+ orderBy=join.orderBy,
+ connection=self._getConnection())
def _throughToRelatedJoin(self, join):
otherClass = join.otherClass
@@ -326,7 +328,8 @@
getattr(intTable, join.joinColumn) == getattr(query.q, join.joinColumn))
ret = otherClass.select(clause,
distinct=True,
- orderBy=join.orderBy)
+ orderBy=join.orderBy,
+ connection=self._getConnection())
print ret
return ret
|
|
From: <sub...@co...> - 2007-02-21 21:26:49
|
Author: luke
Date: 2007-02-21 14:26:44 -0700 (Wed, 21 Feb 2007)
New Revision: 2339
Added:
SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_select_through.py
Modified:
SQLObject/branches/sqlbuilder-views/sqlobject/joins.py
SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py
Log:
SelectResults.throughTo
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/joins.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/joins.py 2007-02-21 20:29:27 UTC (rev 2338)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/joins.py 2007-02-21 21:26:44 UTC (rev 2339)
@@ -62,7 +62,7 @@
otherClass, self._setOtherClass)
self.joinColumn = joinColumn
self.joinMethodName = joinMethodName
- self.orderBy = orderBy
+ self._orderBy = orderBy
if not self.joinColumn:
# Here we set up the basic join, which is
# one-to-many, where the other class points to
@@ -70,6 +70,12 @@
self.joinColumn = styles.getStyle(
self.soClass).tableReference(self.soClass.sqlmeta.table)
+ def orderBy(self):
+ if self._orderBy is NoDefault:
+ self._orderBy = self.otherClass.sqlmeta.defaultOrder
+ return self._orderBy
+ orderBy = property(orderBy)
+
def _setOtherClass(self, cls):
self.otherClass = cls
@@ -77,8 +83,6 @@
return False
def _applyOrderBy(self, results, defaultSortClass):
- if self.orderBy is NoDefault:
- self.orderBy = defaultSortClass.sqlmeta.defaultOrder
if self.orderBy is not None:
results.sort(sorter(self.orderBy))
return results
@@ -159,8 +163,6 @@
else:
conn = None
results = self.otherClass.select(getattr(self.otherClass.q, self.soClass.sqlmeta.style.dbColumnToPythonAttr(self.joinColumn)) == inst.id, connection=conn)
- if self.orderBy is NoDefault:
- self.orderBy = self.otherClass.sqlmeta.defaultOrder
return results.orderBy(self.orderBy)
class SQLMultipleJoin(Join):
@@ -279,8 +281,6 @@
),
TableToId(self.soClass.sqlmeta.table, self.soClass.sqlmeta.idName, inst.id),
), clauseTables=(self.soClass.sqlmeta.table, self.otherClass.sqlmeta.table, self.intermediateTable))
- if self.orderBy is NoDefault:
- self.orderBy = self.otherClass.sqlmeta.defaultOrder
return results.orderBy(self.orderBy)
class SQLRelatedJoin(RelatedJoin):
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py 2007-02-21 20:29:27 UTC (rev 2338)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/sresults.py 2007-02-21 21:26:44 UTC (rev 2339)
@@ -1,6 +1,7 @@
import sqlbuilder
import dbconnection
import main
+import joins
StringType = type('')
@@ -281,4 +282,59 @@
% results)
return results[0]
+ def throughTo(self):
+ return _throughTo_getter(self)
+ throughTo = property(throughTo)
+
+ def _throughTo(self, attr):
+ ref = self.sourceClass.sqlmeta.columns.get(attr.endswith('ID') and attr or attr+'ID', None)
+ if ref and ref.foreignKey:
+ return self._throughToFK(ref)
+ else:
+ join = [x for x in self.sourceClass.sqlmeta.joins if x.joinMethodName==attr]
+ if join:
+ join = join[0]
+ if hasattr(join, 'otherColumn'):
+ return self._throughToRelatedJoin(join)
+ return self._throughToMultipleJoin(join)
+
+ raise AttributeError("throughTo argument (got %s) should be name of foreignKey or SQL*Join in %s" % (attr, self.sourceClass))
+
+ def _throughToFK(self, col):
+ otherClass = getattr(self.sourceClass, "_SO_class_"+col.foreignKey)
+ query = sqlbuilder.Alias(self.queryForSelect(), "%s_%s" % (self.sourceClass.__name__, col.name))
+ return otherClass.select(otherClass.q.id==getattr(query.q, getattr(self.sourceClass.q, col.name).fieldName),
+ distinct=True)
+
+ def _throughToMultipleJoin(self, join):
+ otherClass = join.otherClass
+ query = self.queryForSelect()
+ query = sqlbuilder.Alias(query, "%s_%s" % (self.sourceClass.__name__, join.joinMethodName))
+ joinColumn = getattr(otherClass.q, join.soClass.sqlmeta.style.dbColumnToPythonAttr(join.joinColumn))
+ return otherClass.select(joinColumn == getattr(query.q, self.sourceClass.q.id.fieldName),
+ distinct=True,
+ orderBy=join.orderBy)
+
+ def _throughToRelatedJoin(self, join):
+ otherClass = join.otherClass
+ intTable = sqlbuilder.Table(join.intermediateTable)
+ print join.joinColumn, join.otherColumn
+ query = self.queryForSelect().newItems([getattr(intTable, join.joinColumn)])
+ query = sqlbuilder.Alias(query, "%s_%s" % (self.sourceClass.__name__, join.joinMethodName))
+ print query
+ clause = sqlbuilder.AND(otherClass.q.id == getattr(intTable, join.otherColumn),
+ getattr(intTable, join.joinColumn) == getattr(query.q, join.joinColumn))
+ ret = otherClass.select(clause,
+ distinct=True,
+ orderBy=join.orderBy)
+ print ret
+ return ret
+
+
+class _throughTo_getter(object):
+ def __init__(self, inst):
+ self.sresult = inst
+ def __getattr__(self, attr):
+ return self.sresult._throughTo(attr)
+
__all__ = ['SelectResults']
Added: SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_select_through.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_select_through.py (rev 0)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_select_through.py 2007-02-21 21:26:44 UTC (rev 2339)
@@ -0,0 +1,53 @@
+from sqlobject import *
+from sqlobject.sqlbuilder import *
+from sqlobject.tests.dbtest import *
+
+''' Going to test that complex sqlbuilder constructions are never
+ prematurely stringified. A straight-forward approach is to use
+ Bools, since postgresql wants special formatting in queries.
+ The test is whether a call to sqlrepr(x, 'postgres') includes
+ the appropriate bool formatting throughout.
+'''
+
+class SRThrough1(SQLObject):
+ three = ForeignKey('SRThrough3')
+ twos = SQLMultipleJoin('SRThrough2', joinColumn='oneID')
+
+class SRThrough2(SQLObject):
+ one = ForeignKey('SRThrough1')
+ threes = SQLRelatedJoin('SRThrough3', addRemoveName='Three')
+
+class SRThrough3(SQLObject):
+ name = StringCol()
+ ones = SQLMultipleJoin('SRThrough1', joinColumn='threeID')
+ twos = SQLRelatedJoin('SRThrough2')
+
+
+def setup_module(mod):
+ setupClass([mod.SRThrough3, mod.SRThrough1, mod.SRThrough2])
+ threes = inserts(mod.SRThrough3,
+ [('a',),('b',),('c',)],
+ 'name')
+ ones = inserts(mod.SRThrough1,
+ [(threes[0].id,),(threes[0].id,),(threes[2].id,)],
+ 'threeID')
+ twos = inserts(mod.SRThrough2,
+ [(ones[0].id,),(ones[1].id,),(ones[2].id,)],
+ 'oneID')
+ twos[0].addThree(threes[0])
+ twos[0].addThree(threes[1])
+ mod.threes = threes
+ mod.twos = twos
+ mod.ones = ones
+
+def testThroughFK():
+ assert list(threes[0].ones.throughTo.three) == [threes[0]]
+
+def testThroughMultipleJoin():
+ assert list(threes[0].ones.throughTo.twos) == [twos[0], twos[1]]
+
+def testThroughRelatedJoin():
+ print [list(x.threes) for x in threes[0].twos]
+ assert list(threes[0].twos.throughTo.threes) == [threes[0], threes[1]]
+
+
\ No newline at end of file
|
|
From: SourceForge.net <no...@so...> - 2007-02-21 15:36:53
|
Patches item #1665328, was opened at 2007-02-21 12:36 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1665328&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Nobody/Anonymous (nobody) Summary: childName column broken on leaf InheritableSQLObjects Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() class Derived(Base): derived = IntCol() Derived.createTable() class Derived2(Derived): _inheritable = False derived2 = IntCol() Derived2.createTable() Base(base=1) Derived(base=2, derived=2) Derived2(base=3, derived=3, derived2=3) print Base.get(1).childName # ok (None) print Base.get(2).childName # ok (None) print Base.get(3).childName Traceback (most recent call last): File "<stdin>", line 1, in ? File "<string>", line 1, in <lambda> File "sqlobject/main.py", line 987, in _SO_loadValue result = getattr(self, attrName) AttributeError: 'Derived2' object has no attribute '_SO_val_childName' Besides the bug, what's the idea of having a 'childName' attribute if it always return None? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1665328&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-02-21 15:30:51
|
Patches item #1665322, was opened at 2007-02-21 12:30 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1665322&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Leandro Lucarella (llucax) Assigned to: Nobody/Anonymous (nobody) Summary: InheritableSQLObject childName column in sqlmeta.columns Initial Comment: from sqlobject import * from sqlobject.inheritance import InheritableSQLObject __connection__ = 'sqlite:///:memory:' class Base(InheritableSQLObject): base = IntCol() Base.createTable() print j.Base.sqlmeta.columns {'base': <SOIntCol base>, 'childName': <SOStringCol childName default=None>} I think 'childName' should not be "listed" in sqlmeta.columns because it's a SQLObject "artifact" (just like 'id' column). This complicate automatic conversion from SQLObject to other types (like TurboJson's jsonify_sqlobject() function). ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540674&aid=1665322&group_id=74338 |
|
From: <sub...@co...> - 2007-02-21 15:24:53
|
Author: luke
Date: 2007-02-21 08:24:43 -0700 (Wed, 21 Feb 2007)
New Revision: 2337
Modified:
SQLObject/branches/sqlbuilder-views/sqlobject/include/
SQLObject/branches/sqlbuilder-views/sqlobject/include/pydispatch/
SQLObject/branches/sqlbuilder-views/sqlobject/inheritance/
SQLObject/branches/sqlbuilder-views/sqlobject/inheritance/__init__.py
SQLObject/branches/sqlbuilder-views/sqlobject/inheritance/tests/
SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py
SQLObject/branches/sqlbuilder-views/sqlobject/tests/
SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_sqlbuilder_importproxy.py
SQLObject/branches/sqlbuilder-views/sqlobject/util/
SQLObject/branches/sqlbuilder-views/sqlobject/versioning/
SQLObject/branches/sqlbuilder-views/sqlobject/versioning/test/
SQLObject/branches/sqlbuilder-views/sqlobject/views.py
Log:
ImportProxy inside aliases
Property changes on: SQLObject/branches/sqlbuilder-views/sqlobject/include
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
*~
Property changes on: SQLObject/branches/sqlbuilder-views/sqlobject/include/pydispatch
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
*~
Property changes on: SQLObject/branches/sqlbuilder-views/sqlobject/inheritance
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
*~
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/inheritance/__init__.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/inheritance/__init__.py 2007-02-21 06:23:02 UTC (rev 2336)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/inheritance/__init__.py 2007-02-21 15:24:43 UTC (rev 2337)
@@ -13,13 +13,13 @@
basestring = (types.StringType, types.UnicodeType)
-def tablesUsedDict(obj):
+def tablesUsedDict(obj, db):
if hasattr(obj, "tablesUsedDict"):
- return obj.tablesUsedDict()
+ return obj.tablesUsedDict(db)
elif isinstance(obj, (tuple, list)):
d = {}
for component in obj:
- d.update(tablesUsedDict(component))
+ d.update(tablesUsedDict(component, db))
return d
else:
return {}
@@ -35,14 +35,14 @@
dbName = (ops.get('connection',None) or sourceClass._connection).dbName
- tablesDict = sqlbuilder.tablesUsedDict(clause, dbName)
+ tablesDict = tablesUsedDict(clause, dbName)
tablesDict[sourceClass.sqlmeta.table] = 1
orderBy = ops.get('orderBy')
if inheritedTables:
for tableName in inheritedTables:
tablesDict[tableName] = 1
if orderBy and not isinstance(orderBy, basestring):
- tablesDict.update(sqlbuilder.tablesUsedDict(orderBy, dbName))
+ tablesDict.update(tablesUsedDict(orderBy, dbName))
#DSM: if this class has a parent, we need to link it
#DSM: and be sure the parent is in the table list.
#DSM: The following code is before clauseTables
Property changes on: SQLObject/branches/sqlbuilder-views/sqlobject/inheritance/tests
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
*~
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py 2007-02-21 06:23:02 UTC (rev 2336)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py 2007-02-21 15:24:43 UTC (rev 2337)
@@ -416,7 +416,10 @@
self.aliasTable = aliasTable
def __sqlrepr__(self, db):
- return self.alias + "." + self.fieldName
+ fieldName = self.fieldName
+ if isinstance(fieldName, SQLExpression):
+ fieldName = sqlrepr(fieldName, db)
+ return self.alias + "." + fieldName
def tablesUsedImmediate(self):
return [self.aliasTable]
@@ -1146,10 +1149,14 @@
FieldClass = ImportProxyField
def __init__(self, clsName, registry=None):
self.tableName = _DelayClass(self, clsName)
+ self.sqlmeta = _Delay_proxy(table=_DelayClass(self, clsName))
self.q = self
self.soClass = None
classregistry.registry(registry).addClassCallback(clsName,lambda foreign, me: setattr(me, 'soClass', foreign), self)
+ def __nonzero__(self):
+ return True
+
def __getattr__(self, attr):
if self.soClass is None:
return _Delay(self, attr)
@@ -1163,15 +1170,32 @@
def __sqlrepr__(self, db):
if self.proxy.soClass is None:
return '_DELAYED_' + self.attr
- return sqlrepr(self._resolve(), db)
+ val = self._resolve()
+ if isinstance(val, SQLExpression):
+ val = sqlrepr(val, db)
+ return val
def _resolve(self):
return getattr(self.proxy, self.attr)
+
+ # For AliasTable etc
+ def fieldName(self):
+ class _aliasFieldName(SQLExpression):
+ def __init__(self, proxy):
+ self.proxy = proxy
+ def __sqlrepr__(self, db):
+ return self.proxy._resolve().fieldName
+ return _aliasFieldName(self)
+ fieldName = property(fieldName)
class _DelayClass(_Delay):
def _resolve(self):
return self.proxy.soClass.sqlmeta.table
+class _Delay_proxy(object):
+ def __init__(self, **kw):
+ self.__dict__.update(kw)
+
######
Property changes on: SQLObject/branches/sqlbuilder-views/sqlobject/tests
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
*~
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_sqlbuilder_importproxy.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_sqlbuilder_importproxy.py 2007-02-21 06:23:02 UTC (rev 2336)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_sqlbuilder_importproxy.py 2007-02-21 15:24:43 UTC (rev 2337)
@@ -1,7 +1,7 @@
from sqlobject import *
from sqlobject.tests.dbtest import *
from sqlobject.views import *
-from sqlobject.sqlbuilder import ImportProxy
+from sqlobject.sqlbuilder import ImportProxy, Alias
def testSimple():
nyi = ImportProxy('NotYetImported')
@@ -36,4 +36,16 @@
idName = NotYetImported3.q.id
name = StringCol(dbName=NotYetImported3.q.name)
- assert str(x) == 'not_yet_imported_v.name'
\ No newline at end of file
+ assert str(x) == 'not_yet_imported_v.name'
+
+def testAlias():
+ nyi = ImportProxy('NotYetImported4')
+ y = Alias(nyi, 'y')
+ x = y.q.name
+
+ class NotYetImported4(SQLObject):
+ name = StringCol(dbName='a_name')
+
+ assert str(y) == 'not_yet_imported4 y'
+ assert tablesUsedDict(x, None).keys() == ['not_yet_imported4 y']
+ assert str(x) == 'y.a_name'
\ No newline at end of file
Property changes on: SQLObject/branches/sqlbuilder-views/sqlobject/util
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
*~
Property changes on: SQLObject/branches/sqlbuilder-views/sqlobject/versioning
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
*~
Property changes on: SQLObject/branches/sqlbuilder-views/sqlobject/versioning/test
___________________________________________________________________
Name: svn:ignore
+ *.pyc
*.pyo
*~
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/views.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-21 06:23:02 UTC (rev 2336)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-21 15:24:43 UTC (rev 2337)
@@ -89,10 +89,12 @@
else:
columns.append(ColumnAS(col.dbName, n))
+ metajoin = getattr(cls.sqlmeta, 'join', NoDefault)
clause = getattr(cls.sqlmeta, 'clause', NoDefault)
select = Select(columns,
distinct=True,
distinctOn=cls.sqlmeta.idName,
+ join=metajoin,
clause=clause)
if aggregates:
@@ -110,6 +112,7 @@
new_alias = Alias(
Select([ColumnAS(cls.sqlmeta.idName, agg_id), agg],
groupBy=cls.sqlmeta.idName,
+ join=metajoin,
clause=clause),
agg_alias)
agg_join = LEFTJOINOn(last,
|
|
From: <sub...@co...> - 2007-02-20 17:45:45
|
Author: luke
Date: 2007-02-20 10:45:05 -0700 (Tue, 20 Feb 2007)
New Revision: 2332
Modified:
SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py
SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_sqlbuilder_importproxy.py
SQLObject/branches/sqlbuilder-views/sqlobject/views.py
Log:
Cleaner ImportProxy, ViewSQLObjectMeta start
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py 2007-02-20 17:17:27 UTC (rev 2331)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/sqlbuilder.py 2007-02-20 17:45:05 UTC (rev 2332)
@@ -1139,7 +1139,7 @@
def tablesUsedImmediate(self):
return [str(self.tableName)]
-class ImportProxy(SQLObjectTable):
+class ImportProxy(SQLExpression):
'''Class to be used in column definitions that rely on other tables that might
not yet be in a classregistry.
'''
@@ -1153,7 +1153,7 @@
def __getattr__(self, attr):
if self.soClass is None:
return _Delay(self, attr)
- return SQLObjectTable.__getattr__(self, attr)
+ return getattr(self.soClass.q, attr)
class _Delay(SQLExpression):
def __init__(self, proxy, attr):
@@ -1163,11 +1163,8 @@
def __sqlrepr__(self, db):
if self.proxy.soClass is None:
return '_DELAYED_' + self.attr
- return str(self._resolve())
+ return sqlrepr(self._resolve(), db)
- def __add__(self, other):
- return str(self) + other
-
def _resolve(self):
return getattr(self.proxy, self.attr)
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_sqlbuilder_importproxy.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_sqlbuilder_importproxy.py 2007-02-20 17:17:27 UTC (rev 2331)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/tests/test_sqlbuilder_importproxy.py 2007-02-20 17:45:05 UTC (rev 2332)
@@ -1,5 +1,6 @@
from sqlobject import *
from sqlobject.tests.dbtest import *
+from sqlobject.views import *
from sqlobject.sqlbuilder import ImportProxy
def testSimple():
@@ -9,4 +10,30 @@
class NotYetImported(SQLObject):
name = StringCol(dbName='a_name')
- assert str(x) == 'not_yet_imported.a_name'
\ No newline at end of file
+ y = nyi.q.name
+
+ assert str(x) == 'not_yet_imported.a_name'
+ assert str(y) == 'not_yet_imported.a_name'
+
+def testAddition():
+ nyi = ImportProxy('NotYetImported2')
+ x = nyi.q.name+nyi.q.name
+
+ class NotYetImported2(SQLObject):
+ name = StringCol(dbName='a_name')
+
+ assert str(x) == '((not_yet_imported2.a_name) + (not_yet_imported2.a_name))'
+
+def testOnView():
+ nyi = ImportProxy('NotYetImportedV')
+ x = nyi.q.name
+
+ class NotYetImported3(SQLObject):
+ name = StringCol(dbName='a_name')
+
+ class NotYetImportedV(ViewSQLObject):
+ class sqlmeta:
+ idName = NotYetImported3.q.id
+ name = StringCol(dbName=NotYetImported3.q.name)
+
+ assert str(x) == 'not_yet_imported_v.name'
\ No newline at end of file
Modified: SQLObject/branches/sqlbuilder-views/sqlobject/views.py
===================================================================
--- SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-20 17:17:27 UTC (rev 2331)
+++ SQLObject/branches/sqlbuilder-views/sqlobject/views.py 2007-02-20 17:45:05 UTC (rev 2332)
@@ -4,7 +4,7 @@
#from SQLObject import SQLObject
#from sqlobject.col import Col, KeyCol
from sqlbuilder import *
-from main import SQLObject
+from main import SQLObject, sqlmeta
import types, threading
@@ -57,6 +57,10 @@
else:
return self.FieldClass(alias, self.tableName, column.name, attr)
+class ViewSQLObjectMeta(sqlmeta):
+ pass
+
+
class ViewSQLObject(SQLObject):
'''A SQLObject class that derives all it's values from other SQLObject classes.
Columns on subclasses should use SQLBuilder constructs for dbName,
@@ -66,6 +70,10 @@
alias as an optional alternate name (as table is typically used for SQLObjects)
See test_views.py for simple examples.
'''
+
+ class sqlmeta(ViewSQLObjectMeta):
+ pass
+
def __classinit__(cls, new_attrs):
SQLObject.__classinit__(cls, new_attrs)
# like is_base
@@ -81,7 +89,7 @@
else:
columns.append(ColumnAS(col.dbName, n))
- clause = cls.sqlmeta.clause
+ clause = getattr(cls.sqlmeta, 'clause', NoDefault)
select = Select(columns,
distinct=True,
distinctOn=cls.sqlmeta.idName,
|
|
From: SourceForge.net <no...@so...> - 2007-02-20 17:01:27
|
Bugs item #1663785, was opened at 2007-02-19 21:49 Message generated for change (Comment added) made by dado1945 You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1663785&group_id=74338 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: MySQL Group: SQLObject from repository Status: Open Resolution: Accepted Priority: 5 Private: No Submitted By: dado1945 (dado1945) Assigned to: Oleg Broytmann (phd) Summary: ADD CONSTRAINT fails Initial Comment: Environment: Windows, MySql 5.0, SQLObject from svn Description: (1) It seems SQLObject creates tables alphabetically and adds constraints after creation of each table. It might happen that required table is not created yet for constraint. It is interesting that "sql sql" shows that constraints will be added after all tables are created. (2) Another problem is that foreign key and id has different types (INT and INT UNSIGNED). Because of those two problems constrain creation fails. E.g. this query: ALTER TABLE blog ADD CONSTRAINT blog_language_id_exists FOREIGN KEY (language_id) REFERENCES language (id) gives following error: sqlobject.dberrors.OperationalError: Can't create table '.\tp\#sql-1b8_35.frm' (errno: 150) (1) This problem might be solved by changing line 590 in file sqlobject\manager\command.py: tableConstraints = soClass.createTable() to: tableConstraints = soClass.createTable(applyConstraints=False) I guess the same fix is required by line 583. (2) I think foreign key type must be changed to UNSIGNED INT but I have not found part where to do that. Because of that I just removed UNSIGNED from sqlobject\mysql\mysqlconnection.py line 172. That's not the best fix but the fastest one I have found. Note: I guess this problem might exist for some other databases as well. ---------------------------------------------------------------------- >Comment By: dado1945 (dado1945) Date: 2007-02-20 19:01 Message: Logged In: YES user_id=1533929 Originator: YES 1. Thanks :) 2. I don't think it must be UNSIGNED. I think foreign key must have the same type as id. Let's take your example and change a little bit. I have added UNSIGNED to parent id: CREATE TABLE parent(id INT UNSIGNED NOT NULL, PRIMARY KEY (id) ) TYPE=INNODB; CREATE TABLE child(id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE ) TYPE=INNODB; Now child.parent_id and parent.id has different types (even if both are 32 bits). That's not good behavior and that's happens in SQLObject's MySQL case. parent.id will always be UNSIGNED INT (sqlobject\mysql\mysqlconnection.py line 172) and foreign key will be INT (I don't know where it comes from). ADD CONSTRAIN seems to check if types are equal and fails. ---------------------------------------------------------------------- Comment By: Oleg Broytmann (phd) Date: 2007-02-20 17:58 Message: Logged In: YES user_id=4799 Originator: NO 1. Fixed in the SVN, revision 2329. 2. In the MySQL Reference Manual there is an example: CREATE TABLE parent(id INT NOT NULL, PRIMARY KEY (id) ) TYPE=INNODB; CREATE TABLE child(id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE ) TYPE=INNODB; So it seems a foreign keys have no obligation to be UNSIGNED. Why do you think they *must* be UNSIGNED? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1663785&group_id=74338 |