Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed broken DEFAULT in OPERATOR CLASS.

It was generated something like:

    CREATE OPERATOR CLASS oc1 DEFAULT TrueFOR TYPE ...
  • Loading branch information...
commit 25338a448306a0255bd4cea3d6df397310e92e20 1 parent 1b55c1e
Daniele Varrazzo dvarrazzo authored
2  pyrseas/dbobject/operclass.py
@@ -49,7 +49,7 @@ def create(self):
49 49 stmts = []
50 50 dflt = ''
51 51 if hasattr(self, 'default') and self.default:
52   - dflt = "DEFAULT %s" % self.default
  52 + dflt = "DEFAULT "
53 53 clauses = []
54 54 for (strat, oper) in self.operators.items():
55 55 clauses.append("OPERATOR %d %s" % (strat, oper))
44 tests/dbobject/test_operclass.py
@@ -5,6 +5,18 @@
5 5
6 6 from utils import PyrseasTestCase, fix_indent
7 7
  8 +CREATE_TYPE_STMT = """
  9 +CREATE TYPE myint;
  10 +CREATE FUNCTION myintin(cstring) RETURNS myint AS 'int4in' LANGUAGE internal;
  11 +CREATE FUNCTION myintout(myint) RETURNS cstring AS 'int4out' LANGUAGE internal;
  12 +CREATE TYPE myint (INPUT = myintin, OUTPUT = myintout);
  13 +CREATE FUNCTION myinteq(myint,myint) RETURNS boolean AS 'int4eq' LANGUAGE internal;
  14 +CREATE FUNCTION myintlt(myint,myint) RETURNS boolean AS 'int4lt' LANGUAGE internal;
  15 +CREATE OPERATOR < (PROCEDURE = myintlt, LEFTARG = myint, RIGHTARG = myint);
  16 +CREATE OPERATOR = (PROCEDURE = myinteq, LEFTARG = myint, RIGHTARG = myint);
  17 +CREATE FUNCTION btmyintcmp(myint,myint) RETURNS integer AS 'btint4cmp' LANGUAGE internal;
  18 +"""
  19 +
8 20 CREATE_STMT = "CREATE OPERATOR CLASS oc1 FOR TYPE integer USING btree " \
9 21 "AS OPERATOR 1 <, OPERATOR 3 =, FUNCTION 1 btint4cmp(integer,integer)"
10 22 CREATE_STMT_LONG = "CREATE OPERATOR CLASS oc1 FOR TYPE integer USING btree " \
@@ -27,6 +39,22 @@ def test_map_operclass(self):
27 39 self.assertEqual(dbmap['schema public'][
28 40 'operator class oc1 using btree'], expmap)
29 41
  42 + def test_map_operclass_default(self):
  43 + "Map a default operator class"
  44 + expmap = {'type': 'myint',
  45 + 'default': True,
  46 + 'operators': {
  47 + 1: '<(myint,myint)', 3: '=(myint,myint)'},
  48 + 'functions': {1: 'btmyintcmp(myint,myint)'}}
  49 + self.db.execute(CREATE_TYPE_STMT)
  50 + dbmap = self.db.execute_and_map(
  51 + CREATE_STMT
  52 + .replace('integer', 'myint')
  53 + .replace('int4', 'myint')
  54 + .replace(' FOR ', ' DEFAULT FOR '))
  55 + self.assertEqual(dbmap['schema public'][
  56 + 'operator class oc1 using btree'], expmap)
  57 +
30 58 def test_map_operclass_comment(self):
31 59 "Map an operator class comment"
32 60 self.db.execute(CREATE_STMT)
@@ -49,6 +77,22 @@ def test_create_operclass(self):
49 77 dbsql = self.db.process_map(inmap)
50 78 self.assertEqual(fix_indent(dbsql[0]), CREATE_STMT_LONG)
51 79
  80 + def test_create_operclass_default(self):
  81 + "Create a default operator class"
  82 + inmap = self.std_map()
  83 + inmap['schema public'].update({'operator class oc1 using btree': {
  84 + 'default': True,
  85 + 'type': 'myint', 'operators': {
  86 + 1: '<(myint,myint)', 3: '=(myint,myint)'},
  87 + 'functions': {1: 'btmyintcmp(myint,myint)'}}})
  88 + self.db.execute(CREATE_TYPE_STMT)
  89 + dbsql = self.db.process_map(inmap)
  90 + self.assertEqual(fix_indent(dbsql[0]),
  91 + CREATE_STMT_LONG
  92 + .replace(' FOR ', ' DEFAULT FOR ')
  93 + .replace('integer', 'myint')
  94 + .replace('int4', 'myint'))
  95 +
52 96 def test_create_operclass_in_schema(self):
53 97 "Create a operator within a non-public schema"
54 98 self.db.execute("CREATE SCHEMA s1")

0 comments on commit 25338a4

Please sign in to comment.
Something went wrong with that request. Please try again.