On 07/22/2011 10:48 AM, Jan Pazdziora wrote:
On Wed, Jul 20, 2011 at 04:39:14PM +0200, Ionuț Arțăriși wrote:
Hello,

We've recently come upon a bug when trying to insert a string of 1024
unicode characters into a database column of VARCHAR2(1024 BYTE). Rather
than dealing with string encoding transformations everywhere this
issue pops up
in the code, I thought that modifying the database schema would be the
better solution.

BYTE seems to be the default for the Oracle database, but unicode
strings would map better to VARCHAR2(1024 CHAR).

The problem is that I couldn't find any way to set this in the table
schema files and get it past chameleon. chameleon just doesn't have the
right grammar defined to parse VARCHAR2(1024 CHAR) or "alter session set
nls_length_semantics=char".

So I was wondering if you guys know more about this problem or a better
solution than patching chameleon.
Replacing chameleon with a custom script (sed? perl?) which would do
the equivalent transformation but be easier to be extended would be my
preferred option.

I'll be happy to review a patch which would do that.

Adding a char to varchar2 definitions would then be step to, and piece
of cake.

Hm... writing another tool to do what chameleon currently does seems like a massive undertaking.

Besides, the chameleon code looks quite clean and easy enough to extend. Here's a patch that allows specifying the VARCHAR2 data type (for lack of a better name).

Another question would be: do you guys have commit access to the upstream chameleon project?

-Ionuț
Index: parser.py
===================================================================
--- parser.py   (revision 8)
+++ parser.py   (working copy)
@@ -40,6 +40,7 @@
     'UNIQUE',
     'CONSTRAINT',
     'REFERENCES',
+    'BYTE',
     'BYTEA',
     'BLOB',
     'CHAR',
@@ -461,7 +462,14 @@
         p[0] = ','.join((p[1], p[3]))
     else:
         p[0] = p[1]
-        
+
+def p_datatype(p):
+    """
+    datatype : CHAR
+        | BYTE
+    """
+    p[0] = p[1]
+
 def p_type(p):
     """
     type : CHAR
@@ -470,6 +478,7 @@
         | CHAR LPAREN DIGITS RPAREN
         | VARCHAR LPAREN DIGITS RPAREN
         | VARCHAR2 LPAREN DIGITS RPAREN
+        | VARCHAR2 LPAREN DIGITS datatype RPAREN
         | NUMBER
         | NUMBER LPAREN precision RPAREN
         | NUMERIC
@@ -482,8 +491,10 @@
         | EVR_T
     """
     dt = Type(p[1])
-    if len(p) == 5:
+    if len(p) >= 5:
         dt.precision = p[3]
+    if len(p) == 6:
+        dt.datatype = p[4]
     p[0] = dt
         
 def p_notnull(p):
Index: model.py
===================================================================
--- model.py    (revision 8)
+++ model.py    (working copy)
@@ -150,9 +150,10 @@
 
 class Type(Object):
 
-    def __init__(self, name, precision=None):
+    def __init__(self, name, precision=None, datatype=None):
         Object.__init__(self, name)
         self.precision = precision
+        self.datatype = datatype
         
         
 class Index(Object):
@@ -349,4 +350,4 @@
         self.terms = terms
 
 class Include(Object):
-    pass
\ No newline at end of file
+    pass
Index: oracle.py
===================================================================
--- oracle.py   (revision 8)
+++ oracle.py   (working copy)
@@ -92,7 +92,7 @@
         'SMALLINT': lambda t : model.Type('NUMBER', 5),
         'INTEGER' : lambda t : model.Type('NUMBER', 10),
         'BIGINT'  : lambda t : model.Type('NUMBER', 19),
-        'VARCHAR' : lambda t : model.Type('VARCHAR2', t.precision),
+        'VARCHAR' : lambda t : model.Type('VARCHAR2', t.precision, t.datatype),
         'BYTEA'   : lambda t : model.Type('BLOB'),
     }
     
@@ -107,9 +107,10 @@
         t = self.xlated(type)
         s = []
         s.append(t.name.upper())
-        if t.precision is not None:
-            s.append('(')
-            s.append(str(t.precision))
+        if t.precision:
+            s.append('(' + str(t.precision))
+            if t.datatype:
+                s.append(' ' + str(t.datatype))
             s.append(')')
         return self.join(s)
 
_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to