Commits

Mike Bayer committed 1a8d9c3

- fixes to PG unicode table/sequence reflection/create/drops

Comments (0)

Files changed (3)

lib/sqlalchemy/ansisql.py

             if isinstance(column.default.arg, basestring):
                 return "'%s'" % column.default.arg
             else:
-                return str(self._compile(column.default.arg, None))
+                return unicode(self._compile(column.default.arg, None))
         else:
             return None
 

lib/sqlalchemy/databases/postgres.py

         return bool( not not cursor.rowcount )
 
     def has_sequence(self, connection, sequence_name):
-        cursor = connection.execute('''SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN ( SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%%' AND nspname != 'information_schema' AND relname = %(seqname)s);''', {'seqname': sequence_name})
+        cursor = connection.execute('''SELECT relname FROM pg_class WHERE relkind = 'S' AND relnamespace IN ( SELECT oid FROM pg_namespace WHERE nspname NOT LIKE 'pg_%%' AND nspname != 'information_schema' AND relname = %(seqname)s);''', {'seqname': sequence_name.encode(self.encoding)})
         return bool(not not cursor.rowcount)
 
     def is_disconnect(self, e):
             ORDER BY a.attnum
         """ % schema_where_clause
 
-        s = sql.text(SQL_COLS, bindparams=[sql.bindparam('table_name', type_=sqltypes.Unicode), sql.bindparam('schema', type_=sqltypes.Unicode)], typemap={'attname':sqltypes.Unicode})
+        s = sql.text(SQL_COLS, bindparams=[sql.bindparam('table_name', type_=sqltypes.Unicode), sql.bindparam('schema', type_=sqltypes.Unicode)], typemap={'attname':sqltypes.Unicode, 'default':sqltypes.Unicode})
         c = connection.execute(s, table_name=table.name,
                                   schema=table.schema)
         rows = c.fetchall()
 class PGSchemaDropper(ansisql.ANSISchemaDropper):
     def visit_sequence(self, sequence):
         if not sequence.optional and (not self.checkfirst or self.dialect.has_sequence(self.connection, sequence.name)):
-            self.append("DROP SEQUENCE %s" % sequence.name)
+            self.append("DROP SEQUENCE %s" % self.preparer.format_sequence(sequence))
             self.execute()
 
 class PGDefaultRunner(ansisql.ANSIDefaultRunner):

test/engine/reflection.py

 
             names = set([u'plain', u'Unit\u00e9ble', u'\u6e2c\u8a66'])
             for name in names:
-                Table(name, metadata, Column('id', Integer, primary_key=True))
+                Table(name, metadata, Column('id', Integer, Sequence(name + "_id_seq"), primary_key=True))
             metadata.create_all()
 
             reflected = set(bind.table_names())