def main(): with sqlite3.connect(DB_FILENAME) as conn: # <- context mgr if DB_IS_NEW: # A whole new if clause: print 'Creating schema' with open(SCHEMA_FILENAME, 'rt') as f: schema = f.read() conn.executescript(schema) else: print "Database exists, introspecting:" tablenames = ['author', 'book'] cursor = conn.cursor() for name in tablenames: print "\n" show_table_metadata(cursor, name)
def main(): with sqlite3.connect(DB_FILENAME) as conn: # <- context mgr if DB_IS_NEW: # A whole new if clause: print "Creating schema" with open(SCHEMA_FILENAME, "rt") as f: schema = f.read() conn.executescript(schema) else: print "Database exists, introspecting:" tablenames = ["author", "book"] cursor = conn.cursor() for name in tablenames: print "\n" show_table_metadata(cursor, name)
def main(): with sqlite3.connect(DB_FILENAME) as conn: if DB_IS_NEW: print 'Creating schema' with open(SCHEMA_FILENAME, 'rt') as f: schema = f.read() conn.executescript(schema) else: print 'Database exists, introspecting:' tablenames = ['author', 'book'] cursor = conn.cursor() for name in tablenames: print '\n' show_table_metadata(cursor, name)
def main(): with sqlite3.connect(DB_FILENAME) as conn: # <- context mgr if DB_IS_NEW: # A whole new if clause: print 'Creating schema' with open(SCHEMA_FILENAME, 'rt') as f: schema = f.read() conn.executescript(schema) else: # in the else clause, replace the print statement with this: print "Database exists, introspecting:" tablenames = ['author', 'book'] cursor = conn.cursor() for name in tablenames: print "\n" show_table_metadata(cursor, name)
def main(): DB_IS_NEW = not os.path.exists(DB_FILENAME) conn = sqlite3.connect(DB_FILENAME) if DB_IS_NEW: print 'creating database and schema' with open('ddl.sql') as f: schema = f.read() conn.executescript(schema) else: print "Database exists, introspecting:" tablenames = ['author', 'book'] cursor = conn.cursor() for name in tablenames: print "\n" show_table_metadata(cursor, name) conn.close()