sqlobject-cvs Mailing List for SQLObject (Page 92)
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-05-03 09:29:08
|
Author: phd
Date: 2007-05-03 03:29:02 -0600 (Thu, 03 May 2007)
New Revision: 2633
Modified:
SQLObject/docs/News.txt
Log:
Minor correction.
Modified: SQLObject/docs/News.txt
===================================================================
--- SQLObject/docs/News.txt 2007-05-03 09:28:13 UTC (rev 2632)
+++ SQLObject/docs/News.txt 2007-05-03 09:29:02 UTC (rev 2633)
@@ -216,7 +216,7 @@
their parameter must be a string; now you can pass an SQLExpression:
Table.q.name.contains(func.upper('a')), for example.
-* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
+* Fixed a longstanding bug in sqlbuilder.Select() with groupBy being a
sequence.
* Fixed a bug with Aliases in JOINs.
|
|
From: <sub...@co...> - 2007-05-03 09:28:20
|
Author: phd
Date: 2007-05-03 03:28:13 -0600 (Thu, 03 May 2007)
New Revision: 2632
Modified:
SQLObject/branches/0.9/docs/News.txt
Log:
Minor correction.
Modified: SQLObject/branches/0.9/docs/News.txt
===================================================================
--- SQLObject/branches/0.9/docs/News.txt 2007-05-03 09:27:38 UTC (rev 2631)
+++ SQLObject/branches/0.9/docs/News.txt 2007-05-03 09:28:13 UTC (rev 2632)
@@ -213,7 +213,7 @@
their parameter must be a string; now you can pass an SQLExpression:
Table.q.name.contains(func.upper('a')), for example.
-* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
+* Fixed a longstanding bug in sqlbuilder.Select() with groupBy being a
sequence.
* Fixed a bug with Aliases in JOINs.
|
|
From: <sub...@co...> - 2007-05-03 09:28:05
|
Author: phd
Date: 2007-05-03 03:27:38 -0600 (Thu, 03 May 2007)
New Revision: 2631
Modified:
SQLObject/branches/0.8/docs/News.txt
Log:
Minor correction.
Modified: SQLObject/branches/0.8/docs/News.txt
===================================================================
--- SQLObject/branches/0.8/docs/News.txt 2007-05-03 09:27:09 UTC (rev 2630)
+++ SQLObject/branches/0.8/docs/News.txt 2007-05-03 09:27:38 UTC (rev 2631)
@@ -158,7 +158,7 @@
their parameter must be a string; now you can pass an SQLExpression:
Table.q.name.contains(func.upper('a')), for example.
-* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
+* Fixed a longstanding bug in sqlbuilder.Select() with groupBy being a
sequence.
* Fixed a bug with Aliases in JOINs.
|
|
From: <sub...@co...> - 2007-05-03 09:27:29
|
Author: phd
Date: 2007-05-03 03:27:09 -0600 (Thu, 03 May 2007)
New Revision: 2630
Modified:
SQLObject/branches/0.7/docs/News.txt
Log:
Minor correction.
Modified: SQLObject/branches/0.7/docs/News.txt
===================================================================
--- SQLObject/branches/0.7/docs/News.txt 2007-05-02 18:03:03 UTC (rev 2629)
+++ SQLObject/branches/0.7/docs/News.txt 2007-05-03 09:27:09 UTC (rev 2630)
@@ -21,7 +21,7 @@
their parameter must be a string; now you can pass an SQLExpression:
Table.q.name.contains(func.upper('a')), for example.
-* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
+* Fixed a longstanding bug in sqlbuilder.Select() with groupBy being a
sequence.
* Fixed a bug with Aliases in JOINs.
|
|
From: <sub...@co...> - 2007-05-02 18:03:08
|
Author: phd
Date: 2007-05-02 12:03:03 -0600 (Wed, 02 May 2007)
New Revision: 2629
Modified:
SQLObject/trunk/sqlobject/sqlbuilder.py
Log:
Removed trailing spaces.
Modified: SQLObject/trunk/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/trunk/sqlobject/sqlbuilder.py 2007-05-02 18:02:29 UTC (rev 2628)
+++ SQLObject/trunk/sqlobject/sqlbuilder.py 2007-05-02 18:03:03 UTC (rev 2629)
@@ -398,7 +398,7 @@
def _getattrFromID(self, attr):
return self.FieldClass(self.tableName, self.soClass.sqlmeta.idName, attr)
-
+
def _getattrFromForeignKey(self, column, attr):
ret = getattr(self, column.name)==getattr(self.soClass, '_SO_class_'+column.foreignKey).q.id
print column
@@ -851,7 +851,7 @@
''' Just like SQLOp('AS', expr, name) except without the parentheses '''
def __init__(self, expr, name):
if isinstance(name, (str, unicode)):
- name = SQLConstant(name)
+ name = SQLConstant(name)
SQLOp.__init__(self, 'AS', expr, name)
def __sqlrepr__(self, db):
return "%s %s %s" % (sqlrepr(self.expr1, db), self.op, sqlrepr(self.expr2, db))
|
|
From: <sub...@co...> - 2007-05-02 18:02:33
|
Author: phd
Date: 2007-05-02 12:02:29 -0600 (Wed, 02 May 2007)
New Revision: 2628
Modified:
SQLObject/trunk/sqlobject/tests/test_aliases.py
Log:
Added a test for aliases in JOINs.
Modified: SQLObject/trunk/sqlobject/tests/test_aliases.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_aliases.py 2007-05-02 18:01:53 UTC (rev 2627)
+++ SQLObject/trunk/sqlobject/tests/test_aliases.py 2007-05-02 18:02:29 UTC (rev 2628)
@@ -11,12 +11,11 @@
parent = StringCol()
def test_1syntax():
- return # DEPRECATED this test because table ordering in FROM clause is not stable.
setupClass(JoinAlias)
alias = Alias(JoinAlias)
select = JoinAlias.select(JoinAlias.q.parent == alias.q.name)
assert str(select) == \
- "SELECT join_alias.id, join_alias.name, join_alias.parent FROM join_alias join_alias_alias1, join_alias WHERE ((join_alias.parent) = (join_alias_alias1.name))"
+ "SELECT join_alias.id, join_alias.name, join_alias.parent FROM join_alias, join_alias join_alias_alias1 WHERE ((join_alias.parent) = (join_alias_alias1.name))"
def test_2perform_join():
setupClass(JoinAlias)
@@ -26,3 +25,12 @@
alias = Alias(JoinAlias)
select = JoinAlias.select(JoinAlias.q.parent == alias.q.name)
assert select.count() == 2
+
+def test_3joins():
+ setupClass(JoinAlias)
+ alias = Alias(JoinAlias)
+ select = JoinAlias.select((JoinAlias.q.name == 'a') & (alias.q.name == 'b'),
+ join=LEFTJOINOn(None, alias, alias.q.name == 'c')
+ )
+ assert str(select) == \
+ "SELECT join_alias.id, join_alias.name, join_alias.parent FROM join_alias LEFT JOIN join_alias join_alias_alias3 ON ((join_alias_alias3.name) = ('c')) WHERE (((join_alias.name) = ('a')) AND ((join_alias_alias3.name) = ('b')))"
|
|
From: <sub...@co...> - 2007-05-02 18:01:56
|
Author: phd Date: 2007-05-02 12:01:53 -0600 (Wed, 02 May 2007) New Revision: 2627 Modified: SQLObject/docs/News.txt Log: Fixed a bug with Aliases in JOINs. Modified: SQLObject/docs/News.txt =================================================================== --- SQLObject/docs/News.txt 2007-05-02 18:01:36 UTC (rev 2626) +++ SQLObject/docs/News.txt 2007-05-02 18:01:53 UTC (rev 2627) @@ -208,8 +208,6 @@ Bug Fixes --------- -* Fixed a minor comparison problem in test_decimal.py. - * Fixed a longstanding bug with .select() ignoring 'limit' parameter. * Fixed a bug with absent comma in JOINs. @@ -221,8 +219,12 @@ * Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a sequence. +* Fixed a bug with Aliases in JOINs. + * Yet another patch to properly initialize MySQL connection encoding. +* Fixed a minor comparison problem in test_decimal.py. + * More documentation about orderBy. SQLObject 0.7.5 |
|
From: <sub...@co...> - 2007-05-02 18:01:54
|
Author: phd
Date: 2007-05-02 12:01:36 -0600 (Wed, 02 May 2007)
New Revision: 2626
Modified:
SQLObject/branches/0.9/docs/News.txt
SQLObject/branches/0.9/sqlobject/sqlbuilder.py
SQLObject/branches/0.9/sqlobject/tests/test_aliases.py
Log:
Fixed a bug with Aliases in JOINs.
Modified: SQLObject/branches/0.9/docs/News.txt
===================================================================
--- SQLObject/branches/0.9/docs/News.txt 2007-05-02 18:01:17 UTC (rev 2625)
+++ SQLObject/branches/0.9/docs/News.txt 2007-05-02 18:01:36 UTC (rev 2626)
@@ -205,8 +205,6 @@
Bug Fixes
---------
-* Fixed a minor comparison problem in test_decimal.py.
-
* Fixed a longstanding bug with .select() ignoring 'limit' parameter.
* Fixed a bug with absent comma in JOINs.
@@ -218,8 +216,12 @@
* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
sequence.
+* Fixed a bug with Aliases in JOINs.
+
* Yet another patch to properly initialize MySQL connection encoding.
+* Fixed a minor comparison problem in test_decimal.py.
+
* More documentation about orderBy.
SQLObject 0.7.5
Modified: SQLObject/branches/0.9/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/0.9/sqlobject/sqlbuilder.py 2007-05-02 18:01:17 UTC (rev 2625)
+++ SQLObject/branches/0.9/sqlobject/sqlbuilder.py 2007-05-02 18:01:36 UTC (rev 2626)
@@ -742,12 +742,12 @@
def __init__(self, table1, table2, op=','):
if table1 and type(table1) <> str:
if isinstance(table1, Alias):
- table1 = "%s AS %s" % (table1.q.tableName, table1.q.alias)
+ table1 = "%s %s %s" % (table1.q.tableName, AliasField.as_string, table1.q.alias)
else:
table1 = table1.sqlmeta.table
if type(table2) <> str:
if isinstance(table2, Alias):
- table2 = "%s AS %s" % (table2.q.tableName, table2.q.alias)
+ table2 = "%s %s %s" % (table2.q.tableName, AliasField.as_string, table2.q.alias)
else:
table2 = table2.sqlmeta.table
self.table1 = table1
Modified: SQLObject/branches/0.9/sqlobject/tests/test_aliases.py
===================================================================
--- SQLObject/branches/0.9/sqlobject/tests/test_aliases.py 2007-05-02 18:01:17 UTC (rev 2625)
+++ SQLObject/branches/0.9/sqlobject/tests/test_aliases.py 2007-05-02 18:01:36 UTC (rev 2626)
@@ -25,3 +25,12 @@
alias = Alias(JoinAlias)
select = JoinAlias.select(JoinAlias.q.parent == alias.q.name)
assert select.count() == 2
+
+def test_3joins():
+ setupClass(JoinAlias)
+ alias = Alias(JoinAlias)
+ select = JoinAlias.select((JoinAlias.q.name == 'a') & (alias.q.name == 'b'),
+ join=LEFTJOINOn(None, alias, alias.q.name == 'c')
+ )
+ assert str(select) == \
+ "SELECT join_alias.id, join_alias.name, join_alias.parent FROM join_alias LEFT JOIN join_alias join_alias_alias3 ON ((join_alias_alias3.name) = ('c')) WHERE (((join_alias.name) = ('a')) AND ((join_alias_alias3.name) = ('b')))"
|
|
From: <sub...@co...> - 2007-05-02 18:01:23
|
Author: phd
Date: 2007-05-02 12:01:17 -0600 (Wed, 02 May 2007)
New Revision: 2625
Modified:
SQLObject/branches/0.8/docs/News.txt
SQLObject/branches/0.8/sqlobject/sqlbuilder.py
SQLObject/branches/0.8/sqlobject/tests/test_aliases.py
Log:
Fixed a bug with Aliases in JOINs.
Modified: SQLObject/branches/0.8/docs/News.txt
===================================================================
--- SQLObject/branches/0.8/docs/News.txt 2007-05-02 18:00:53 UTC (rev 2624)
+++ SQLObject/branches/0.8/docs/News.txt 2007-05-02 18:01:17 UTC (rev 2625)
@@ -150,8 +150,6 @@
Bug Fixes
---------
-* Fixed a minor comparison problem in test_decimal.py.
-
* Fixed a longstanding bug with .select() ignoring 'limit' parameter.
* Fixed a bug with absent comma in JOINs.
@@ -163,8 +161,12 @@
* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
sequence.
+* Fixed a bug with Aliases in JOINs.
+
* Yet another patch to properly initialize MySQL connection encoding.
+* Fixed a minor comparison problem in test_decimal.py.
+
* More documentation about orderBy.
SQLObject 0.7.5
Modified: SQLObject/branches/0.8/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/0.8/sqlobject/sqlbuilder.py 2007-05-02 18:00:53 UTC (rev 2624)
+++ SQLObject/branches/0.8/sqlobject/sqlbuilder.py 2007-05-02 18:01:17 UTC (rev 2625)
@@ -740,12 +740,12 @@
def __init__(self, table1, table2, op=','):
if table1 and type(table1) <> str:
if isinstance(table1, Alias):
- table1 = "%s AS %s" % (table1.q.tableName, table1.q.alias)
+ table1 = "%s %s %s" % (table1.q.tableName, AliasField.as_string, table1.q.alias)
else:
table1 = table1.sqlmeta.table
if type(table2) <> str:
if isinstance(table2, Alias):
- table2 = "%s AS %s" % (table2.q.tableName, table2.q.alias)
+ table2 = "%s %s %s" % (table2.q.tableName, AliasField.as_string, table2.q.alias)
else:
table2 = table2.sqlmeta.table
self.table1 = table1
Modified: SQLObject/branches/0.8/sqlobject/tests/test_aliases.py
===================================================================
--- SQLObject/branches/0.8/sqlobject/tests/test_aliases.py 2007-05-02 18:00:53 UTC (rev 2624)
+++ SQLObject/branches/0.8/sqlobject/tests/test_aliases.py 2007-05-02 18:01:17 UTC (rev 2625)
@@ -25,3 +25,12 @@
alias = Alias(JoinAlias)
select = JoinAlias.select(JoinAlias.q.parent == alias.q.name)
assert select.count() == 2
+
+def test_3joins():
+ setupClass(JoinAlias)
+ alias = Alias(JoinAlias)
+ select = JoinAlias.select((JoinAlias.q.name == 'a') & (alias.q.name == 'b'),
+ join=LEFTJOINOn(None, alias, alias.q.name == 'c')
+ )
+ assert str(select) == \
+ "SELECT join_alias.id, join_alias.name, join_alias.parent FROM join_alias LEFT JOIN join_alias join_alias_alias3 ON ((join_alias_alias3.name) = ('c')) WHERE (((join_alias.name) = ('a')) AND ((join_alias_alias3.name) = ('b')))"
|
|
From: <sub...@co...> - 2007-05-02 18:00:59
|
Author: phd
Date: 2007-05-02 12:00:53 -0600 (Wed, 02 May 2007)
New Revision: 2624
Modified:
SQLObject/branches/0.7/docs/News.txt
SQLObject/branches/0.7/sqlobject/sqlbuilder.py
SQLObject/branches/0.7/sqlobject/tests/test_aliases.py
Log:
Fixed a bug with Aliases in JOINs.
Modified: SQLObject/branches/0.7/docs/News.txt
===================================================================
--- SQLObject/branches/0.7/docs/News.txt 2007-05-02 14:54:19 UTC (rev 2623)
+++ SQLObject/branches/0.7/docs/News.txt 2007-05-02 18:00:53 UTC (rev 2624)
@@ -13,8 +13,6 @@
Bug Fixes
---------
-* Fixed a minor comparison problem in test_decimal.py.
-
* Fixed a longstanding bug with .select() ignoring 'limit' parameter.
* Fixed a bug with absent comma in JOINs.
@@ -26,8 +24,12 @@
* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
sequence.
+* Fixed a bug with Aliases in JOINs.
+
* Yet another patch to properly initialize MySQL connection encoding.
+* Fixed a minor comparison problem in test_decimal.py.
+
* More documentation about orderBy.
SQLObject 0.7.5
Modified: SQLObject/branches/0.7/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/sqlbuilder.py 2007-05-02 14:54:19 UTC (rev 2623)
+++ SQLObject/branches/0.7/sqlobject/sqlbuilder.py 2007-05-02 18:00:53 UTC (rev 2624)
@@ -733,12 +733,12 @@
def __init__(self, table1, table2, op=','):
if table1 and type(table1) <> str:
if isinstance(table1, Alias):
- table1 = "%s AS %s" % (table1.q.tableName, table1.q.alias)
+ table1 = "%s %s %s" % (table1.q.tableName, AliasField.as_string, table1.q.alias)
else:
table1 = table1.sqlmeta.table
if type(table2) <> str:
if isinstance(table2, Alias):
- table2 = "%s AS %s" % (table2.q.tableName, table2.q.alias)
+ table2 = "%s %s %s" % (table2.q.tableName, AliasField.as_string, table2.q.alias)
else:
table2 = table2.sqlmeta.table
self.table1 = table1
Modified: SQLObject/branches/0.7/sqlobject/tests/test_aliases.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/tests/test_aliases.py 2007-05-02 14:54:19 UTC (rev 2623)
+++ SQLObject/branches/0.7/sqlobject/tests/test_aliases.py 2007-05-02 18:00:53 UTC (rev 2624)
@@ -25,3 +25,12 @@
alias = Alias(JoinAlias)
select = JoinAlias.select(JoinAlias.q.parent == alias.q.name)
assert select.count() == 2
+
+def test_3joins():
+ setupClass(JoinAlias)
+ alias = Alias(JoinAlias)
+ select = JoinAlias.select((JoinAlias.q.name == 'a') & (alias.q.name == 'b'),
+ join=LEFTJOINOn(None, alias, alias.q.name == 'c')
+ )
+ assert str(select) == \
+ "SELECT join_alias.id, join_alias.name, join_alias.parent FROM join_alias LEFT JOIN join_alias join_alias_alias3 ON ((join_alias_alias3.name) = ('c')) WHERE (((join_alias.name) = ('a')) AND ((join_alias_alias3.name) = ('b')))"
|
|
From: <sub...@co...> - 2007-05-02 14:54:25
|
Author: phd
Date: 2007-05-02 08:54:19 -0600 (Wed, 02 May 2007)
New Revision: 2623
Modified:
SQLObject/docs/News.txt
Log:
Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a sequence.
Modified: SQLObject/docs/News.txt
===================================================================
--- SQLObject/docs/News.txt 2007-05-02 14:53:50 UTC (rev 2622)
+++ SQLObject/docs/News.txt 2007-05-02 14:54:19 UTC (rev 2623)
@@ -218,6 +218,9 @@
their parameter must be a string; now you can pass an SQLExpression:
Table.q.name.contains(func.upper('a')), for example.
+* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
+ sequence.
+
* Yet another patch to properly initialize MySQL connection encoding.
* More documentation about orderBy.
|
|
From: <sub...@co...> - 2007-05-02 14:53:58
|
Author: phd
Date: 2007-05-02 08:53:50 -0600 (Wed, 02 May 2007)
New Revision: 2622
Added:
SQLObject/trunk/sqlobject/tests/test_groupBy.py
Modified:
SQLObject/trunk/sqlobject/sqlbuilder.py
Log:
Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a sequence.
Modified: SQLObject/trunk/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/trunk/sqlobject/sqlbuilder.py 2007-05-02 14:53:17 UTC (rev 2621)
+++ SQLObject/trunk/sqlobject/sqlbuilder.py 2007-05-02 14:53:50 UTC (rev 2622)
@@ -651,7 +651,10 @@
if self.ops['clause'] is not NoDefault:
select += " WHERE %s" % sqlrepr(self.ops['clause'], db)
if self.ops['groupBy'] is not NoDefault:
- select += " GROUP BY %s" % sqlrepr(self.ops['groupBy'], db)
+ groupBy = sqlrepr(self.ops['groupBy'], db)
+ if isinstance(self.ops['groupBy'], (list, tuple)):
+ groupBy = groupBy[1:-1] # Remove parens
+ select += " GROUP BY %s" % groupBy
if self.ops['having'] is not NoDefault:
select += " HAVING %s" % sqlrepr(self.ops['having'], db)
if self.ops['orderBy'] is not NoDefault and self.ops['orderBy'] is not None:
Added: SQLObject/trunk/sqlobject/tests/test_groupBy.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_groupBy.py (rev 0)
+++ SQLObject/trunk/sqlobject/tests/test_groupBy.py 2007-05-02 14:53:50 UTC (rev 2622)
@@ -0,0 +1,39 @@
+from sqlobject import *
+from sqlobject.sqlbuilder import Select, func
+from sqlobject.tests.dbtest import *
+
+########################################
+## groupBy
+########################################
+
+class GroupbyTest(SQLObject):
+ name = StringCol()
+ value = IntCol()
+
+def test_groupBy():
+ setupClass(GroupbyTest)
+ GroupbyTest(name='a', value=1)
+ GroupbyTest(name='a', value=2)
+ GroupbyTest(name='b', value=1)
+
+ connection = getConnection()
+ select = Select([GroupbyTest.q.name, func.COUNT(GroupbyTest.q.value)],
+ groupBy=GroupbyTest.q.name,
+ orderBy=GroupbyTest.q.name)
+ sql = connection.sqlrepr(select)
+ rows = connection.queryAll(sql)
+ assert rows == [('a', 2), ('b', 1)]
+
+def test_groupBy_list():
+ setupClass(GroupbyTest)
+ GroupbyTest(name='a', value=1)
+ GroupbyTest(name='a', value=2)
+ GroupbyTest(name='b', value=1)
+
+ connection = getConnection()
+ select = Select([GroupbyTest.q.name, GroupbyTest.q.value],
+ groupBy=[GroupbyTest.q.name, GroupbyTest.q.value],
+ orderBy=[GroupbyTest.q.name, GroupbyTest.q.value])
+ sql = connection.sqlrepr(select)
+ rows = connection.queryAll(sql)
+ assert rows == [('a', 1), ('a', 2), ('b', 1)]
|
|
From: <sub...@co...> - 2007-05-02 14:53:22
|
Author: phd
Date: 2007-05-02 08:53:17 -0600 (Wed, 02 May 2007)
New Revision: 2621
Added:
SQLObject/branches/0.9/sqlobject/tests/test_groupBy.py
Modified:
SQLObject/branches/0.9/docs/News.txt
SQLObject/branches/0.9/sqlobject/sqlbuilder.py
Log:
Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a sequence.
Modified: SQLObject/branches/0.9/docs/News.txt
===================================================================
--- SQLObject/branches/0.9/docs/News.txt 2007-05-02 14:52:46 UTC (rev 2620)
+++ SQLObject/branches/0.9/docs/News.txt 2007-05-02 14:53:17 UTC (rev 2621)
@@ -215,6 +215,9 @@
their parameter must be a string; now you can pass an SQLExpression:
Table.q.name.contains(func.upper('a')), for example.
+* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
+ sequence.
+
* Yet another patch to properly initialize MySQL connection encoding.
* More documentation about orderBy.
Modified: SQLObject/branches/0.9/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/0.9/sqlobject/sqlbuilder.py 2007-05-02 14:52:46 UTC (rev 2620)
+++ SQLObject/branches/0.9/sqlobject/sqlbuilder.py 2007-05-02 14:53:17 UTC (rev 2621)
@@ -505,11 +505,17 @@
if self.whereClause is not NoDefault:
select += " WHERE %s" % sqlrepr(self.whereClause, db)
if self.groupBy is not NoDefault:
- select += " GROUP BY %s" % sqlrepr(self.groupBy, db)
+ groupBy = sqlrepr(self.groupBy, db)
+ if isinstance(self.groupBy, list) or isinstance(self.groupBy, tuple):
+ groupBy = groupBy[1:-1] # Remove parens
+ select += " GROUP BY %s" % groupBy
if self.having is not NoDefault:
select += " HAVING %s" % sqlrepr(self.having, db)
if self.orderBy is not NoDefault:
- select += " ORDER BY %s" % sqlrepr(self.orderBy, db)
+ orderBy = sqlrepr(self.orderBy, db)
+ if isinstance(self.orderBy, list) or isinstance(self.orderBy, tuple):
+ orderBy = orderBy[1:-1] # Remove parens
+ select += " ORDER BY %s" % orderBy
if self.limit is not NoDefault:
select += " LIMIT %s" % sqlrepr(self.limit, db)
return select
Added: SQLObject/branches/0.9/sqlobject/tests/test_groupBy.py
===================================================================
--- SQLObject/branches/0.9/sqlobject/tests/test_groupBy.py (rev 0)
+++ SQLObject/branches/0.9/sqlobject/tests/test_groupBy.py 2007-05-02 14:53:17 UTC (rev 2621)
@@ -0,0 +1,39 @@
+from sqlobject import *
+from sqlobject.sqlbuilder import Select, func
+from sqlobject.tests.dbtest import *
+
+########################################
+## groupBy
+########################################
+
+class GroupbyTest(SQLObject):
+ name = StringCol()
+ value = IntCol()
+
+def test_groupBy():
+ setupClass(GroupbyTest)
+ GroupbyTest(name='a', value=1)
+ GroupbyTest(name='a', value=2)
+ GroupbyTest(name='b', value=1)
+
+ connection = getConnection()
+ select = Select([GroupbyTest.q.name, func.COUNT(GroupbyTest.q.value)],
+ groupBy=GroupbyTest.q.name,
+ orderBy=GroupbyTest.q.name)
+ sql = connection.sqlrepr(select)
+ rows = connection.queryAll(sql)
+ assert rows == [('a', 2), ('b', 1)]
+
+def test_groupBy_list():
+ setupClass(GroupbyTest)
+ GroupbyTest(name='a', value=1)
+ GroupbyTest(name='a', value=2)
+ GroupbyTest(name='b', value=1)
+
+ connection = getConnection()
+ select = Select([GroupbyTest.q.name, GroupbyTest.q.value],
+ groupBy=[GroupbyTest.q.name, GroupbyTest.q.value],
+ orderBy=[GroupbyTest.q.name, GroupbyTest.q.value])
+ sql = connection.sqlrepr(select)
+ rows = connection.queryAll(sql)
+ assert rows == [('a', 1), ('a', 2), ('b', 1)]
|
|
From: <sub...@co...> - 2007-05-02 14:52:49
|
Author: phd
Date: 2007-05-02 08:52:46 -0600 (Wed, 02 May 2007)
New Revision: 2620
Added:
SQLObject/branches/0.8/sqlobject/tests/test_groupBy.py
Modified:
SQLObject/branches/0.8/docs/News.txt
SQLObject/branches/0.8/sqlobject/sqlbuilder.py
Log:
Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a sequence.
Modified: SQLObject/branches/0.8/docs/News.txt
===================================================================
--- SQLObject/branches/0.8/docs/News.txt 2007-05-02 14:52:17 UTC (rev 2619)
+++ SQLObject/branches/0.8/docs/News.txt 2007-05-02 14:52:46 UTC (rev 2620)
@@ -160,6 +160,9 @@
their parameter must be a string; now you can pass an SQLExpression:
Table.q.name.contains(func.upper('a')), for example.
+* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
+ sequence.
+
* Yet another patch to properly initialize MySQL connection encoding.
* More documentation about orderBy.
Modified: SQLObject/branches/0.8/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/0.8/sqlobject/sqlbuilder.py 2007-05-02 14:52:17 UTC (rev 2619)
+++ SQLObject/branches/0.8/sqlobject/sqlbuilder.py 2007-05-02 14:52:46 UTC (rev 2620)
@@ -505,11 +505,17 @@
if self.whereClause is not NoDefault:
select += " WHERE %s" % sqlrepr(self.whereClause, db)
if self.groupBy is not NoDefault:
- select += " GROUP BY %s" % sqlrepr(self.groupBy, db)
+ groupBy = sqlrepr(self.groupBy, db)
+ if isinstance(self.groupBy, list) or isinstance(self.groupBy, tuple):
+ groupBy = groupBy[1:-1] # Remove parens
+ select += " GROUP BY %s" % groupBy
if self.having is not NoDefault:
select += " HAVING %s" % sqlrepr(self.having, db)
if self.orderBy is not NoDefault:
- select += " ORDER BY %s" % sqlrepr(self.orderBy, db)
+ orderBy = sqlrepr(self.orderBy, db)
+ if isinstance(self.orderBy, list) or isinstance(self.orderBy, tuple):
+ orderBy = orderBy[1:-1] # Remove parens
+ select += " ORDER BY %s" % orderBy
if self.limit is not NoDefault:
select += " LIMIT %s" % sqlrepr(self.limit, db)
return select
Added: SQLObject/branches/0.8/sqlobject/tests/test_groupBy.py
===================================================================
--- SQLObject/branches/0.8/sqlobject/tests/test_groupBy.py (rev 0)
+++ SQLObject/branches/0.8/sqlobject/tests/test_groupBy.py 2007-05-02 14:52:46 UTC (rev 2620)
@@ -0,0 +1,39 @@
+from sqlobject import *
+from sqlobject.sqlbuilder import Select, func
+from sqlobject.tests.dbtest import *
+
+########################################
+## groupBy
+########################################
+
+class GroupbyTest(SQLObject):
+ name = StringCol()
+ value = IntCol()
+
+def test_groupBy():
+ setupClass(GroupbyTest)
+ GroupbyTest(name='a', value=1)
+ GroupbyTest(name='a', value=2)
+ GroupbyTest(name='b', value=1)
+
+ connection = getConnection()
+ select = Select([GroupbyTest.q.name, func.COUNT(GroupbyTest.q.value)],
+ groupBy=GroupbyTest.q.name,
+ orderBy=GroupbyTest.q.name)
+ sql = connection.sqlrepr(select)
+ rows = connection.queryAll(sql)
+ assert rows == [('a', 2), ('b', 1)]
+
+def test_groupBy_list():
+ setupClass(GroupbyTest)
+ GroupbyTest(name='a', value=1)
+ GroupbyTest(name='a', value=2)
+ GroupbyTest(name='b', value=1)
+
+ connection = getConnection()
+ select = Select([GroupbyTest.q.name, GroupbyTest.q.value],
+ groupBy=[GroupbyTest.q.name, GroupbyTest.q.value],
+ orderBy=[GroupbyTest.q.name, GroupbyTest.q.value])
+ sql = connection.sqlrepr(select)
+ rows = connection.queryAll(sql)
+ assert rows == [('a', 1), ('a', 2), ('b', 1)]
|
|
From: <sub...@co...> - 2007-05-02 14:52:23
|
Author: phd
Date: 2007-05-02 08:52:17 -0600 (Wed, 02 May 2007)
New Revision: 2619
Added:
SQLObject/branches/0.7/sqlobject/tests/test_groupBy.py
Modified:
SQLObject/branches/0.7/docs/News.txt
SQLObject/branches/0.7/sqlobject/sqlbuilder.py
Log:
Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a sequence.
Modified: SQLObject/branches/0.7/docs/News.txt
===================================================================
--- SQLObject/branches/0.7/docs/News.txt 2007-05-01 21:44:37 UTC (rev 2618)
+++ SQLObject/branches/0.7/docs/News.txt 2007-05-02 14:52:17 UTC (rev 2619)
@@ -23,6 +23,9 @@
their parameter must be a string; now you can pass an SQLExpression:
Table.q.name.contains(func.upper('a')), for example.
+* Fixed a longstanding bug with sqlbuilder.Select() with groupBy being a
+ sequence.
+
* Yet another patch to properly initialize MySQL connection encoding.
* More documentation about orderBy.
Modified: SQLObject/branches/0.7/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/sqlbuilder.py 2007-05-01 21:44:37 UTC (rev 2618)
+++ SQLObject/branches/0.7/sqlobject/sqlbuilder.py 2007-05-02 14:52:17 UTC (rev 2619)
@@ -502,11 +502,17 @@
if self.whereClause is not NoDefault:
select += " WHERE %s" % sqlrepr(self.whereClause, db)
if self.groupBy is not NoDefault:
- select += " GROUP BY %s" % sqlrepr(self.groupBy, db)
+ groupBy = sqlrepr(self.groupBy, db)
+ if isinstance(self.groupBy, list) or isinstance(self.groupBy, tuple):
+ groupBy = groupBy[1:-1] # Remove parens
+ select += " GROUP BY %s" % groupBy
if self.having is not NoDefault:
select += " HAVING %s" % sqlrepr(self.having, db)
if self.orderBy is not NoDefault:
- select += " ORDER BY %s" % sqlrepr(self.orderBy, db)
+ orderBy = sqlrepr(self.orderBy, db)
+ if isinstance(self.orderBy, list) or isinstance(self.orderBy, tuple):
+ orderBy = orderBy[1:-1] # Remove parens
+ select += " ORDER BY %s" % orderBy
if self.limit is not NoDefault:
select += " LIMIT %s" % sqlrepr(self.limit, db)
return select
Added: SQLObject/branches/0.7/sqlobject/tests/test_groupBy.py
===================================================================
--- SQLObject/branches/0.7/sqlobject/tests/test_groupBy.py (rev 0)
+++ SQLObject/branches/0.7/sqlobject/tests/test_groupBy.py 2007-05-02 14:52:17 UTC (rev 2619)
@@ -0,0 +1,39 @@
+from sqlobject import *
+from sqlobject.sqlbuilder import Select, func
+from sqlobject.tests.dbtest import *
+
+########################################
+## groupBy
+########################################
+
+class GroupbyTest(SQLObject):
+ name = StringCol()
+ value = IntCol()
+
+def test_groupBy():
+ setupClass(GroupbyTest)
+ GroupbyTest(name='a', value=1)
+ GroupbyTest(name='a', value=2)
+ GroupbyTest(name='b', value=1)
+
+ connection = getConnection()
+ select = Select([GroupbyTest.q.name, func.COUNT(GroupbyTest.q.value)],
+ groupBy=GroupbyTest.q.name,
+ orderBy=GroupbyTest.q.name)
+ sql = connection.sqlrepr(select)
+ rows = connection.queryAll(sql)
+ assert rows == [('a', 2), ('b', 1)]
+
+def test_groupBy_list():
+ setupClass(GroupbyTest)
+ GroupbyTest(name='a', value=1)
+ GroupbyTest(name='a', value=2)
+ GroupbyTest(name='b', value=1)
+
+ connection = getConnection()
+ select = Select([GroupbyTest.q.name, GroupbyTest.q.value],
+ groupBy=[GroupbyTest.q.name, GroupbyTest.q.value],
+ orderBy=[GroupbyTest.q.name, GroupbyTest.q.value])
+ sql = connection.sqlrepr(select)
+ rows = connection.queryAll(sql)
+ assert rows == [('a', 1), ('a', 2), ('b', 1)]
|
|
From: <sub...@co...> - 2007-05-01 01:50:45
|
Author: luke
Date: 2007-04-30 19:50:42 -0600 (Mon, 30 Apr 2007)
New Revision: 2616
Added:
SQLObject/trunk/sqlobject/tests/test_sqlbuilder_joins_instances.py
Modified:
SQLObject/trunk/sqlobject/main.py
SQLObject/trunk/sqlobject/sqlbuilder.py
SQLObject/trunk/sqlobject/tests/test_select_through.py
SQLObject/trunk/sqlobject/views.py
Log:
Merged fixes from branches/cache-deps-on-views for sresults.throughTo and joins/instances as .q. expressions
Modified: SQLObject/trunk/sqlobject/main.py
===================================================================
--- SQLObject/trunk/sqlobject/main.py 2007-05-01 01:35:15 UTC (rev 2615)
+++ SQLObject/trunk/sqlobject/main.py 2007-05-01 01:50:42 UTC (rev 2616)
@@ -1615,7 +1615,13 @@
cls._connection = value
setConnection = classmethod(setConnection)
+ def __sqlrepr__(self, db):
+ return sqlbuilder.sqlrepr(self.__class__.q.id==self.id)
+
+ def tablesUsedImmediate(self):
+ return [self.__class__.q]
+
def capitalize(name):
return name[0].capitalize() + name[1:]
Modified: SQLObject/trunk/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/trunk/sqlobject/sqlbuilder.py 2007-05-01 01:35:15 UTC (rev 2615)
+++ SQLObject/trunk/sqlobject/sqlbuilder.py 2007-05-01 01:50:42 UTC (rev 2616)
@@ -349,7 +349,6 @@
registerConverter(UnicodeField, SQLExprConverter)
-
class Table(SQLExpression):
FieldClass = Field
@@ -381,17 +380,43 @@
if attr.startswith('__'):
raise AttributeError
if attr == 'id':
- return self.FieldClass(self.tableName, self.soClass.sqlmeta.idName, attr)
+ return self._getattrFromID(attr)
+ elif attr+'ID' in self.soClass.sqlmeta.columns:
+ column = self.soClass.sqlmeta.columns[attr+'ID']
+ return self._getattrFromForeignKey(column, attr)
+ elif attr in [x.joinMethodName for x in self.soClass.sqlmeta.joins]:
+ join = [x for x in self.soClass.sqlmeta.joins if x.joinMethodName == attr][0]
+ return self._getattrFromJoin(join, attr)
elif attr not in self.soClass.sqlmeta.columns:
raise AttributeError("%s instance has no attribute '%s'" % (self.soClass.__name__, attr))
else:
column = self.soClass.sqlmeta.columns[attr]
if hasattr(column, "dbEncoding"):
- return self.UnicodeFieldClass(self.tableName, column.dbName,
- attr, column)
+ return self._getattrFromUnicodeColumn(column, attr)
else:
- return self.FieldClass(self.tableName, column.dbName, attr)
+ return self._getattrFromColumn(column, attr)
+ def _getattrFromID(self, attr):
+ return self.FieldClass(self.tableName, self.soClass.sqlmeta.idName, attr)
+
+ def _getattrFromForeignKey(self, column, attr):
+ ret = getattr(self, column.name)==getattr(self.soClass, '_SO_class_'+column.foreignKey).q.id
+ print column
+ return ret
+
+ def _getattrFromJoin(self, join, attr):
+ if hasattr(join, 'otherColumn'):
+ return AND(join.otherClass.q.id == Field(join.intermediateTable, join.otherColumn),
+ Field(join.intermediateTable, join.joinColumn) == self.soClass.q.id)
+ else:
+ return getattr(join.otherClass.q, join.joinColumn)==self.soClass.q.id
+
+ def _getattrFromColumn(self, column, attr):
+ return self.FieldClass(self.tableName, column.dbName, attr)
+
+ def _getattrFromUnicodeColumn(self, column, attr):
+ return self.UnicodeFieldClass(self.tableName, column.dbName, attr, column)
+
class TableSpace:
TableClass = Table
Modified: SQLObject/trunk/sqlobject/tests/test_select_through.py
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_select_through.py 2007-05-01 01:35:15 UTC (rev 2615)
+++ SQLObject/trunk/sqlobject/tests/test_select_through.py 2007-05-01 01:50:42 UTC (rev 2616)
@@ -48,6 +48,7 @@
def testThroughRelatedJoin():
assert list(threes[0].twos.throughTo.threes) == [threes[0], threes[1]]
+ assert list(SRThrough3.select(SRThrough3.q.id==threes[0].id).throughTo.twos) == list(threes[0].twos)
def testThroughFKAndJoin():
assert list(threes[0].ones.throughTo.three.throughTo.twos) == [twos[0]]
\ No newline at end of file
Copied: SQLObject/trunk/sqlobject/tests/test_sqlbuilder_joins_instances.py (from rev 2534, SQLObject/branches/cache-deps-on-views/sqlobject/tests/test_sqlbuilder_joins_instances.py)
===================================================================
--- SQLObject/trunk/sqlobject/tests/test_sqlbuilder_joins_instances.py (rev 0)
+++ SQLObject/trunk/sqlobject/tests/test_sqlbuilder_joins_instances.py 2007-05-01 01:50:42 UTC (rev 2616)
@@ -0,0 +1,62 @@
+from sqlobject import *
+from sqlobject.sqlbuilder import *
+from sqlobject.tests.dbtest import *
+
+''' Testing for expressing join, foreign keys, and instance identity in SQLBuilder expressions.
+'''
+
+class SBPerson(SQLObject):
+ name = StringCol()
+ addresses = SQLMultipleJoin('SBAddress', joinColumn='personID')
+ sharedAddresses = SQLRelatedJoin('SBAddress', addRemoveName='SharedAddress')
+
+class SBAddress(SQLObject):
+ city = StringCol()
+ person = ForeignKey('SBPerson')
+ sharedPeople = SQLRelatedJoin('SBPerson')
+
+
+def setup_module(mod):
+ setupClass([SBPerson, SBAddress])
+ mod.ppl = inserts(SBPerson, [('James',),
+ ('Julia',)],
+ 'name')
+ mod.adds = inserts(SBAddress, [('London',mod.ppl[0].id),
+ ('Chicago',mod.ppl[1].id),
+ ('Abu Dhabi', mod.ppl[1].id)],
+ 'city personID')
+ mod.ppl[0].addSharedAddress(mod.adds[0])
+ mod.ppl[0].addSharedAddress(mod.adds[1])
+ mod.ppl[1].addSharedAddress(mod.adds[0])
+
+def testJoin():
+ assert list(SBPerson.select(AND(SBPerson.q.addresses,SBAddress.q.city=='London'))) == \
+ list(SBPerson.select(AND(SBPerson.q.id==SBAddress.q.personID, SBAddress.q.city=='London'))) == \
+ list(SBAddress.selectBy(city='London').throughTo.person)
+
+def testFK():
+ assert list(SBPerson.select(AND(SBAddress.q.person, SBAddress.q.city=='London'))) == \
+ list(SBPerson.select(AND(SBPerson.q.id==SBAddress.q.personID, SBAddress.q.city=='London')))
+
+def testJoin2():
+ assert list(SBAddress.select(AND(SBPerson.q.addresses, SBPerson.q.name=='Julia'))) == \
+ list(SBAddress.select(AND(SBPerson.q.id==SBAddress.q.personID, SBPerson.q.name=='Julia'))) == \
+ list(SBPerson.selectBy(name='Julia').throughTo.addresses)
+
+def testFK2():
+ assert list(SBAddress.select(AND(SBAddress.q.person, SBPerson.q.name=='Julia'))) == \
+ list(SBAddress.select(AND(SBPerson.q.id==SBAddress.q.personID, SBPerson.q.name=='Julia')))
+
+def testRelatedJoin():
+ assert list(SBAddress.select(AND(SBAddress.q.sharedPeople, SBPerson.q.name=='Julia'))) == \
+ list(SBPerson.selectBy(name='Julia').throughTo.sharedAddresses) == \
+ list(ppl[1].sharedAddresses)
+
+def testInstance():
+ assert list(SBAddress.select(AND(SBAddress.q.person, ppl[0]))) == \
+ list(SBAddress.select(AND(SBPerson.q.id==SBAddress.q.personID, SBPerson.q.id==ppl[0].id))) == \
+ list(ppl[0].addresses)
+
+def testInstance2():
+ assert list(SBAddress.select(AND(SBPerson.q.addresses, ppl[0]))) == \
+ list(SBAddress.select(AND(SBPerson.q.id==SBAddress.q.personID, SBPerson.q.id==ppl[0].id)))
\ No newline at end of file
Modified: SQLObject/trunk/sqlobject/views.py
===================================================================
--- SQLObject/trunk/sqlobject/views.py 2007-05-01 01:35:15 UTC (rev 2615)
+++ SQLObject/trunk/sqlobject/views.py 2007-05-01 01:50:42 UTC (rev 2616)
@@ -32,25 +32,18 @@
def __getattr__(self, attr):
if attr == 'sqlmeta':
raise AttributeError
- alias = self.soClass.sqlmeta.alias
- if attr.startswith('__'):
- raise AttributeError
- if attr == 'id':
- return self.FieldClass(alias, self.tableName, 'id', attr)
- elif attr not in self.soClass.sqlmeta.columns:
- raise AttributeError("%s instance has no attribute '%s'" % (self.soClass.__name__, attr))
- else:
- column = self.soClass.sqlmeta.columns[attr]
- if hasattr(column, "dbEncoding"):
- return self.UnicodeFieldClass(alias, self.tableName, column.name,
- attr, column)
- else:
- return self.FieldClass(alias, self.tableName, column.name, attr)
+ return SQLObjectTable.__getattr__(self, attr)
-class ViewSQLObjectMeta(sqlmeta):
- pass
+ def _getattrFromID(self, attr):
+ return self.FieldClass(self.soClass.sqlmeta.alias, self.tableName, 'id', attr)
+ def _getattrFromColumn(self, column, attr):
+ return self.FieldClass(self.soClass.sqlmeta.alias, self.tableName, column.name, attr)
+ def _getattrFromUnicodeColumn(self, column, attr):
+ return self.UnicodeFieldClass(self.soClass.sqlmeta.alias, self.tableName, column.name, attr, column)
+
+
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,
@@ -61,9 +54,6 @@
See test_views.py for simple examples.
'''
- class sqlmeta(ViewSQLObjectMeta):
- pass
-
def __classinit__(cls, new_attrs):
SQLObject.__classinit__(cls, new_attrs)
# like is_base
|
|
From: samson D. <Dy...@BL...> - 2007-04-29 10:56:10
|
Investors huge, report? http://img152.imageshack.us/img152/3110/k5eu4.jpg The for loop evaluates every option in the musicType select object. |
|
From: Lassi m. <Las...@al...> - 2007-04-29 10:53:37
|
ANLEGER UHR BJ5N.F!!! DIE RALLYE IST GESTARTET Firma: BOERSE INVEST BETEI WKN : 797639 ISIN : CH0012802093 Markt: Frankfurt Kürzel : BJ5N.F Preis: 1.90 5-Tag Prognose: 3.00 KAUFEN KAUFEN KAUFEN! BJ5N.F ESGESCHAFT FIN UNTER PARI! |
|
From: SourceForge.net <no...@so...> - 2007-04-27 21:37:50
|
Bugs item #1628893, was opened at 2007-01-05 17:18 Message generated for change (Settings changed) made by ldaverio You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1628893&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: Postgres Group: SQLObject release (specify) Status: Open >Resolution: Fixed Priority: 5 Private: No Submitted By: Laurent DAVERIO (ldaverio) Assigned to: Nobody/Anonymous (nobody) Summary: SQLObject 0.7.2 / Zope / Pg DateTimeCol problem Initial Comment: When upgrading from version 0.7.0 to 0.7.2, SQLObject used inside Zope becomes unable to access PostgreSQL timestamp columns. If a column has type "timestamp" or "timestamp with time zone" or "timestamp without time zone", it will be represented as a DateTimeCol in SQLObject. The traceback below is obtained when trying to acess data from a table having such a timestamp column : Module Products.Outdoor.Classes, line 1311, in getEchantillonTemoignages Module sqlobject.sresults, line 155, in __iter__ Module sqlobject.dbconnection, line 721, in next Module sqlobject.main, line 918, in get Module sqlobject.main, line 964, in _init Module sqlobject.main, line 1155, in _SO_selectInit Module sqlobject.col, line 955, in to_python Invalid: expected an date/time string of the '%Y-%m-%d %H:%M:%S' format in the DateTimeCol 'dateTemoig nage', got <type 'instance'> DateTime('2006/12/13 11:41:40 GMT+0') instead The error is the same regardless of whether the schema is defined explicitly in Python, or not (i.e. fromDatabase=True in the sqlmeta class). The exact same fragment of code will work flawlessly from a Python script, or event from Zope's debug shell. It seems that Zope's DateTime implementation automatically appends timezone information to the string representation of the timestamp value. A partial workaround would be to change the type of the column to 'text', but then it would no longer possible to perform date calculations on the value, or to use strftime formatting. The release notes of SQLObject 0.7.2 indicate that some of the changes were specifically intended to make SQLObject compatible with Zope, but unfortunately the result seems to be exactly opposite... My setup : - FreeBSD 6.1 - Python 2.4.3 - Zope 2.9.6 - SQLObject 0.7.2 - PostgreSQL 8.1.5 (all software installed from FreeBSD Ports) ---------------------------------------------------------------------- Comment By: Laurent DAVERIO (ldaverio) Date: 2007-04-27 23:36 Message: Logged In: YES user_id=1684381 Originator: YES My new setup : - FreeBSD 6.2 - Python 2.4.4 - Zope 2.9.7 - SQLObject 0.8.2 - PostgreSQL 8.2.4 (all software installed from FreeBSD Ports) With this setup, no error appears any longer :-) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1628893&group_id=74338 |
|
From: SourceForge.net <no...@so...> - 2007-04-27 21:36:23
|
Bugs item #1628893, was opened at 2007-01-05 17:18 Message generated for change (Comment added) made by ldaverio You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1628893&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: Postgres Group: SQLObject release (specify) Status: Open >Resolution: Works For Me Priority: 5 Private: No Submitted By: Laurent DAVERIO (ldaverio) Assigned to: Nobody/Anonymous (nobody) Summary: SQLObject 0.7.2 / Zope / Pg DateTimeCol problem Initial Comment: When upgrading from version 0.7.0 to 0.7.2, SQLObject used inside Zope becomes unable to access PostgreSQL timestamp columns. If a column has type "timestamp" or "timestamp with time zone" or "timestamp without time zone", it will be represented as a DateTimeCol in SQLObject. The traceback below is obtained when trying to acess data from a table having such a timestamp column : Module Products.Outdoor.Classes, line 1311, in getEchantillonTemoignages Module sqlobject.sresults, line 155, in __iter__ Module sqlobject.dbconnection, line 721, in next Module sqlobject.main, line 918, in get Module sqlobject.main, line 964, in _init Module sqlobject.main, line 1155, in _SO_selectInit Module sqlobject.col, line 955, in to_python Invalid: expected an date/time string of the '%Y-%m-%d %H:%M:%S' format in the DateTimeCol 'dateTemoig nage', got <type 'instance'> DateTime('2006/12/13 11:41:40 GMT+0') instead The error is the same regardless of whether the schema is defined explicitly in Python, or not (i.e. fromDatabase=True in the sqlmeta class). The exact same fragment of code will work flawlessly from a Python script, or event from Zope's debug shell. It seems that Zope's DateTime implementation automatically appends timezone information to the string representation of the timestamp value. A partial workaround would be to change the type of the column to 'text', but then it would no longer possible to perform date calculations on the value, or to use strftime formatting. The release notes of SQLObject 0.7.2 indicate that some of the changes were specifically intended to make SQLObject compatible with Zope, but unfortunately the result seems to be exactly opposite... My setup : - FreeBSD 6.1 - Python 2.4.3 - Zope 2.9.6 - SQLObject 0.7.2 - PostgreSQL 8.1.5 (all software installed from FreeBSD Ports) ---------------------------------------------------------------------- >Comment By: Laurent DAVERIO (ldaverio) Date: 2007-04-27 23:36 Message: Logged In: YES user_id=1684381 Originator: YES My new setup : - FreeBSD 6.2 - Python 2.4.4 - Zope 2.9.7 - SQLObject 0.8.2 - PostgreSQL 8.2.4 (all software installed from FreeBSD Ports) With this setup, no error appears any longer :-) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=540672&aid=1628893&group_id=74338 |
|
From: Klabbe M. <Me...@Sc...> - 2007-04-26 22:33:31
|
out WATCH OJU.F TRADE LIKE CRAZY ON FRIDAY! THIS FRANKFURT STOCK IS GOING THROUGH THE ROOF! COMPANY: ORAMED PHARMA SYMBOL: OJU.F PRICE: 0.65 TARGET: 2.15 WKN : A0J3FG ISIN : US68403P1049 WE ARE PREDICTING AMAZING GAINS ON THIS ONE! BE PART OF IT! ADD IT TO YOUR PORTFOLIO! WATCH OJU.F ON FRIDAY APRIL 27TH! All times are Eastern Hop MediumHow Get Wish Infopop |
|
From: <sub...@co...> - 2007-04-25 16:57:53
|
Author: luke
Date: 2007-04-25 10:57:47 -0600 (Wed, 25 Apr 2007)
New Revision: 2604
Added:
SQLObject/branches/cache-deps-on-views/sqlobject/materialized/dependency_events.py
SQLObject/branches/cache-deps-on-views/sqlobject/materialized/materialized_events.py
Modified:
SQLObject/branches/cache-deps-on-views/sqlobject/main.py
SQLObject/branches/cache-deps-on-views/sqlobject/materialized/__init__.py
SQLObject/branches/cache-deps-on-views/sqlobject/materialized/dependency.py
SQLObject/branches/cache-deps-on-views/sqlobject/materialized/materialized.py
SQLObject/branches/cache-deps-on-views/sqlobject/materialized/tests/test_materialized.py
SQLObject/branches/cache-deps-on-views/sqlobject/sqlbuilder.py
SQLObject/branches/cache-deps-on-views/sqlobject/views.py
Log:
Checkpoint for materialized, working partially with ViewSQLObject
Modified: SQLObject/branches/cache-deps-on-views/sqlobject/main.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/main.py 2007-04-25 16:56:17 UTC (rev 2603)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/main.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -934,7 +934,7 @@
try:
val = cls(_SO_fetch_no_create=1)
val._SO_validatorState = SQLObjectState(val)
- val._init(id, connection, selectResults)
+ val._init(id, connection=connection, selectResults=selectResults)
cache.put(id, cls, val)
finally:
cache.finishPut(cls)
Modified: SQLObject/branches/cache-deps-on-views/sqlobject/materialized/__init__.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/materialized/__init__.py 2007-04-25 16:56:17 UTC (rev 2603)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/materialized/__init__.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -1,2 +1,4 @@
from dependency import *
-from materialized import *
\ No newline at end of file
+import dependency_events
+from materialized import *
+import materialized_events
\ No newline at end of file
Modified: SQLObject/branches/cache-deps-on-views/sqlobject/materialized/dependency.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/materialized/dependency.py 2007-04-25 16:56:17 UTC (rev 2603)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/materialized/dependency.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -1,23 +1,10 @@
from sqlobject import declarative
from sqlobject import sqlbuilder
-from sqlobject.events import *
-from sqlobject.include.pydispatch import dispatcher
from sqlobject import classregistry
from sqlobject import SQLObject
-from operator import isCallable
import inspect
-def _processDependentOn(new_class_name, bases, new_attrs, post_funcs, early_funcs):
- def f(cls):
- for name, value in new_attrs.items():
- if hasattr(value, '_dependentOn'):
- for dep, maker, source in value._dependentOn:
- dep.add(maker(cls, name, value),source)
- early_funcs.append(f)
-
-listen(_processDependentOn, dispatcher.Any, ClassCreateSignal)
-
class depFromClsAttr(object):
def __call__(self, cls, name, value):
return (cls.__name__, name)
@@ -80,9 +67,12 @@
factory = kw.pop('factory', None)
if factory is None:
factory = self.DependencyClass.DecoratorFactory()
+ if not isinstance(source[0], (list, tuple)):
+ source = (source,)
def decorate(func):
depOn = getattr(func, '_dependentOn', [])
- depOn.append((self, factory, source))
+ for s in source:
+ depOn.append((self, factory, s))
setattr(func, '_dependentOn', depOn)
return func
return decorate
@@ -149,26 +139,11 @@
_toProcess = self.instancesToProcess(inst, attrs)
for (cls, attr), insts in _toProcess.iteritems():
for inst in insts:
- inst._SO_updateCacheObject([attr])
- self.process(inst, [attr])
+ changed = inst._SO_updateCacheObject([attr])
+ if changed:
+ self.process(inst, [attr])
dep = SQLDependencyManager()
dependentOn = dep.dependentOn
-
-
-def _processDepsOnChange(inst, kwargs):
- dep.process(inst, kwargs.keys())
-
-listen(_processDepsOnChange, SQLObject, RowUpdatedSignal)
-listen(_processDepsOnChange, SQLObject, RowCreatedSignal)
-
-def _processDepsOnDelete(inst, post_funcs):
- attrs = ['id'] + inst.sqlmeta.columns.keys()
- toProcess = dep.instancesToProcess(inst, attrs)
- def f(inst, toProcess=toProcess):
- dep.process(inst, attrs, _toProcess=toProcess)
- if toProcess:
- post_funcs.append(f)
-listen(_processDepsOnDelete, SQLObject, RowDestroySignal)
\ No newline at end of file
Added: SQLObject/branches/cache-deps-on-views/sqlobject/materialized/dependency_events.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/materialized/dependency_events.py (rev 0)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/materialized/dependency_events.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -0,0 +1,28 @@
+from sqlobject import events
+from sqlobject import SQLObject
+from dependency import dep
+
+def _processDependentOn(new_class_name, bases, new_attrs, post_funcs, early_funcs):
+ def f(cls):
+ for name, value in new_attrs.items():
+ if hasattr(value, '_dependentOn'):
+ for dep, maker, source in value._dependentOn:
+ dep.add(maker(cls, name, value),source)
+ early_funcs.append(f)
+
+events.listen(_processDependentOn, events.dispatcher.Any, events.ClassCreateSignal)
+
+def _processDepsOnChange(inst, kwargs):
+ dep.process(inst, kwargs.keys())
+
+events.listen(_processDepsOnChange, SQLObject, events.RowUpdatedSignal)
+events.listen(_processDepsOnChange, SQLObject, events.RowCreatedSignal)
+
+def _processDepsOnDelete(inst, post_funcs):
+ attrs = ['id'] + inst.sqlmeta.columns.keys()
+ toProcess = dep.instancesToProcess(inst, attrs)
+ def f(inst, toProcess=toProcess):
+ dep.process(inst, attrs, _toProcess=toProcess)
+ if toProcess:
+ post_funcs.append(f)
+events.listen(_processDepsOnDelete, SQLObject, events.RowDestroySignal)
\ No newline at end of file
Modified: SQLObject/branches/cache-deps-on-views/sqlobject/materialized/materialized.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/materialized/materialized.py 2007-04-25 16:56:17 UTC (rev 2603)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/materialized/materialized.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -1,8 +1,5 @@
from sqlobject import SQLObject, SQLObjectNotFound, sqlmeta as _sqlmeta
-from sqlobject import events, col
-from sqlobject.main import makeProperties
-from dependency import dep
-from sqlobject.events import *
+from sqlobject import col
class materialized_sqlmeta(_sqlmeta):
cachedIn = None
@@ -20,7 +17,13 @@
idType = cls.idType
cls.cacheClass = type(cls.soClass.__name__+'Cache', (SQLObject,), {'sqlmeta': cache_sqlmeta})
-
+
+ def addCacheColumn(self, value):
+ self.cachedAttributes[value.name] = value
+ self.cacheClass.sqlmeta.addColumn(value.colType(name=value.name, default=None))
+ self.cacheClass.sqlmeta.addColumn(col.BoolCol(name=value.name+'_dirty', default=True))
+ addCacheColumn = classmethod(addCacheColumn)
+
setClass = classmethod(setClass)
class MaterializedSQLObject(SQLObject):
@@ -37,31 +40,22 @@
def _SO_updateCacheObject(self, attrs):
+ changed = []
for attr in attrs:
cacheAttr = self.sqlmeta.cachedAttributes.get(attr, None)
if cacheAttr:
new_value = cacheAttr.func(self)
- self._SO_cacheObject.set(**{attr+'_dirty': False,
- attr: new_value})
+ if new_value != getattr(self._SO_cacheObject, attr):
+ changed.append(attr)
+ self._SO_cacheObject.set(**{attr+'_dirty': False,
+ attr: new_value})
+ else:
+ # If it's not cached, assume descendents should be notified regardless.
+ # Currently this should be mostly for joins, if we decide to cache joins
+ # then they would appear changed in most cases here anyways (add, delete).
+ changed.append(attr)
+ return changed
-def _addColumn(cls, connection, column_name, column_definition, changeSchema, post_funcs):
- ''' for automatically adding dependencies to foreign keys'''
- def f(cls, col):
- if col.foreignKey:
- dep.add((cls.__name__, col.name), (col.foreignKey, 'id', lambda cls=cls,col=col: getattr(cls.q, col.origName)))
- post_funcs.append(f)
-
-events.listen(_addColumn, MaterializedSQLObject, events.AddColumnSignal)
-
-def _addJoin(cls, join_name, join_definition, post_funcs):
- ''' for automatically adding dependencies to joins'''
- def f(cls, join):
- dep.add((cls.__name__, join.joinMethodName), (join.otherClassName, 'id', lambda cls=cls,join=join: getattr(cls.q, join.joinMethodName)))
- post_funcs.append(f)
-
-events.listen(_addJoin, MaterializedSQLObject, events.AddJoinSignal)
-
-
class MaterializedAttr(object):
def __init__(self, func, colType, name=None):
self.func = func
@@ -89,15 +83,3 @@
def decorate(func):
return MaterializedAttr(func, colType, name=name)
return decorate
-
-
-def _addColumnsToCacheClass(new_class_name, bases, new_attrs, post_funcs, early_funcs):
- def f(cls):
- for name, value in new_attrs.items():
- if isinstance(value, MaterializedAttr):
- cls.sqlmeta.cachedAttributes[value.name] = value
- cls.sqlmeta.cacheClass.sqlmeta.addColumn(value.colType(name=value.name, default=None))
- cls.sqlmeta.cacheClass.sqlmeta.addColumn(col.BoolCol(name=value.name+'_dirty', default=True))
- post_funcs.extend((f,makeProperties))
-
-listen(_addColumnsToCacheClass, MaterializedSQLObject, ClassCreateSignal)
Added: SQLObject/branches/cache-deps-on-views/sqlobject/materialized/materialized_events.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/materialized/materialized_events.py (rev 0)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/materialized/materialized_events.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -0,0 +1,39 @@
+from materialized import MaterializedSQLObject, MaterializedAttr
+from dependency import dep
+from sqlobject import events, derived
+from sqlobject.main import makeProperties
+
+####
+# auto from columns
+
+def _addColumn(cls, connection, column_name, column_definition, changeSchema, post_funcs):
+ ''' for automatically adding dependencies to foreign keys'''
+ def f(cls, col):
+ if col.foreignKey:
+ dep.add((cls.__name__, col.name), (col.foreignKey, 'id', lambda cls=cls,col=col: getattr(cls.q, col.origName)))
+ if col.derived:
+ pass
+ post_funcs.append(f)
+
+events.listen(_addColumn, MaterializedSQLObject, events.AddColumnSignal)
+
+def _addJoin(cls, join_name, join_definition, post_funcs):
+ ''' for automatically adding dependencies to joins'''
+ def f(cls, join):
+ dep.add((cls.__name__, join.joinMethodName), (join.otherClassName, 'id', lambda cls=cls,join=join: getattr(cls.q, join.joinMethodName)))
+ post_funcs.append(f)
+
+events.listen(_addJoin, MaterializedSQLObject, events.AddJoinSignal)
+
+####
+# cachedAs
+
+def _addColumnsToCacheClass(new_class_name, bases, new_attrs, post_funcs, early_funcs):
+ def f(cls):
+ for name, value in new_attrs.items():
+ if isinstance(value, MaterializedAttr):
+ cls.sqlmeta.addCacheColumn(value)
+ post_funcs.extend((f,makeProperties))
+
+events.listen(_addColumnsToCacheClass, MaterializedSQLObject, events.ClassCreateSignal)
+
Modified: SQLObject/branches/cache-deps-on-views/sqlobject/materialized/tests/test_materialized.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/materialized/tests/test_materialized.py 2007-04-25 16:56:17 UTC (rev 2603)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/materialized/tests/test_materialized.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -63,7 +63,7 @@
def _get_name3(self):
''' dep on dep '''
return self.name + self.detail
-
+
def setup_module(mod):
setupClass([MaterializedOne, MaterializedTwo, MaterializedOne.sqlmeta.cacheClass, MaterializedTwo.sqlmeta.cacheClass])
mod.ones = inserts(MaterializedOne, (('S',),
Modified: SQLObject/branches/cache-deps-on-views/sqlobject/sqlbuilder.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/sqlbuilder.py 2007-04-25 16:56:17 UTC (rev 2603)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/sqlbuilder.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -383,27 +383,43 @@
if attr.startswith('__'):
raise AttributeError
if attr == 'id':
- return self.FieldClass(self.tableName, self.soClass.sqlmeta.idName, attr)
+ return self._getattrFromID(attr)
elif attr+'ID' in self.soClass.sqlmeta.columns:
column = self.soClass.sqlmeta.columns[attr+'ID']
- return getattr(self, column.name)==getattr(self.soClass, '_SO_class_'+column.foreignKey).q.id
+ return self._getattrFromForeignKey(column, attr)
elif attr in [x.joinMethodName for x in self.soClass.sqlmeta.joins]:
join = [x for x in self.soClass.sqlmeta.joins if x.joinMethodName == attr][0]
- if hasattr(join, 'otherColumn'):
- return AND(join.otherClass.q.id == Field(join.intermediateTable, join.otherColumn),
- Field(join.intermediateTable, join.joinColumn) == self.soClass.q.id)
- else:
- return getattr(join.otherClass.q, join.joinColumn)==self.soClass.q.id
+ return self._getattrFromJoin(join, attr)
elif attr not in self.soClass.sqlmeta.columns:
raise AttributeError("%s instance has no attribute '%s'" % (self.soClass.__name__, attr))
else:
column = self.soClass.sqlmeta.columns[attr]
if hasattr(column, "dbEncoding"):
- return self.UnicodeFieldClass(self.tableName, column.dbName,
- attr, column)
+ return self._getattrFromUnicodeColumn(column, attr)
else:
- return self.FieldClass(self.tableName, column.dbName, attr)
+ return self._getattrFromColumn(column, attr)
+ def _getattrFromID(self, attr):
+ return self.FieldClass(self.tableName, self.soClass.sqlmeta.idName, attr)
+
+ def _getattrFromForeignKey(self, column, attr):
+ ret = getattr(self, column.name)==getattr(self.soClass, '_SO_class_'+column.foreignKey).q.id
+ print column
+ return ret
+
+ def _getattrFromJoin(self, join, attr):
+ if hasattr(join, 'otherColumn'):
+ return AND(join.otherClass.q.id == Field(join.intermediateTable, join.otherColumn),
+ Field(join.intermediateTable, join.joinColumn) == self.soClass.q.id)
+ else:
+ return getattr(join.otherClass.q, join.joinColumn)==self.soClass.q.id
+
+ def _getattrFromColumn(self, column, attr):
+ return self.FieldClass(self.tableName, column.dbName, attr)
+
+ def _getattrFromUnicodeColumn(self, column, attr):
+ return self.UnicodeFieldClass(self.tableName, column.dbName, attr, column)
+
class TableSpace:
TableClass = Table
Modified: SQLObject/branches/cache-deps-on-views/sqlobject/views.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/views.py 2007-04-25 16:56:17 UTC (rev 2603)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/views.py 2007-04-25 16:57:47 UTC (rev 2604)
@@ -32,25 +32,18 @@
def __getattr__(self, attr):
if attr == 'sqlmeta':
raise AttributeError
- alias = self.soClass.sqlmeta.alias
- if attr.startswith('__'):
- raise AttributeError
- if attr == 'id':
- return self.FieldClass(alias, self.tableName, 'id', attr)
- elif attr not in self.soClass.sqlmeta.columns:
- raise AttributeError("%s instance has no attribute '%s'" % (self.soClass.__name__, attr))
- else:
- column = self.soClass.sqlmeta.columns[attr]
- if hasattr(column, "dbEncoding"):
- return self.UnicodeFieldClass(alias, self.tableName, column.name,
- attr, column)
- else:
- return self.FieldClass(alias, self.tableName, column.name, attr)
+ return SQLObjectTable.__getattr__(self, attr)
-class ViewSQLObjectMeta(sqlmeta):
- pass
+ def _getattrFromID(self, attr):
+ return self.FieldClass(self.soClass.sqlmeta.alias, self.tableName, 'id', attr)
+ def _getattrFromColumn(self, column, attr):
+ return self.FieldClass(self.soClass.sqlmeta.alias, self.tableName, column.name, attr)
+ def _getattrFromUnicodeColumn(self, column, attr):
+ return self.UnicodeFieldClass(self.soClass.sqlmeta.alias, self.tableName, column.name, attr, column)
+
+
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,
@@ -61,9 +54,6 @@
See test_views.py for simple examples.
'''
- class sqlmeta(ViewSQLObjectMeta):
- pass
-
def __classinit__(cls, new_attrs):
SQLObject.__classinit__(cls, new_attrs)
# like is_base
|
|
From: <sub...@co...> - 2007-04-25 16:56:22
|
Author: luke
Date: 2007-04-25 10:56:17 -0600 (Wed, 25 Apr 2007)
New Revision: 2603
Added:
SQLObject/branches/cache-deps-on-views/sqlobject/derived.py
Modified:
SQLObject/branches/cache-deps-on-views/sqlobject/tests/test_derived_accessors.py
Log:
Missed file for Derived columns, test update
Added: SQLObject/branches/cache-deps-on-views/sqlobject/derived.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/derived.py (rev 0)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/derived.py 2007-04-25 16:56:17 UTC (rev 2603)
@@ -0,0 +1,124 @@
+from col import ForeignKey, Col, SOCol
+from sqlbuilder import AND, SQLConstant
+import classregistry
+
+class SODerived(SOCol):
+ def __init__(self, *args, **kw):
+ kw['derived'] = True
+ kw['immutable'] = True
+ super(SODerived, self).__init__(*args, **kw)
+
+class SOFilterFrom(SODerived):
+ def __init__(self, joinName=None, query=None, **kw):
+ super(SOFilterFrom, self).__init__(**kw)
+ self.join = joinName
+ self.query = query
+
+ def selectResults(self, obj):
+ name = self.join
+ sresults = None
+ for j in obj.sqlmeta.joins:
+ if j.joinMethodName == name:
+ sresults = j.performJoin(obj)
+ break
+ if sresults is None:
+ join = obj.sqlmeta.columnsExtended.get(name, None)
+ if join:
+ sresults = join.selectResults(obj)
+ assert sresults is not None, "Could not find join '%s' in %s" % (name, obj)
+ return sresults.filter(self.query)
+
+ def __get__(self, obj, type=None):
+ return self.selectResults(obj)
+
+class FilterFrom(Col):
+ baseClass = SOFilterFrom
+
+ def __init__(self, joinName=None, query=None, **kw):
+ super(FilterFrom, self).__init__(joinName=joinName, query=query, **kw)
+
+class SOOneFrom(SOFilterFrom):
+ def __get__(self, obj, type=None):
+ if self.notNone:
+ return self.selectResults(obj).getOne()
+ else:
+ return self.selectResults(obj).getOne(None)
+
+class OneFrom(FilterFrom):
+ baseClass = SOOneFrom
+
+class SOAggregateFrom(SOFilterFrom):
+ aggregateName = None
+ def __init__(self, joinName=None, column=None, query=None, **kw):
+ kw['joinName'] = joinName
+ kw['query'] = query
+ super(SOAggregateFrom, self).__init__(**kw)
+ self.aggregateColumn = column
+
+ def __get__(self, obj, type=None):
+ if self.aggregateName is None:
+ raise ValueError, ("Missing aggregateName, too abstract")
+ arg = []
+ if self.aggregateColumn:
+ arg.append(self.aggregateColumn)
+ return getattr(self.selectResults(obj), self.aggregateName)(*arg)
+
+class AggregateFrom(FilterFrom):
+ baseClass = SOAggregateFrom
+
+ def __init__(self, joinName=None, column=None, query=None, **kw):
+ super(AggregateFrom, self).__init__(joinName=joinName, column=column, query=query, **kw)
+
+class SOCountFrom(SOAggregateFrom):
+ aggregateName = "count"
+
+class CountFrom(AggregateFrom):
+ baseClass = SOCountFrom
+
+class SOMinFrom(SOAggregateFrom):
+ aggregateName = "min"
+
+class MinFrom(AggregateFrom):
+ baseClass = SOMinFrom
+
+class SOMaxFrom(SOAggregateFrom):
+ aggregateName = "max"
+
+class MaxFrom(AggregateFrom):
+ baseClass = SOMaxFrom
+
+class SOAvgFrom(SOAggregateFrom):
+ aggregateName = "avg"
+
+class AvgFrom(AggregateFrom):
+ baseClass = SOAvgFrom
+
+class SOSumFrom(SOAggregateFrom):
+ aggregateName = "sum"
+
+class SumFrom(AggregateFrom):
+ baseClass = SOSumFrom
+
+class SOValueFrom(SODerived):
+ def __init__(self, sourceColumn=None, valueColumn=None, **kw):
+ super(SOValueFrom, self).__init__(**kw)
+ self.sourceColumn = sourceColumn
+ self.valueColumn = valueColumn
+
+ def __get__(self, obj, type=None):
+ return getattr(getattr(obj, self.sourceColumn), self.valueColumn)
+
+class ValueFrom(Col):
+ baseClass = SOValueFrom
+
+ def __init__(self, sourceColumn=None, valueColumn=None, **kw):
+ super(ValueFrom, self).__init__(sourceColumn=sourceColumn, valueColumn=valueColumn, **kw)
+
+SQLForeignKey = ForeignKey
+
+#~ all = []
+#~ for key, value in globals().items():
+ #~ if isinstance(value, type) and (issubclass(value, Col) or issubclass(value, SOCol)):
+ #~ all.append(key)
+#~ __all__.extend(all)
+#~ del all
\ No newline at end of file
Modified: SQLObject/branches/cache-deps-on-views/sqlobject/tests/test_derived_accessors.py
===================================================================
--- SQLObject/branches/cache-deps-on-views/sqlobject/tests/test_derived_accessors.py 2007-04-25 15:17:07 UTC (rev 2602)
+++ SQLObject/branches/cache-deps-on-views/sqlobject/tests/test_derived_accessors.py 2007-04-25 16:56:17 UTC (rev 2603)
@@ -2,17 +2,21 @@
from sqlobject.sqlbuilder import ImportProxy
from sqlobject.tests.dbtest import *
+DPerson = ImportProxy('DerivePerson')
+DPhone = ImportProxy('DerivePhone')
+DPhoneCall = ImportProxy('DerivePhoneCall')
+
class DerivePerson(SQLObject):
name = StringCol(alternateID=True)
city = StringCol()
phones = SQLMultipleJoin('DerivePhone', joinColumn='personID')
- primaryPhone = OneFrom('phones', query=ImportProxy('DerivePhone').q.isPrimary==True)
- secondaryPhones = FilterFrom('phones', query=ImportProxy('DerivePhone').q.isPrimary==False)
+ primaryPhone = OneFrom('phones', query=DPhone.q.isPrimary==True)
+ secondaryPhones = FilterFrom('phones', query=DPhone.q.isPrimary==False)
- primaryMinutes = ValueFrom('primaryPhone', ImportProxy('DerivePhone').q.totalMinutes)
- mostMinutes = MaxFrom('phones', ImportProxy('DerivePhone').q.totalMinutes)
- mostSecondaryMinutes = MaxFrom('secondaryPhones', ImportProxy('DerivePhone').q.totalMinutes)
+ primaryMinutes = ValueFrom('primaryPhone', 'totalMinutes')
+ mostMinutes = MaxFrom('phones', DPhone.q.totalMinutes)
+ mostSecondaryMinutes = MaxFrom('secondaryPhones', DPhone.q.totalMinutes)
# mostUsedPhone = OneFrom('phones', query=ImportProxy('DerivePhone').q.totalMinutes==SelfProxy.q.mostMinutes)
@@ -20,8 +24,8 @@
number = StringCol(alternateID=True)
isPrimary = BoolCol()
- city = ValueFrom('person', ImportProxy('Person').q.city)
- totalMinutes = SumFrom('calls', ImportProxy('DerivePhoneCall').q.minutes)
+ city = ValueFrom('person', 'city')
+ totalMinutes = SumFrom('calls', DPhoneCall.q.minutes)
# totalLocalMinutes = SumFrom('calls', ImportProxy('DerivedPhoneCall').q.minutes,
# query=ImportProxy('DerivedPhoneCall').q.city == SelfProxy.q.city)
@@ -69,3 +73,7 @@
assert ph1.totalMinutes == ph1.calls.sum(DerivePhoneCall.q.minutes)
#assert ph1.totalLocalMinutes == ph1.calls.filter(DerivePhone.sum(DerivePhoneCall.q.minutes)
+def test_valueFrom():
+ ph1 = DerivePhone.byNumber('1234')
+ assert ph1.city == ph1.person.city
+ assert ph1.person.primaryMinutes == ph1.totalMinutes
\ No newline at end of file
|
|
From: <sub...@co...> - 2007-04-25 15:17:12
|
Author: phd Date: 2007-04-25 09:17:07 -0600 (Wed, 25 Apr 2007) New Revision: 2602 Modified: SQLObject/docs/News.txt SQLObject/docs/SQLObject.txt Log: More documentation about orderBy. Modified: SQLObject/docs/News.txt =================================================================== --- SQLObject/docs/News.txt 2007-04-25 15:16:50 UTC (rev 2601) +++ SQLObject/docs/News.txt 2007-04-25 15:17:07 UTC (rev 2602) @@ -220,6 +220,8 @@ * Yet another patch to properly initialize MySQL connection encoding. +* More documentation about orderBy. + SQLObject 0.7.5 =============== Modified: SQLObject/docs/SQLObject.txt =================================================================== --- SQLObject/docs/SQLObject.txt 2007-04-25 15:16:50 UTC (rev 2601) +++ SQLObject/docs/SQLObject.txt 2007-04-25 15:17:07 UTC (rev 2602) @@ -568,14 +568,13 @@ .. _orderBy: -You can use the keyword arguments `orderBy` to create ``ORDER BY`` in -the select statements: `orderBy` takes a string, which should be the -*database* name of the column, or a column in the form -``Person.q.firstName``. You can use ``"-colname"`` to specify -descending order (this is translated to DESC, so it works on -non-numeric types as well), or call -``MyClass.select().reversed()``. orderBy can also take a list of -column names in the same format as a single column name. +You can use the keyword arguments `orderBy` to create ``ORDER BY`` in the +select statements: `orderBy` takes a string, which should be the *database* +name of the column, or a column in the form ``Person.q.firstName``. You +can use ``"-colname"`` or ``DESC(Person.q.firstName``) to specify +descending order (this is translated to DESC, so it works on non-numeric +types as well), or call ``MyClass.select().reversed()``. orderBy can also +take a list of columns in the same format: ``["-weight", "name"]``. You can use the special class variable `_defaultOrder` to give a default ordering for all selects. To get an unordered result when |
|
From: <sub...@co...> - 2007-04-25 15:16:54
|
Author: phd Date: 2007-04-25 09:16:50 -0600 (Wed, 25 Apr 2007) New Revision: 2601 Modified: SQLObject/branches/0.9/docs/News.txt SQLObject/branches/0.9/docs/SQLObject.txt Log: More documentation about orderBy. Modified: SQLObject/branches/0.9/docs/News.txt =================================================================== --- SQLObject/branches/0.9/docs/News.txt 2007-04-25 15:16:39 UTC (rev 2600) +++ SQLObject/branches/0.9/docs/News.txt 2007-04-25 15:16:50 UTC (rev 2601) @@ -217,6 +217,8 @@ * Yet another patch to properly initialize MySQL connection encoding. +* More documentation about orderBy. + SQLObject 0.7.5 =============== Modified: SQLObject/branches/0.9/docs/SQLObject.txt =================================================================== --- SQLObject/branches/0.9/docs/SQLObject.txt 2007-04-25 15:16:39 UTC (rev 2600) +++ SQLObject/branches/0.9/docs/SQLObject.txt 2007-04-25 15:16:50 UTC (rev 2601) @@ -568,11 +568,13 @@ .. _orderBy: -You can use the keyword arguments `orderBy` to create ``ORDER BY`` in -the select statements: `orderBy` takes a string, which should be the -*database* name of the column, or a column in the form -``Person.q.firstName``. You can use ``"-colname"`` to specify -descending order, or call ``MyClass.select().reversed()``. +You can use the keyword arguments `orderBy` to create ``ORDER BY`` in the +select statements: `orderBy` takes a string, which should be the *database* +name of the column, or a column in the form ``Person.q.firstName``. You +can use ``"-colname"`` or ``DESC(Person.q.firstName``) to specify +descending order (this is translated to DESC, so it works on non-numeric +types as well), or call ``MyClass.select().reversed()``. orderBy can also +take a list of columns in the same format: ``["-weight", "name"]``. You can use the special class variable `_defaultOrder` to give a default ordering for all selects. To get an unordered result when |