Changeset 792 for trunk/tests


Ignore:
Timestamp:
Jan 28, 2016, 2:54:34 PM (3 years ago)
Author:
cito
Message:

Using ARRAY and ROW constructor in pgdb again

Using the special input syntax for quoting arrays and rows had some
advantages, but one big disadvantage, namely the missing type information.
Therefore, this change has been reverted, we now use ARRAY and ROW
constructor syntax again to quote lists and tuples. See comments.

The code has become simpler again and doesn't need the re module any more.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/test_dbapi20.py

    r791 r792  
    484484                " (n smallint, i int[], t text[][])" % table)
    485485            params = [(n, v[0], v[1]) for n, v in enumerate(values)]
    486             cur.executemany(
    487                 "insert into %s values (%%d,%%s,%%s)" % table, params)
     486            # Note that we must explicit casts because we are inserting
     487            # empty arrays.  Otherwise this is not necessary.
     488            cur.executemany("insert into %s values"
     489                " (%%d,%%s::int[],%%s::text[][])" % table, params)
    488490            cur.execute("select i, t from %s order by n" % table)
    489491            self.assertEqual(cur.description[0].type_code, pgdb.ARRAY)
     
    541543
    542544    def test_select_record(self):
    543         values = (1, 25000, 2.5, 'hello', 'Hello World!', 'Hello, World!',
     545        value = (1, 25000, 2.5, 'hello', 'Hello World!', 'Hello, World!',
    544546            '(test)', '(x,y)', ' x y ', 'null', None)
    545547        con = self._connect()
    546548        try:
    547549            cur = con.cursor()
    548             # Note that %s::record does not work on input unfortunately
    549             # ("input of anonymous composite types is not implemented").
    550             # so we need to resort to a row constructor instead.
    551             row = ','.join(["%s"] * len(values))
    552             cur.execute("select ROW(%s) as test_record" % row, values)
     550            cur.execute("select %s as test_record", [value])
    553551            self.assertEqual(cur.description[0].name, 'test_record')
    554552            self.assertEqual(cur.description[0].type_code, 'record')
     
    559557        # untyped record (an anonymous composite type). For the same
    560558        # reason this is also a normal tuple, not a named tuple.
    561         text_values = tuple(None if v is None else str(v) for v in values)
    562         self.assertEqual(row, text_values)
     559        text_row = tuple(None if v is None else str(v) for v in value)
     560        self.assertEqual(row, text_row)
    563561
    564562    def test_custom_type(self):
Note: See TracChangeset for help on using the changeset viewer.