sqlobject-discuss Mailing List for SQLObject (Page 412)
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
You can subscribe to this list here.
2003 |
Jan
|
Feb
(2) |
Mar
(43) |
Apr
(204) |
May
(208) |
Jun
(102) |
Jul
(113) |
Aug
(63) |
Sep
(88) |
Oct
(85) |
Nov
(95) |
Dec
(62) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(38) |
Feb
(93) |
Mar
(125) |
Apr
(89) |
May
(66) |
Jun
(65) |
Jul
(53) |
Aug
(65) |
Sep
(79) |
Oct
(60) |
Nov
(171) |
Dec
(176) |
2005 |
Jan
(264) |
Feb
(260) |
Mar
(145) |
Apr
(153) |
May
(192) |
Jun
(166) |
Jul
(265) |
Aug
(340) |
Sep
(300) |
Oct
(469) |
Nov
(316) |
Dec
(235) |
2006 |
Jan
(236) |
Feb
(156) |
Mar
(229) |
Apr
(221) |
May
(257) |
Jun
(161) |
Jul
(97) |
Aug
(169) |
Sep
(159) |
Oct
(400) |
Nov
(136) |
Dec
(134) |
2007 |
Jan
(152) |
Feb
(101) |
Mar
(115) |
Apr
(120) |
May
(129) |
Jun
(82) |
Jul
(118) |
Aug
(82) |
Sep
(30) |
Oct
(101) |
Nov
(137) |
Dec
(53) |
2008 |
Jan
(83) |
Feb
(139) |
Mar
(55) |
Apr
(69) |
May
(82) |
Jun
(31) |
Jul
(66) |
Aug
(30) |
Sep
(21) |
Oct
(37) |
Nov
(41) |
Dec
(65) |
2009 |
Jan
(69) |
Feb
(46) |
Mar
(22) |
Apr
(20) |
May
(39) |
Jun
(30) |
Jul
(36) |
Aug
(58) |
Sep
(38) |
Oct
(20) |
Nov
(10) |
Dec
(11) |
2010 |
Jan
(24) |
Feb
(63) |
Mar
(22) |
Apr
(72) |
May
(8) |
Jun
(13) |
Jul
(35) |
Aug
(23) |
Sep
(12) |
Oct
(26) |
Nov
(11) |
Dec
(30) |
2011 |
Jan
(15) |
Feb
(44) |
Mar
(36) |
Apr
(26) |
May
(27) |
Jun
(10) |
Jul
(28) |
Aug
(12) |
Sep
|
Oct
|
Nov
(17) |
Dec
(16) |
2012 |
Jan
(12) |
Feb
(31) |
Mar
(23) |
Apr
(14) |
May
(10) |
Jun
(26) |
Jul
|
Aug
(2) |
Sep
(2) |
Oct
(1) |
Nov
|
Dec
(6) |
2013 |
Jan
(4) |
Feb
(5) |
Mar
|
Apr
(4) |
May
(13) |
Jun
(7) |
Jul
(5) |
Aug
(15) |
Sep
(25) |
Oct
(18) |
Nov
(7) |
Dec
(3) |
2014 |
Jan
(1) |
Feb
(5) |
Mar
|
Apr
(3) |
May
(3) |
Jun
(2) |
Jul
(4) |
Aug
(5) |
Sep
|
Oct
(11) |
Nov
|
Dec
(62) |
2015 |
Jan
(8) |
Feb
(3) |
Mar
(15) |
Apr
|
May
|
Jun
(6) |
Jul
|
Aug
(6) |
Sep
|
Oct
|
Nov
|
Dec
(19) |
2016 |
Jan
(2) |
Feb
|
Mar
(2) |
Apr
(4) |
May
(3) |
Jun
(7) |
Jul
(14) |
Aug
(13) |
Sep
(6) |
Oct
(2) |
Nov
(3) |
Dec
|
2017 |
Jan
(6) |
Feb
(14) |
Mar
(2) |
Apr
|
May
(1) |
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(4) |
Nov
(3) |
Dec
|
2018 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2019 |
Jan
|
Feb
(1) |
Mar
|
Apr
(44) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
2020 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
(1) |
2021 |
Jan
|
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
(3) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2022 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(1) |
Oct
|
Nov
|
Dec
(1) |
2023 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
(1) |
Nov
(2) |
Dec
|
2024 |
Jan
|
Feb
|
Mar
|
Apr
(4) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
2025 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Bruno T. <bt...@as...> - 2003-08-06 00:32:18
|
Hi There > > > At 14:18 2003-07-24 -0400, Brad Bollenbach wrote: > >> > Well, if there's going to be composite keys, that might as well be > >> > generalized to all the columns (i.e., any attribute could be a > >> composite > >> > of several columns). > >> > >> What's the use case for this? So I think a have a situation where some could need this: (note, this is existent database, system under development has to integrate to it, so bad database layout is not a way out here. Badly designed databases are out there and we must work with some of them) :( products_table +---+-----------------------+ |id | description | family_id | subfamily_id | +---+----------------+-----------+--------------+ | 1| Foobar gum | 10 | 5| | 1| Foobar lolipops| 10 | 6| | 1| Foobar socks | 20 | 5| family_table +---+-----------------------+ |id | description | +---+-----------------------+ | 10| Candies | | 20| Underwear | subfamily_table +---+-----------+---------------+ |id | family_id | description | +---+-----------+---------------+ | 5| 10| chewing gum | | 5| 20| socks | | 6| 10| lolipops | I need to retrieve subfamily description for my products. It is possible to manually retrieve it, but the idea is just state to SQLObject that id and family_id are primary keys for the subfamily table and that the subfamily are linked to the products through those keys. Having SQLObject retrieving the subfamily object when I retrieve a product using those definitions would be great. []'s Bruno Trevisan bt...@as... |=3D| Async Open Source |=3D| D. Alexandrina, 253= 4 http://www.async.com.br/ |=3D| +55 16 261-2331 |=3D| 13566-290 |=3D| +55 16 9781-8717 |=3D| S=E3o Carlos, SP, B= rasil |
From: Brad B. <br...@bb...> - 2003-08-05 23:09:58
|
On Tuesday, August 5, 2003, at 06:59 PM, Magnus Lyck=E5 wrote: > At 14:18 2003-07-24 -0400, Brad Bollenbach wrote: >> > Well, if there's going to be composite keys, that might as well be >> > generalized to all the columns (i.e., any attribute could be a=20 >> composite >> > of several columns). >> >> What's the use case for this? > > For instance money objects that consist of an amount and a currency. > You could make them full objects with an identifier and do: > > order_line > |id |order_id|spec |money_id| > +---+--------+--------------+--------+ > | 1| 123|Dog collar | 1| > | 2| 123|Dog food | 2| > > money > |id |amt |currency| > +---+-------+--------+ > | 1|12.50 |EUR | > | 2|0.34 |USD | This is bad database design. amt and currency belong in the order_line=20= table. > But is seems simpler to just do: > > order_line > |id |order_id|spec |price_amt|price_currency| > +---+--------+--------------+---------+--------------+ > | 1| 123|Dog collar |12.50 |EUR | > | 2| 123|Dog food |0.34 |USD | > > > In this case you could say that the price is a value from a > design point of view, but an object from a programming point > of view. Martin Fowler calls such objects "Value Objects" in > the book "Patterns of Enterprise Application Architechture". I don't follow your point. At what point do Python properties stop=20 being useable here, and composite columns (for something other than the=20= PK) become necessary? -- Brad Bollenbach BBnet.ca= |
From: Magnus <ma...@th...> - 2003-08-05 22:53:07
|
At 14:18 2003-07-24 -0400, Brad Bollenbach wrote: > > Well, if there's going to be composite keys, that might as well be > > generalized to all the columns (i.e., any attribute could be a composite > > of several columns). > >What's the use case for this? For instance money objects that consist of an amount and a currency. You could make them full objects with an identifier and do: order_line |id |order_id|spec |money_id| +---+--------+--------------+--------+ | 1| 123|Dog collar | 1| | 2| 123|Dog food | 2| money |id |amt |currency| +---+-------+--------+ | 1|12.50 |EUR | | 2|0.34 |USD | But is seems simpler to just do: order_line |id |order_id|spec |price_amt|price_currency| +---+--------+--------------+---------+--------------+ | 1| 123|Dog collar |12.50 |EUR | | 2| 123|Dog food |0.34 |USD | In this case you could say that the price is a value from a design point of view, but an object from a programming point of view. Martin Fowler calls such objects "Value Objects" in the book "Patterns of Enterprise Application Architechture". -- Magnus Lycka (It's really Lyckå), ma...@th... Thinkware AB, Sweden, www.thinkware.se I code Python ~ The Agile Programming Language |
From: Luke O. <lu...@me...> - 2003-08-03 18:27:04
|
Although I haven't been too active recently, I also will be on vacation without computers through Aug 11th. SQLObject additions are percolating in my mind however, time is becoming available, and I'll see what I can answer on the list when I get back. - Luke Quoting Ian Bicking <ia...@co...>: > Sorry I haven't been keeping up on things recently, I've spent all my > long-attention-span time on projects I have to get done before I leave > on a camping trip. And now that I'm leaving I'll be much more absent. > (And here I've responded to all these threads, and I won't be able to > follow up much...) > > I'll be back mid-August. My inattentiveness now isn't any long-term > indicator, it's just summer. > > Ian > > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > -- The Pursuit of Counterfactual Histories |
From: Andy T. <an...@ha...> - 2003-08-03 10:22:55
|
Achim Domma (ProCoders) wrote: > Hi, > > I've seen Brad Bollenbach very good talk at Europython, and now I finaly > found the time to give SQLObject a try. I really like it, but have some > questions: > > - In the examples, the connection is always hardcoded in the module, where > my classes are definied. In real world apps I would like to specifiy the > connection from outside of the module. I might have two different instances > of my app, using two different servers/databases. How would I do that? > > - What's about aggregate columns? I want to build a system with some kind of > ranking mechanism, where I usually only want to show the average ranking. As > far as I understand, I would have to calculate that value 'by hand', if I > use SQLObject. Is that right? > > regards, > Achim > I'll leave others to answer your question on aggregate columns, but for connections I do the same thing that I would for 'raw' db-api code. I store the user name, password, host name and database name in a configuration file and then read that in at the top of my module. The values are placed in a dictionary (actually, they are stored in dict format but that's just because I'm lazy) and then used as arguments to the connection attribute. e.g.; """ import os.path CONFIG_FILENAME='myconfig.txt' if '__file__' in locals(): CONFIG=os.path.dirname(__file__)+'/'+CONFIG_FILENAME else: CONFIG=CONFIG_FILENAME config=readAndEvalFile(CONFIG) __connection__=MySQLConnection(db=config['db'], host=config['host'], user=config['user'], passwd=config['passwd']) """ The only magic there is the readAndEvalFile function which simply reads the file you supply and turns it into a dictionary. Of course, you don't need to store the values in a configuration file. If you are building a web or gui front end to your application you can prompt for the values and then pass them in to your module at run time. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ |
From: Achim D. \(ProCoders\) <do...@pr...> - 2003-08-03 08:20:18
|
Hi, I've seen Brad Bollenbach very good talk at Europython, and now I finaly found the time to give SQLObject a try. I really like it, but have some questions: - In the examples, the connection is always hardcoded in the module, where my classes are definied. In real world apps I would like to specifiy the connection from outside of the module. I might have two different instances of my app, using two different servers/databases. How would I do that? - What's about aggregate columns? I want to build a system with some kind of ranking mechanism, where I usually only want to show the average ranking. As far as I understand, I would have to calculate that value 'by hand', if I use SQLObject. Is that right? regards, Achim |
From: J-P L. <jp...@si...> - 2003-08-01 21:54:32
|
Is anyone else having problems when forking multiple processes? I'm using postgres and am getting the following error: File "ContactModel.py", line 42, in getContacts for contactDBO in resultList: File "SQLObject/DBConnection.py", line 134, in iterSelect OperationalError: ERROR: SET TRANSACTION ISOLATION LEVEL must be called before any query I'm using cherrypy with SQLObject and simply setting forking=1 in the config which creates a new process with every request. Search the net - people have pointed fingers at connection pooling. Has anyone experienced a similiar problem or know more about this? Thanks much! -- J-P |
From: Dave P. <dpo...@te...> - 2003-08-01 19:42:18
|
Thanks, that did it! import SQLObject.SQLBuilder Records.expires = func.NOW() + SQLBuilder.SQLConstant("INTERVAL 30 DAY") :) On Fri, 2003-08-01 at 14:35, Ian Bicking wrote: > Oops, that should have been > SQLObject.SQLBuilder.SQLConstant("INTERVAL 30 DAY") > -- you could also register something like mx.DeltaDateTime as a type, > and convert it that way. > > Good luck, I'm off... > Ian > > > On Fri, 2003-08-01 at 13:56, Dave Poirier wrote: > > On Fri, 2003-08-01 at 10:40, Ian Bicking wrote: > > > On Fri, 2003-08-01 at 08:18, Dave Poirier wrote: > > > > I'm trying to create a record in a database with a 'expires' field, > > > > which records are deleted whenever expires <= NOW(). I seem to have > > > > difficulty grasping how I can generate a query similar to: > > > > > > > > UPDATE records SET expires = NOW() + INTERVAL 30 DAY; > > > > > > > > I've tried something like: > > > > > > > > Records.expires = func.NOW('INTERVAL 30 DAY') > > > > Records.expires = func.NOW() + 'INTERVAL 30 DAY' > > > > Records.expires = func.NOW() + '+ INTERVAL 30 DAY' > > > > Records.expires = func.DATE_ADD(func.NOW(),'INTERVAL 30 DAY') > > > > > > func.NOW() + const('INTERVAL 30 DAY') > > > > The query being sent to MySQL is: > > > > UPDATE session SET expires = (NOW() + __call__('INTERVAL 30 MINUTE')) > > WHERE id = 2 > > > > MySQL complains with: > > > > ProgrammingError: (1064, "You have an error in your SQL syntax near > > '('INTERVAL 30 MINUTE')) WHERE id = 2' at line 1") > > > > > > -Dave |
From: Ian B. <ia...@co...> - 2003-08-01 19:34:04
|
Oops, that should have been SQLObject.SQLBuilder.SQLConstant("INTERVAL 30 DAY") -- you could also register something like mx.DeltaDateTime as a type, and convert it that way. Good luck, I'm off... Ian On Fri, 2003-08-01 at 13:56, Dave Poirier wrote: > On Fri, 2003-08-01 at 10:40, Ian Bicking wrote: > > On Fri, 2003-08-01 at 08:18, Dave Poirier wrote: > > > I'm trying to create a record in a database with a 'expires' field, > > > which records are deleted whenever expires <= NOW(). I seem to have > > > difficulty grasping how I can generate a query similar to: > > > > > > UPDATE records SET expires = NOW() + INTERVAL 30 DAY; > > > > > > I've tried something like: > > > > > > Records.expires = func.NOW('INTERVAL 30 DAY') > > > Records.expires = func.NOW() + 'INTERVAL 30 DAY' > > > Records.expires = func.NOW() + '+ INTERVAL 30 DAY' > > > Records.expires = func.DATE_ADD(func.NOW(),'INTERVAL 30 DAY') > > > > func.NOW() + const('INTERVAL 30 DAY') > > The query being sent to MySQL is: > > UPDATE session SET expires = (NOW() + __call__('INTERVAL 30 MINUTE')) > WHERE id = 2 > > MySQL complains with: > > ProgrammingError: (1064, "You have an error in your SQL syntax near > '('INTERVAL 30 MINUTE')) WHERE id = 2' at line 1") > > > -Dave > > > > ------------------------------------------------------- > This SF.Net email sponsored by: Free pre-built ASP.NET sites including > Data Reports, E-commerce, Portals, and Forums are available now. > Download today and enter to win an XBOX or Visual Studio .NET. > http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss |
From: Dave P. <dpo...@te...> - 2003-08-01 18:56:31
|
On Fri, 2003-08-01 at 10:40, Ian Bicking wrote: > On Fri, 2003-08-01 at 08:18, Dave Poirier wrote: > > I'm trying to create a record in a database with a 'expires' field, > > which records are deleted whenever expires <= NOW(). I seem to have > > difficulty grasping how I can generate a query similar to: > > > > UPDATE records SET expires = NOW() + INTERVAL 30 DAY; > > > > I've tried something like: > > > > Records.expires = func.NOW('INTERVAL 30 DAY') > > Records.expires = func.NOW() + 'INTERVAL 30 DAY' > > Records.expires = func.NOW() + '+ INTERVAL 30 DAY' > > Records.expires = func.DATE_ADD(func.NOW(),'INTERVAL 30 DAY') > > func.NOW() + const('INTERVAL 30 DAY') The query being sent to MySQL is: UPDATE session SET expires = (NOW() + __call__('INTERVAL 30 MINUTE')) WHERE id = 2 MySQL complains with: ProgrammingError: (1064, "You have an error in your SQL syntax near '('INTERVAL 30 MINUTE')) WHERE id = 2' at line 1") -Dave |
From: Ian B. <ia...@co...> - 2003-08-01 15:39:08
|
On Fri, 2003-08-01 at 08:18, Dave Poirier wrote: > I'm trying to create a record in a database with a 'expires' field, > which records are deleted whenever expires <= NOW(). I seem to have > difficulty grasping how I can generate a query similar to: > > UPDATE records SET expires = NOW() + INTERVAL 30 DAY; > > I've tried something like: > > Records.expires = func.NOW('INTERVAL 30 DAY') > Records.expires = func.NOW() + 'INTERVAL 30 DAY' > Records.expires = func.NOW() + '+ INTERVAL 30 DAY' > Records.expires = func.DATE_ADD(func.NOW(),'INTERVAL 30 DAY') func.NOW() + const('INTERVAL 30 DAY') > as well as many other combinations, but none of them seemed to work. > > Any suggestion? > -Dave. > > btw, how does one access the raw database connection from a SQLObject? I > know I somehow have to go thru _connection and then something else, but > everytime I've tried using _runWithConnection or something similar I > always end up with an error of some kind. You might use query, queryAll, or queryOne with your _connection object. Ian |
From: Andy T. <an...@ha...> - 2003-08-01 13:22:56
|
Ian Bicking wrote: > This is the same bug that Javier was encountering. There's a fix in > CVS, or if SF CVS is slow (which it has been) and you want immediate > satisfaction, use this replacement function in SQLObject.py: > > def addNeedSet(obj, setCls, registry, attr): > try: > cls = findClass(setCls, registry=registry) > if callable(getattr(obj, attr, None)): > if not isinstance(getattr(obj, attr), type): > # Otherwise we got a class, which means we probably > # already set this column. > getattr(obj, attr)(cls) > else: > setattr(obj, attr, cls) > return > except KeyError: > pass > q = needSet.setdefault(registry, {}).setdefault(setCls, []) > q.append((obj, attr)) > > > > On Wed, 2003-07-30 at 07:17, Andy Todd wrote: > >>Hi, >> >>How do I define two (or more) relationships between two tables in my >>schema? I have a currencies table and a currency_rates table. Before I >>try and add the relationships their definitions are; >> [snip] >> Thanks Ian, works like a charm. And thanks for SQLObject too, its a gem. Regards, Andy -- -------------------------------------------------------------------------------- From the desk of Andrew J Todd esq - http://www.halfcooked.com/ |
From: Dave P. <dpo...@te...> - 2003-08-01 13:19:00
|
I'm trying to create a record in a database with a 'expires' field, which records are deleted whenever expires <= NOW(). I seem to have difficulty grasping how I can generate a query similar to: UPDATE records SET expires = NOW() + INTERVAL 30 DAY; I've tried something like: Records.expires = func.NOW('INTERVAL 30 DAY') Records.expires = func.NOW() + 'INTERVAL 30 DAY' Records.expires = func.NOW() + '+ INTERVAL 30 DAY' Records.expires = func.DATE_ADD(func.NOW(),'INTERVAL 30 DAY') as well as many other combinations, but none of them seemed to work. Any suggestion? -Dave. btw, how does one access the raw database connection from a SQLObject? I know I somehow have to go thru _connection and then something else, but everytime I've tried using _runWithConnection or something similar I always end up with an error of some kind. |
From: Ian B. <ia...@co...> - 2003-08-01 03:08:48
|
Sorry I haven't been keeping up on things recently, I've spent all my long-attention-span time on projects I have to get done before I leave on a camping trip. And now that I'm leaving I'll be much more absent. (And here I've responded to all these threads, and I won't be able to follow up much...) I'll be back mid-August. My inattentiveness now isn't any long-term indicator, it's just summer. Ian |
From: Ian B. <ia...@co...> - 2003-08-01 02:58:04
|
On Thu, 2003-07-31 at 18:28, Dave Poirier wrote: > How could one proceed to delete multiple records out of a database with > a single query? I've been trying various methods but I seem to always > end up with an "unhashable" error. > > desired query: DELETE * FROM accounts WHERE record_expiration <= NOW(); > > attempted SQLObject code: > > Accounts.delete( (Accounts.q.record_expiration <= func.NOW()) ) .delete() only supports getting a single id, which is why this isn't working for you. Basically deletes are hard, because there's a chance you might be deleting an instantiated object, and the object should know that it's been deleted. So you can't get the query you want, and in general won't be able to. > the only way I've been able to delete the records was true a rather more > db intensive method: > > for account in Accounts.select( (Accounts.q.record_expiration <= > func.NOW()) ): > Accounts.delete( account.id ) Yes, that's pretty much the way. Ideally .delete() should be able to take a list of ids and delete them all, checking the cache for any objects but not fetching rows that haven't been instantiated. Then .select() should have an option for only returning IDs, and not instantiating objects either. This would allow you to do the Right Thing while still keeping the number of queries down. At least until you start considering transactions, but I don't quite know what to think about deletes and transactions at this point. Ian |
From: Ian B. <ia...@co...> - 2003-08-01 02:49:49
|
On Thu, 2003-07-31 at 07:53, Luc Stepniewski wrote: > I've looked at Converters.py. I don't understand the way the information is > identified. When I look at it, it seems the information is identified only by > its basic types. > I added an output of obj.__class__ in sqlRepr() in Converters.py to see the > class name. The problem is that I get 'SQLObject.SQLBuilder.SQLConstant'. > What am I supposed to do this it? > SQLObject don't seem to support Bool postgreSQL type, so I looked at what was > returned by sqlRepr() when trying to interpret Bool keyword: it returns the > same thing: SQLObject.SQLBuilder.SQLConstant It looks like in general the converters aren't respecting the sqlRepr magic method. I checked in a fix for that, which should fix this problem (at least if that's all that's going on here). Ian |
From: Ian B. <ia...@co...> - 2003-08-01 02:47:13
|
On Thu, 2003-07-31 at 04:18, Luc Stepniewski wrote: > Hello, > > I'm trying to understand how SQLObject works, but I'm having problem > understanding the generated tables: > > If I want to create two tables, with one that has a relation one-to-many to > the other, I define an attribute with the ForeignKey() method, but when I do > this, I notice that there are no *real* restriction on the usage of that > generated column in the database (I'm using PostgreSQL). Here are more > explanations: No, SQLObject doesn't put in the REFERENCES constraint. You can certainly make a CREATE statement yourself instead of letting SQLObject do that, or you could do (untested): ForeignKey('societe', sqlType='INT REFERENCES societe (id)') Perhaps at some point we'll fix ForeignKey to do the right thing. Ian |
From: Ian B. <ia...@co...> - 2003-08-01 02:15:35
|
Someone requested a Gmane group (a Usenet news interface to the list). Here's the info for the interested: * Newsgroup name: gmane.comp.python.sqlobject * Mailing list address: sql...@li... * The gateway is bi-directional * Address encryption is off * Spam detection is on * The list is described as: "Discussion of Python object-relational mapper SQLObject" * News URL: news://news.gmane.org/gmane.comp.python.sqlobject * Web URL: http://news.gmane.org/thread.php?group=gmane.comp.python.sqlobject I'm giving them archives too, so hopefully their archiving will be better than SF's. Should we ask them to encrypt addresses? Personally I don't care -- all the spammers have my address anyway. Ian |
From: Ian B. <ia...@co...> - 2003-08-01 02:09:15
|
This is the same bug that Javier was encountering. There's a fix in CVS, or if SF CVS is slow (which it has been) and you want immediate satisfaction, use this replacement function in SQLObject.py: def addNeedSet(obj, setCls, registry, attr): try: cls = findClass(setCls, registry=registry) if callable(getattr(obj, attr, None)): if not isinstance(getattr(obj, attr), type): # Otherwise we got a class, which means we probably # already set this column. getattr(obj, attr)(cls) else: setattr(obj, attr, cls) return except KeyError: pass q = needSet.setdefault(registry, {}).setdefault(setCls, []) q.append((obj, attr)) On Wed, 2003-07-30 at 07:17, Andy Todd wrote: > Hi, > > How do I define two (or more) relationships between two tables in my > schema? I have a currencies table and a currency_rates table. Before I > try and add the relationships their definitions are; > > """ > class Currencies(SQLObject): > currencyCode=StringCol(length=6) > currencyDesc=StringCol(length=255) > exchanges=MultipleJoin('Exchanges', joinColumn='currency_id') > countries=MultipleJoin('Countries', joinColumn='currency_id') > > class CurrencyRates(SQLObject): > rateDate=DateTimeCol() > rate=Col() > """ > > Now I get confused when I add the two relationships (currency from and > currency to). I tried; > > """ > class Currencies(SQLObject): > currencyCode=StringCol(length=6) > currencyDesc=StringCol(length=255) > exchanges=MultipleJoin('Exchanges', joinColumn='currency_id') > countries=MultipleJoin('Countries', joinColumn='currency_id') > ratesFrom=MultipleJoin('CurrencyRates', joinColumn='currency_from_id') > ratesTo=MultipleJoin('CurrencyRates', joinColumn='currency_to_id') > > class CurrencyRates(SQLObject): > rateDate=DateTimeCol() > rate=Col() > currencyFrom=ForeignKey('Currencies') > currencyTo=ForeignKey('Currencies') > """ > > But this causes an error on import; > > """ > Traceback (most recent call last): > File "classes.py", line 51, in ? > class CurrencyRates(SQLObject): > File "C:\PROGRA~2\PYTHON22\Lib\site-packages\SQLObject\SQLObject.py", > line 233, in __new__ > newClass.addColumn(column) > File "C:\PROGRA~2\PYTHON22\Lib\site-packages\SQLObject\SQLObject.py", > line 503, in addColumn > '_SO_class_%s' % column.foreignKey) > File "C:\PROGRA~2\PYTHON22\Lib\site-packages\SQLObject\SQLObject.py", > line 102, in addNeedSet > getattr(obj, attr)(cls) > File "C:\PROGRA~2\PYTHON22\Lib\site-packages\SQLObject\SQLObject.py", > line 404, in __new__ > val._init(id, connection, selectResults) > File "C:\PROGRA~2\PYTHON22\Lib\site-packages\SQLObject\SQLObject.py", > line 662, in _init > selectResults = (connection or > self._connection)._SO_selectOne(self, dbNames) > File > "C:\PROGRA~2\PYTHON22\Lib\site-packages\SQLObject\DBConnection.py", line > 267, in _SO_selectOne > return self.queryOne("SELECT %s FROM %s WHERE %s = %s" % > File > "C:\PROGRA~2\PYTHON22\Lib\site-packages\SQLObject\SQLBuilder.py", line > 126, in sqlRepr > raise ValueError, "Unknown SQL builtin type: %s for %s" % \ > ValueError: Unknown SQL builtin type: <class > 'SQLObject.SQLObject.MetaSQLObject'> for <class '__main__.Currencies'> > """ > > Any suggestions? Apologies if this question has already been answered. > > Regards, > Andy |
From: Ian B. <ia...@co...> - 2003-08-01 02:05:52
|
On Tue, 2003-07-29 at 01:21, Javier Ruere wrote: > I was trying to make a BoolCol class just to learn how things work. > I grabed the StringCol and SOStringCol classes, changed things and the > generated SQL was right. This was very easy to make!! > Now I was wondering if there is a way I can define filters for the > data, both in it's way in and out of the DB, so that I can take whatever > the Python type is and change it to what the DB wants. In this case > change the int to a '1' or the like for SQLite and 'TRUE' for PostgreSQL > (don't know MySQL) and the inverse operation when read from the DB. Is > there a way to do this? No, there isn't a way to do this generally. It's on the top of my hard-things-to-do list for SQLObject (it's not terribly hard, but it's not trivial). Until then you have to do things like: def _set_someBool(self, value): if value: value = 't' else: value = 'f' self._SO_set_someBool(self, value) > PS: I'm developing an app from scratch, should I be using the SQLObject > from CVS? Has it's structure changed much from v0.4? Structure hasn't changed, just some bug fixes. Structure probably will change, though, when I have a chance to commit some more time to SQLObject (but that's at least three weeks away) -- I am planning some significant renaming. But handling that change should be a simple search-and-replace, and I'll document the replacements. I'm going to avoid requiring any non-trivial changes to people's code that uses SQLObject (renaming is trivial, restructuring isn't). Ian |
From: Ian B. <ia...@co...> - 2003-08-01 01:59:32
|
On Mon, 2003-07-28 at 08:41, Brad Bollenbach wrote: > The cleanest way is to figure out how we want to define composite > primary keys. > > Like this? > > class SiteMonitor(SQLObject): > site = ForeignKey("Site") > monitor = ForeignKey("Monitor") > > _primary_key = (site, monitor) I'm thinking: id = ('site', 'monitor') or: id = (site, monitor) both should be equivalent. This goes along with using: id = StringCol() when you have a non-integer primary key. When using a composite keys, obj.id should return a tuple of the respective columns -- ids should be hashable and immutable, which fits tuples nicely. Ian |
From: Ian B. <ia...@co...> - 2003-08-01 01:58:44
|
On Sat, 2003-07-26 at 16:49, Javier Ruere wrote: > Hi, I started using SQLObject today and I like it a lot. > There are a couple of questions I have for which I could find no > answers on the mailing list. > First, why are transactions not supported in SQLite? I believe the DB > has that ability. They should be, though I haven't really tried it. Sometime I have to really try transactions out more thoroughly and document them better. What support there is for transactions is not database-specific. > Second, I could not get the code in the attached file (prueba.py) > working. Is what I'm trying to do there forbiden? No, you just found a bug related to having two ForeignKey('Place') -- SQLObject has a fixup stage where 'Place' gets replaced with the real class, and funny stuff was happening when that got hit twice. It's fixed now in CVS. > Third, the following code gets a type error when run in the interactive > shell: > > import SQLObject > SQLObject.__dict__ Ah... I used __getattr__ without checking for special methods. That should be fixed in CVS now as well. (Note pserver is a day behind sometimes) Ian |
From: Ian B. <ia...@co...> - 2003-08-01 01:56:13
|
On Mon, 2003-07-28 at 03:31, Fran=E7ois Girault wrote: > Hi all, >=20 > in some cases, there's additionnal datas in relation table. For > example, the rank if the relation is ordered, or a lock object for > edition...=20 I'm not entirely clear on what you want here. I think you are describing a whole set of features, and maybe you're thinking about how to describe those. I'm not actually very happy with the _columns (now defunct), _idName, _joins, etc., style. So alternative syntaxes are good. If the feature needs a name (like columns and joins do), then attributes is the way to go. Neither ordering or locks need a name, though -- they would be used implicitly in other areas. __order__ and __lock__ are possibilities -- at least they are obviously magic, but I'm also a little reluctant to overuse the double-underscore variables. Though I don't really believe the idea that double underscore variables are preserved for Python. Python grows such variables very slowly. I'm open to other ideas. Nested classes, like: class InvoiceItem(SQLObject): invoiceOrder =3D IntCol() class meta: orderBy =3D invoiceOrder lock =3D 'optimistic' Certainly easily extensible, without a not-so-bad syntax. It would lead to the separate mapping object that some people sometime want... But maybe that's not what you are asking about ;) I'm not entirely clear on the rest of this... > It's very common to see that. >=20 > So I'm thinking about how to implement this : >=20 > - one (ugly but usuable) way to do that without modifying SQLObject > is to describe the join like an entity with 2 foreign keys, and then > specifying the additionnal columns as usual. >=20 > - a cleaner way would be to add the columns to the join declaration, > and then attach these columns to the entities retrevied when > performing the join. I don't think this would be threadsafe -- things shouldn't be attached to SQLObject instances unless they really belong to the instance, not the instance in a specific context. But as I reread this, I'm really not clear about what you're trying to do. An example might clarify (though I probably won't be able to follow up) Ian |
From: Edmund L. <el...@in...> - 2003-08-01 01:44:13
|
Ian Bicking wrote: > Hmmm... I have a unit test that I think should cover this particular > case (JoinTest2.test), so I suspect I won't be able to reproduce the > problem. Are there transactions or threads involved? Really? I'm not doing anything fancy... no transactions or threads. I ran the test manually from the command line. The only thing that might interfere with this is that Webware and code using SO was running in a separate window. Let me see if I can't write a short snippet that will reproduce the problem. I'll get back to you. ...Edmund. |
From: Ian B. <ia...@co...> - 2003-08-01 01:33:28
|
On Sun, 2003-07-27 at 20:41, Edmund Lian wrote: > I have a one-to-many relationship of the form: > > class A(SQLObject): > ... > things = MultipleJoin("B") > > class B(SQLObject): > ... > aThing = ForeignKey("A") > > > If I check what things are in A via something like aObj.things, then > delete one of the B objects that appears in the list directly via > bObj.destroySelf(), executing the aObj.things again raises a > SQLObjectNotFound error for the just deleted B instance. > > Executing aObj.things a second time works though. So there appears to be > some kind of cache synchronization issue at play here. Is there some way > to force an object to refresh it's cached values? Hmmm... I have a unit test that I think should cover this particular case (JoinTest2.test), so I suspect I won't be able to reproduce the problem. Are there transactions or threads involved? Ian |