Beispiel #1
0
    print("Dropping table %s if it exists" % format(table_name))
    db.executeQuery('DROP TABLE IF EXISTS %s' % str(table_name))

    print("Creating table %s " % format(table_name))
    db.executeQuery(table_description)

# *** TABLES FOR WHICH DATA IS NOT REFRESHED, SO THEY CAN'T BE DROPPED ***
# Array containing create statements for tables.
PERSISTENTTABLES = {}
PERSISTENTTABLES['temperatureLog'] = ("CREATE TABLE `temperatureLog` ("
                                      "  `temperature` DECIMAL(5,1) NOT NULL,"
                                      "  `date` datetime NOT NULL,"
                                      "	 `alerttext TEXT"
                                      "  PRIMARY KEY (`date`)"
                                      ") ENGINE=InnoDB")

# Loop over the array
for table_name in PERSISTENTTABLES:
    table_description = PERSISTENTTABLES[table_name]

    print("Checking if table %s exists" % format(table_name))
    tableCount = db.getCount('SHOW TABLES LIKE \'%s\';' % str(table_name))
    if tableCount == 0:
        print("Creating table %s " % format(table_name))
        print(table_description)
        db.executeQuery(table_description)
    else:
        print(
            'Table %s already exists and could contain unique data, skipping table'
            % format(table_name))