I have a table called led_status and a Field called "test_led":
mysql> describe led_status;
+------------------------------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------------+------------+------+-----+---------+-------+
| test_led | varchar(5) | NO | | NULL | |
+------------------------------+------------+------+-----+---------+-------+
I am attempting to enter a string of either "TRUE" or "FALSE" (not int 1 or 0) with the following code:
def write_database_value(table,field,value):
connect = mysql.connector.connect(user=db_info.username,
password=db_info.password,
host=db_info.servername,
database=db_info.database)
cursor = connect.cursor()
cursor.execute(("UPDATE %s SET %s = %s") % (table, field, value))
connect.commit()
cursor.close()
connect.close()
def read_database_value(table,field):
connect = mysql.connector.connect(user=db_info.username,
password=db_info.password,
host=db_info.servername,
database=db_info.database)
cursor = connect.cursor(buffered=True)
cursor.execute(("SELECT %s FROM %s") % (field, table))
for data in cursor:
database_value = data
cursor.close()
connect.close()
return database_value
Which is called from this script:
def get_led_status(led):
led_status = read_database_value("led_status", led)
led_status = (led_status[0])
return led_status
def is_pool_pump_running():
pool_running = get_led_status("test_led")
if pool_running == "TRUE":
print("Pool Pump is Running, shutting it off now")
write_database_value("led_status","test_led","FALSE")
else:
print("Pool Pump is NOT Running, turning it on now")
write_database_value("led_status","test_led","TRUE")
However everytime I run the script it changes my "TRUE" to a 1 and my "FALSE" to a 0.
I am switching over from a flat file to a database and all of my code (4000 lines of it so far) uses "TRUE" and "FALSE" so I really don't want to have to rewrite it just to use 1 and 0 as opposed to "TRUE" and "FALSE".
Any thoughts would be greatly appreciated.