#NEWLINE# def _create_sqlite_metatable( self ) : #NEWLINE# #INDENT# "\n        SQLite doesn't come with any metatables (at least ones that fit into our\n        framework), so we're going to create them.\n        " #NEWLINE# sys . stderr . write ( 'Indexing schema. This will take a second...' ) #NEWLINE# rows_to_insert = [ ] #NEWLINE# tables = [ row [ 0 ] for row in self . cur . execute ( "select name from sqlite_master where type='table';" ) ] #NEWLINE# for table in tables : #NEWLINE# #INDENT# for row in self . cur . execute ( "pragma table_info('{0}')" . format ( table ) ) : #NEWLINE# #INDENT# rows_to_insert . append ( ( table , row [ 1 ] , row [ 2 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . cur . execute ( 'drop table if exists tmp_dbpy_schema;' ) #NEWLINE# self . cur . execute ( 'create temp table tmp_dbpy_schema(table_name varchar, column_name varchar, data_type varchar);' ) #NEWLINE# for row in rows_to_insert : #NEWLINE# #INDENT# self . cur . execute ( "insert into tmp_dbpy_schema(table_name, column_name, data_type) values('{0}', '{1}', '{2}');" . format ( * row ) ) #NEWLINE# #UNINDENT# self . cur . execute ( "SELECT name, sql  FROM sqlite_master where sql like '%REFERENCES%';" ) #NEWLINE# self . cur . execute ( 'drop table if exists tmp_dbpy_foreign_keys;' ) #NEWLINE# self . cur . execute ( 'create temp table tmp_dbpy_foreign_keys(table_name varchar, column_name varchar, foreign_table varchar, foreign_column varchar);' ) #NEWLINE# foreign_keys = [ ] #NEWLINE# self . cur . execute ( 'SELECT name, sql  FROM sqlite_master ;' ) #NEWLINE# for ( table_name , sql ) in self . cur : #NEWLINE# #INDENT# rgx = 'FOREIGN KEY \\(\\[(.*)\\]\\) REFERENCES \\[(.*)\\] \\(\\[(.*)\\]\\)' #NEWLINE# if ( sql is None ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# for ( column_name , foreign_table , foreign_key ) in re . findall ( rgx , sql ) : #NEWLINE# #INDENT# foreign_keys . append ( ( table_name , column_name , foreign_table , foreign_key ) ) #NEWLINE# #UNINDENT# #UNINDENT# for row in foreign_keys : #NEWLINE# #INDENT# sql_insert = "insert into tmp_dbpy_foreign_keys(table_name, column_name, foreign_table, foreign_column) values('{0}', '{1}', '{2}', '{3}');" #NEWLINE# self . cur . execute ( sql_insert . format ( * row ) ) #NEWLINE# #UNINDENT# self . con . commit ( ) #NEWLINE# sys . stderr . write ( 'finished!\n' )