import gnucash
import MySQLdb

database = MySQLdb.connect(host='localhost', user='root', passwd='oxford')
cursor = database.cursor()
sql = 'CREATE DATABASE test'
cursor.execute(sql)

session = gnucash.Session('mysql://root:oxford@localhost/test', is_new=True, ignore_lock=False)

query = gnucash.Query()
query.search_for(gnucash.gnucash_core_c.GNC_ID_INVOICE)
query.set_book(session.book)
query.run()

database = MySQLdb.connect(host='localhost', user='root', passwd='oxford')
cursor = database.cursor()
sql = 'DROP DATABASE IF EXISTS test'
cursor.execute(sql)