Permalink
Browse files

Fixed broken DEFAULT in OPERATOR CLASS.

It was generated something like:

    CREATE OPERATOR CLASS oc1 DEFAULT TrueFOR TYPE ...
  • Loading branch information...
dvarrazzo committed Dec 11, 2011
1 parent 1b55c1e commit 25338a448306a0255bd4cea3d6df397310e92e20
Showing with 45 additions and 1 deletion.
  1. +1 −1 pyrseas/dbobject/operclass.py
  2. +44 −0 tests/dbobject/test_operclass.py
@@ -49,7 +49,7 @@ def create(self):
stmts = []
dflt = ''
if hasattr(self, 'default') and self.default:
- dflt = "DEFAULT %s" % self.default
+ dflt = "DEFAULT "
clauses = []
for (strat, oper) in self.operators.items():
clauses.append("OPERATOR %d %s" % (strat, oper))
@@ -5,6 +5,18 @@
from utils import PyrseasTestCase, fix_indent
+CREATE_TYPE_STMT = """
+CREATE TYPE myint;
+CREATE FUNCTION myintin(cstring) RETURNS myint AS 'int4in' LANGUAGE internal;
+CREATE FUNCTION myintout(myint) RETURNS cstring AS 'int4out' LANGUAGE internal;
+CREATE TYPE myint (INPUT = myintin, OUTPUT = myintout);
+CREATE FUNCTION myinteq(myint,myint) RETURNS boolean AS 'int4eq' LANGUAGE internal;
+CREATE FUNCTION myintlt(myint,myint) RETURNS boolean AS 'int4lt' LANGUAGE internal;
+CREATE OPERATOR < (PROCEDURE = myintlt, LEFTARG = myint, RIGHTARG = myint);
+CREATE OPERATOR = (PROCEDURE = myinteq, LEFTARG = myint, RIGHTARG = myint);
+CREATE FUNCTION btmyintcmp(myint,myint) RETURNS integer AS 'btint4cmp' LANGUAGE internal;
+"""
+
CREATE_STMT = "CREATE OPERATOR CLASS oc1 FOR TYPE integer USING btree " \
"AS OPERATOR 1 <, OPERATOR 3 =, FUNCTION 1 btint4cmp(integer,integer)"
CREATE_STMT_LONG = "CREATE OPERATOR CLASS oc1 FOR TYPE integer USING btree " \
@@ -27,6 +39,22 @@ def test_map_operclass(self):
self.assertEqual(dbmap['schema public'][
'operator class oc1 using btree'], expmap)
+ def test_map_operclass_default(self):
+ "Map a default operator class"
+ expmap = {'type': 'myint',
+ 'default': True,
+ 'operators': {
+ 1: '<(myint,myint)', 3: '=(myint,myint)'},
+ 'functions': {1: 'btmyintcmp(myint,myint)'}}
+ self.db.execute(CREATE_TYPE_STMT)
+ dbmap = self.db.execute_and_map(
+ CREATE_STMT
+ .replace('integer', 'myint')
+ .replace('int4', 'myint')
+ .replace(' FOR ', ' DEFAULT FOR '))
+ self.assertEqual(dbmap['schema public'][
+ 'operator class oc1 using btree'], expmap)
+
def test_map_operclass_comment(self):
"Map an operator class comment"
self.db.execute(CREATE_STMT)
@@ -49,6 +77,22 @@ def test_create_operclass(self):
dbsql = self.db.process_map(inmap)
self.assertEqual(fix_indent(dbsql[0]), CREATE_STMT_LONG)
+ def test_create_operclass_default(self):
+ "Create a default operator class"
+ inmap = self.std_map()
+ inmap['schema public'].update({'operator class oc1 using btree': {
+ 'default': True,
+ 'type': 'myint', 'operators': {
+ 1: '<(myint,myint)', 3: '=(myint,myint)'},
+ 'functions': {1: 'btmyintcmp(myint,myint)'}}})
+ self.db.execute(CREATE_TYPE_STMT)
+ dbsql = self.db.process_map(inmap)
+ self.assertEqual(fix_indent(dbsql[0]),
+ CREATE_STMT_LONG
+ .replace(' FOR ', ' DEFAULT FOR ')
+ .replace('integer', 'myint')
+ .replace('int4', 'myint'))
+
def test_create_operclass_in_schema(self):
"Create a operator within a non-public schema"
self.db.execute("CREATE SCHEMA s1")

0 comments on commit 25338a4

Please sign in to comment.