コード例 #1
0
 def get_columns(self, table, schema=None):
     cursor = self.execute_sql(
         f'PRAGMA "{schema or "main"}".table_info("{table}")')
     return [
         ColumnMetadata(r[1], r[2], not r[3], bool(r[5]), table, r[4])
         for r in cursor.fetchall()
     ]
コード例 #2
0
ファイル: MyDataset.py プロジェクト: hockey-for-NOI/DBMS
 def get_columns(self, table):
     command = '''USE DATABASE ''' + self.database + ''' ;'''
     command = command + '''  DESC '''
     command = command + table
     command = command + ''' ;'''
     code = exe(command)[0]
     code.pop()
     columns = list([])
     for line in code:
         line = line.strip('\n')
         values = line.split(' ')
         name = values[0].strip(':')
         data_type = values[1]
         if (values[2] == '--Not'):
             null = False
         else:
             null = True
         if (values[len(values) - 2] == 'Not'):
             pk = False
         else:
             pk = True
         column = ColumnMetadata(name=name,
                                 data_type=data_type,
                                 null=null,
                                 primary_key=pk,
                                 table=table)
         columns.append(column)
     return columns
コード例 #3
0
 def get_columns(self, table, schema='public'):
     query = """
         SELECT column_name, is_nullable, data_type
         FROM information_schema.columns
         WHERE table_name = %s AND table_schema = %s
         ORDER BY ordinal_position"""
     cursor = yield self.execute_sql(query, (table, schema))
     pks = set((yield self.get_primary_keys(table, schema)))
     raise gen.Return([ColumnMetadata(name, dt, null == 'YES', name in pks, table)
             for name, null, dt in cursor.fetchall()])
コード例 #4
0
ファイル: mysql.py プロジェクト: laiqiqi/torpeewee
 async def get_columns(self, table, schema=None):
     sql = """
         SELECT column_name, is_nullable, data_type, column_default
         FROM information_schema.columns
         WHERE table_name = %s AND table_schema = DATABASE()"""
     cursor = await self.execute_sql(sql, (table, ))
     pks = set(self.get_primary_keys(table))
     return [
         ColumnMetadata(name, dt, null == 'YES', name in pks, table, df)
         for name, null, dt, df in cursor.fetchall()
     ]
コード例 #5
0
 def get_columns(self, table, schema=None):
     sql = """
             SELECT column_name, is_nullable, data_type
             FROM information_schema.columns
             WHERE table_name = %s AND table_schema = DATABASE()"""
     cursor = yield self.execute_sql(sql, (table, ))
     pks = set(self.get_primary_keys(table))
     raise gen.Return([
         ColumnMetadata(name, dt, null == 'YES', name in pks, table)
         for name, null, dt in cursor.fetchall()
     ])
コード例 #6
0
 async def get_columns(self, table, schema=None):
     query = """
         SELECT column_name, is_nullable, data_type, column_default
         FROM information_schema.columns
         WHERE table_name = %s AND table_schema = %s
         ORDER BY ordinal_position"""
     cursor = await self.execute_sql(query, (table, schema or 'public'))
     pks = set(self.get_primary_keys(table, schema))
     return [
         ColumnMetadata(name, dt, null == 'YES', name in pks, table, df)
         for name, null, dt, df in cursor.fetchall()
     ]
コード例 #7
0
    def get_columns(self, table, schema=None):
        res = self.execute_sql(
            '''select column_name, data_type, is_nullable
            from information_schema.columns
            where table_name=?
            order by ordinal_position''', (table, ))

        pks = set(self.get_primary_keys(table, schema))

        return [
            ColumnMetadata(col_name, col_type, nullable == 'YES', col_name
                           in pks, table)
            for col_name, col_type, nullable in res.fetchall()
        ]
コード例 #8
0
 def stash_columns(self):
     where, params = self.where_table_parm('table_schema', 'table_name')
     query = (
         "SELECT table_schema, table_name, column_name, is_nullable, data_type, column_default "
         "FROM information_schema.columns tc "
         f"WHERE {where} "
         "ORDER BY table_schema, table_name, ordinal_position"
     )
     cursor = self.db.execute_sql(query, params)
     fetch = cursor.fetchall()
     columns = {}
     for schema, g1 in groupby(fetch, key=itemgetter(0)):
         columns[schema] = {}
         for table, g2 in groupby(g1, key=itemgetter(1)):
             columns[schema][table] = [
                 ColumnMetadata(cn, dt, nl == 'YES', cn in self.primary_keys.get(sn, {}).get(tn, []), tn, cd)
                 for (sn, tn, cn, nl, dt, cd) in list(g2)
             ]
     return columns
コード例 #9
0
 def get_columns(self, table, schema='dbo'):
     return [
         ColumnMetadata(name, dt, nu == 'YES', con == 'PRIMARY KEY', table,
                        df)
         for name, df, nu, dt, *_, con in self.md_cache(table, schema)
     ]