~sidnei/storm/mssql-support

« back to all changes in this revision

Viewing changes to tests/databases/postgres.py

  • Committer: Gustavo Niemeyer
  • Date: 2007-08-07 23:15:09 UTC
  • mfrom: (156.1.8 preset-primary-key)
  • Revision ID: gustavo@niemeyer.net-20070807231509-iw58uiygzuef5wth
Merged preset-primary-key branch [r=radix,jkakar] [f=126080]

This branch introduces a new hook which allows backends to modify
variables which are part of the primary key of an object before
they are inserted in the database.  Also, lazy values may now be
used in the primary key, which means that it's possible to set these
primary variables to SQL expressions if needed.

Other minor changes include an optimization in Result: it will
preset the raw cursor's arraysize to a better value if it's found
to be 1.  Result.__iter__() was also fixed to parse rows through
the from_database hook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from storm.database import create_database
27
27
from storm.variables import UnicodeVariable, DateTimeVariable
28
28
from storm.variables import ListVariable, IntVariable, Variable
29
 
from storm.expr import Union, Select, Alias, SQLRaw, State
 
29
from storm.expr import Union, Select, Alias, SQLRaw, State, Sequence
30
30
 
31
31
from tests.databases.base import DatabaseTest, UnsupportedDatabaseTest
32
32
from tests.helper import TestHelper, MakePath
41
41
        self.database = create_database(os.environ["STORM_POSTGRES_URI"])
42
42
 
43
43
    def create_tables(self):
 
44
        self.connection.execute("CREATE TABLE number "
 
45
                                "(one INTEGER, two INTEGER, three INTEGER)")
44
46
        self.connection.execute("CREATE TABLE test "
45
47
                                "(id SERIAL PRIMARY KEY, title VARCHAR)")
46
48
        self.connection.execute("CREATE TABLE datetime_test "
199
201
        result = self.connection.execute(expr)
200
202
        self.assertEquals(result.get_all(), [(1,), (1,)])
201
203
 
 
204
    def test_sequence(self):
 
205
        expr1 = Select(Sequence("test_id_seq"))
 
206
        expr2 = "SELECT currval('test_id_seq')"
 
207
        value1 = self.connection.execute(expr1).get_one()[0]
 
208
        value2 = self.connection.execute(expr2).get_one()[0]
 
209
        value3 = self.connection.execute(expr1).get_one()[0]
 
210
        self.assertEquals(value1, value2)
 
211
        self.assertEquals(value3-value1, 1)
 
212
 
202
213
 
203
214
class PostgresUnsupportedTest(UnsupportedDatabaseTest, TestHelper):
204
215