Thread: [SQLObject] func.NOW + INTERVAL
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
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 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: 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 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 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 |