Exemplo n.º 1
0
def get_columns_07x_fixed(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 (pyflake)
    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)
        #### if default:
        ####    default = re.sub(r"^\'|\'$", '', default)
        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.º 2
0
def get_columns_07x_fixed(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 (pyflake)
    columns = []
    while True:
        row = c.fetchone()
        if row is None:
            break
        # BUILDBOT: unused `has_default` removed
        (name, type_, nullable, default,
         primary_key) = (row[1], row[2].upper(), not row[3], row[4], row[5])
        name = re.sub(r'^\"|\"$', '', name)
        # if default:
        #    default = re.sub(r"^\'|\'$", '', default)
        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 get_columns_06x_fixed(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 (pyflake)
    columns = []
    while True:
        row = c.fetchone()
        if row is None:
            break
        # BUILDBOT: unused `has_default` removed
        (name, type_, nullable, default, primary_key) = (
            row[1], row[2].upper(), not row[3], row[4], row[5])
        name = re.sub(r'^\"|\"$', '', name)
        # if default:
        #     default = re.sub(r"^\'|\'$", '', default)
        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]
        except KeyError:
            util.warn("Did not recognize type '%s' of column '%s'" %
                      (coltype, name))
            coltype = sqltypes.NullType
        if args is not None:
            args = re.findall(r'(\d+)', args)
            coltype = coltype(*[int(a) for a in args])

        columns.append({
            'name': name,
            'type': coltype,
            'nullable': nullable,
            'default': default,
            'primary_key': primary_key
        })
    return columns