Exemplo n.º 1
0
    def _get_column_info(self, name, type_, nullable, default, primary_key):

        match = re.match(r'(\w+)(\(.*?\))?', type_)
        if match:
            coltype = match.group(1)
            args = match.group(2)
        else:
            coltype = "VARCHAR"
            args = ''
        try:
            coltype = self.ischema_names[coltype]
            if args is not None:
                args = re.findall(r'(\d+)', args)
                coltype = coltype(*[int(a) for a in args])
        except KeyError:
            util.warn("Did not recognize type '%s' of column '%s'" %
                      (coltype, name))
            coltype = sqltypes.NullType()

        if default is not None:
            default = str(default)

        return {
            'name': name,
            'type': coltype,
            'nullable': nullable,
            'default': default,
            'autoincrement': default is None,
            'primary_key': primary_key
        }
Exemplo n.º 2
0
    def get_columns(self, connection, table_name, schema=None, **kw):
        quote = self.identifier_preparer.quote_identifier
        if schema is not None:
            pragma = "PRAGMA %s." % quote(schema)
        else:
            pragma = "PRAGMA "
        qtable = quote(table_name)
        c = _pragma_cursor(
            connection.execute("%stable_info(%s)" % (pragma, qtable)))
        found_table = False
        columns = []
        while True:
            row = c.fetchone()
            if row is None:
                break
            (name, type_, nullable, default, has_default, primary_key) = \
                (row[1], row[2].upper(), not row[3],
                row[4], row[4] is not None, row[5])
            name = re.sub(r'^\"|\"$', '', name)
            match = re.match(r'(\w+)(\(.*?\))?', type_)
            if match:
                coltype = match.group(1)
                args = match.group(2)
            else:
                coltype = "VARCHAR"
                args = ''
            try:
                coltype = self.ischema_names[coltype]
                if args is not None:
                    args = re.findall(r'(\d+)', args)
                    coltype = coltype(*[int(a) for a in args])
            except KeyError:
                util.warn("Did not recognize type '%s' of column '%s'" %
                          (coltype, name))
                coltype = sqltypes.NullType()

            columns.append({
                'name': name,
                'type': coltype,
                'nullable': nullable,
                'default': default,
                'autoincrement': default is None,
                'primary_key': primary_key
            })
        return columns
Exemplo n.º 3
0
 def _type_affinity_fixture(self):
     return [
         ("LONGTEXT", sqltypes.TEXT()),
         ("TINYINT", sqltypes.INTEGER()),
         ("MEDIUMINT", sqltypes.INTEGER()),
         ("INT2", sqltypes.INTEGER()),
         ("UNSIGNED BIG INT", sqltypes.INTEGER()),
         ("INT8", sqltypes.INTEGER()),
         ("CHARACTER(20)", sqltypes.TEXT()),
         ("CLOB", sqltypes.TEXT()),
         ("CLOBBER", sqltypes.TEXT()),
         ("VARYING CHARACTER(70)", sqltypes.TEXT()),
         ("NATIVE CHARACTER(70)", sqltypes.TEXT()),
         ("BLOB", sqltypes.BLOB()),
         ("BLOBBER", sqltypes.NullType()),
         ("DOUBLE PRECISION", sqltypes.REAL()),
         ("FLOATY", sqltypes.REAL()),
         ("NOTHING WE KNOW", sqltypes.NUMERIC()),
     ]
Exemplo n.º 4
0
def Geometry(*args, **kwargs):
    return sa_types.NullType()