#NEWLINE# def create_table( model ) : #NEWLINE# #INDENT# if ( model . db_table_name in EXISTING_TABLES ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# dependencies = [ col . foreign_key for col in model . db_columns if ( col . foreign_key and ( col . foreign_key [ 0 ] != model . db_table_name ) ) ] #NEWLINE# for ( mod , col ) in dependencies : #NEWLINE# #INDENT# M = model_list . get ( mod ) #NEWLINE# if ( not M ) : #NEWLINE# #INDENT# raise Exception ( ( 'Dependency on unknown model: %s' % str ( mod ) ) ) #NEWLINE# #UNINDENT# if ( M . db_table_name not in EXISTING_TABLES ) : #NEWLINE# #INDENT# create_table ( M ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( col not in EXISTING_TABLES [ M . db_table_name ] ) : #NEWLINE# #INDENT# add_column ( M , col ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# table_string = [ ] #NEWLINE# table_string . append ( ( 'CREATE TABLE IF NOT EXISTS %s (' % model . db_table_name ) ) #NEWLINE# columns_string = [ ] #NEWLINE# for col in model . db_columns : #NEWLINE# #INDENT# columns_string . append ( str ( col ) ) #NEWLINE# #UNINDENT# for extra in model . db_extras : #NEWLINE# #INDENT# columns_string . append ( unicode ( extra ) ) #NEWLINE# #UNINDENT# table_string . append ( ',' . join ( columns_string ) ) #NEWLINE# table_string . append ( ')' ) #NEWLINE# create_stmt = '' . join ( table_string ) #NEWLINE# cursor = World . get_world ( ) . db . conn . cursor ( ) #NEWLINE# cursor . execute ( create_stmt ) #NEWLINE# EXISTING_TABLES [ model . db_table_name ] = [ col . name for col in model . db_columns ]