Wednesday
14
Sep 2005

Using SQL functions as default field values

(5:39 pm) Tags: [Software]

From the sqlobject mailing (thanks to Andrew Bennetts):

from sqlobject.sqlbuilder import SQLConstant
UTC_NOW = SQLConstant("CURRENT_TIMESTAMP AT TIME ZONE 'UTC'")
DEFAULT = SQLConstant("DEFAULT")

If you use lazyUpdates then you will need to explicitly sync an object
before reading its column back after assigning a constant to it. Example of
what I mean:

# Assume Foo is an SQLObject with a DateTimeCol called lastupdated
foo = Foo.get(1)
foo.lastupdated = UTC_NOW
print foo.lastupdated # prints UTC_NOW object
foo.sync()
print foo.lastupdated # prints an actual datetime, as stored in the db.

Aside from that, it works quite smoothly.

Popularity: 21%

Comments: (1)

Why I develop in Python versus Java

(6:55 am) Tags: [Software, Why I like...]

Java:

  1. Write code
  2. Compile
  3. Build JAR
  4. Stop Server
  5. copy JAR
  6. rebuild WAR
  7. Start Server
  8. Test code

Python:

  1. Write code
  2. Ctrl+C
  3. Up arrow, ENTER
  4. Test Code

Note the added Java bits can be automated with Ant and the like, but still take TIME.

Popularity: 28%

Comments: (0)