def setUp(self):
     
     try:
         # create a test database.
         self.testName = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
         MYSQL_URL = "mysql://*****:*****@localhost/test"
         
         mysqlUrl = urlparse.urlparse(MYSQL_URL)
         url = mysqlUrl.hostname
         password = mysqlUrl.password
         userName = mysqlUrl.username
         dbName = mysqlUrl.path[1:] # slice off the '/'
         
         db = MySQLdb.connect(host=url,user=userName,passwd=password,db=dbName) 
         cur = db.cursor()
         cur.execute('create database %s'%self.testName)
         db.commit()
         
         #cur.execute("GRANT ALL ON %s.* TO 'dev'@'localhost';"%self.testName)
         #db.commit()
         fibDataDB = FibDataDB(url, self.testName,userName,password)
         
         fibDataDB.createTable()
         db.commit()
         
         db.close()
     except MySQLdb.Error, e:
         self.log.error("error creating table fibdata")
         self.log.error(e)
         self.handleMySQLException(e,True)
         return None        
    def setUp(self):

        try:
            # create a test database.
            self.testName = datetime.datetime.now().strftime(
                "%Y_%m_%d_%H_%M_%S")
            MYSQL_URL = "mysql://*****:*****@localhost/test"

            mysqlUrl = urlparse.urlparse(MYSQL_URL)
            url = mysqlUrl.hostname
            password = mysqlUrl.password
            userName = mysqlUrl.username
            dbName = mysqlUrl.path[1:]  # slice off the '/'

            db = MySQLdb.connect(host=url,
                                 user=userName,
                                 passwd=password,
                                 db=dbName)
            cur = db.cursor()
            cur.execute('create database %s' % self.testName)
            db.commit()

            #cur.execute("GRANT ALL ON %s.* TO 'dev'@'localhost';"%self.testName)
            #db.commit()
            fibDataDB = FibDataDB(url, self.testName, userName, password)

            fibDataDB.createTable()
            db.commit()

            db.close()
        except MySQLdb.Error, e:
            print("error creating table fibdata")
            print(e)
if __name__ == '__main__':

    try:
        logging.basicConfig()
        log = logging.getLogger('fibonacci')
        log.setLevel(logging.DEBUG)

        try:
            mysqlUrl = urlparse.urlparse(os.environ['MYSQL_URL'])
        except KeyError:
            log.warn(
                "env variable MYSQL_URL not found, reverting to DATABASE_URL")
            mysqlUrl = urlparse.urlparse(os.environ['DATABASE_URL'])

        url = mysqlUrl.hostname
        log.debug("url = %s" % url)
        password = mysqlUrl.password
        log.debug("password = %s" % password)
        userName = mysqlUrl.username
        log.debug("username = %s" % userName)
        dbName = mysqlUrl.path[1:]  # slice off the '/'
        log.debug("dbName = %s" % dbName)

        fibdataDB = FibDataDB(url, dbName, userName, password)

        fibdataDB.createTable()
        log.info("fibdata table created")

    except MySQLdb.Error, e:
        print "Exception during database initialization: %s" % str(e)
if __name__ == '__main__':
    
    try:
        logging.basicConfig()
        log = logging.getLogger('fibonacci')
        log.setLevel(logging.DEBUG)

        try:
            mysqlUrl = urlparse.urlparse(os.environ['MYSQL_URL'])
        except KeyError:
            log.warn("env variable MYSQL_URL not found, reverting to DATABASE_URL")
            mysqlUrl = urlparse.urlparse(os.environ['DATABASE_URL'])
        
        
        url = mysqlUrl.hostname
        log.debug("url = %s"%url)
        password = mysqlUrl.password
        log.debug("password = %s"%password) 
        userName = mysqlUrl.username
        log.debug("username = %s"%userName)
        dbName = mysqlUrl.path[1:] # slice off the '/'
        log.debug("dbName = %s"%dbName) 
        
        fibdataDB = FibDataDB(url,dbName,userName,password)
        
        fibdataDB.createTable()
        log.info("fibdata table created")
          
    except MySQLdb.Error, e:
        print "Exception during database initialization: %s"%str(e)