Permalink
Browse files

Add support for CATEGORY and PREFERRED to TYPEs.

 * pyrseas/dbobject/dbtype.py (BaseType.create): Handle new clauses.
   (TypeDict.query): Retrieve new catalog columns.
   (TypeDict._from_catalog): Delete category on non-base types.
 * tests/dbobject/test_type.py: Add test for category.
  • Loading branch information...
1 parent 033f247 commit a65b8128fe5af0175722b0e9ee445c01fbd4be3f @jmafc jmafc committed Jan 5, 2012
Showing with 19 additions and 2 deletions.
  1. +6 −1 pyrseas/dbobject/dbtype.py
  2. +13 −1 tests/dbobject/test_type.py
@@ -79,6 +79,10 @@ def create(self):
opt_clauses.append("STORAGE = %s" % self.storage)
if hasattr(self, 'delimiter'):
opt_clauses.append("DELIMITER = '%s'" % self.delimiter)
+ if hasattr(self, 'category'):
+ opt_clauses.append("CATEGORY = '%s'" % self.category)
+ if hasattr(self, 'preferred'):
+ opt_clauses.append("PREFERRED = TRUE")
stmts.append("CREATE TYPE %s (\n INPUT = %s,"
"\n OUTPUT = %s%s%s)" % (
self.qualname(), self.input, self.output,
@@ -204,6 +208,7 @@ class TypeDict(DbObjectDict):
typanalyze::regproc AS analyze,
typlen AS internallength, typalign AS alignment,
typstorage AS storage, typdelim AS delimiter,
+ typcategory AS category, typispreferred AS preferred,
obj_description(t.oid, 'pg_type') AS description
FROM pg_type t
JOIN pg_namespace n ON (typnamespace = n.oid)
@@ -226,7 +231,7 @@ def _from_catalog(self):
del dbtype.receive, dbtype.send
del dbtype.typmod_in, dbtype.typmod_out, dbtype.analyze
del dbtype.internallength, dbtype.alignment, dbtype.storage
- del dbtype.delimiter
+ del dbtype.delimiter, dbtype.category
if kind == 'd':
self[(sch, typ)] = Domain(**dbtype.__dict__)
elif kind == 'e':
@@ -107,10 +107,22 @@ def test_base_type(self):
self.db.execute(CREATE_FUNC_OUT)
expmap = {'input': 't1textin', 'output': 't1textout',
'internallength': 'variable', 'alignment': 'int4',
- 'storage': 'plain'}
+ 'storage': 'plain', 'category': 'U'}
dbmap = self.db.execute_and_map(CREATE_TYPE_STMT)
self.assertEqual(dbmap['schema public']['type t1'], expmap)
+ def test_base_type_category(self):
+ "Map a base type"
+ self.db.execute(CREATE_SHELL_STMT)
+ self.db.execute(CREATE_FUNC_IN)
+ self.db.execute(CREATE_FUNC_OUT)
+ expmap = {'input': 't1textin', 'output': 't1textout',
+ 'internallength': 'variable', 'alignment': 'int4',
+ 'storage': 'plain', 'category': 'S'}
+ dbmap = self.db.execute_and_map("CREATE TYPE t1 (INPUT = t1textin, "
+ "OUTPUT = t1textout, CATEGORY = 'S')")
+ self.assertEqual(dbmap['schema public']['type t1'], expmap)
+
class BaseTypeToSqlTestCase(PyrseasTestCase):
"""Test SQL generation from input base types"""

0 comments on commit a65b812

Please sign in to comment.