mysql - Python: Checking if field exists in table -


how can check if field exists in table. need if statement believe this.

i don't want insert data row if field within row contains same data.

so example have table 6 rows. prefix, code_id, answer, station_id, timestamp, comport.

the user enter in station_id through console , prefix,code_id, , answer in 1 line. split 3 variables , store them in database.

cursor.execute("""insert scan (prefix, code_id, answer, station_id,timestamp,comport) values(%s, %s, %s, %s, %s, %s)""",(prefix, code_id, answer, station, timestamp,station)) 

but before insert statement want see if data user enters in table.

i hope i'm being clear enough. if not let me know , edit question.

edit: tried no luck

#test if fields exist before inserting!         query = cursor.execute("""select count(*) scan prefix = %s , code_id = %s , answer = %s , station_id = %s""",                           (prefix, code_id, answer, station,))         if query != 1:             cursor.execute("""insert scan (prefix, code_id, answer, station_id,timestamp,comport) values(%s, %s, %s, %s, %s, %s)""",                            (prefix, code_id, answer, station, timestamp,station))             print 'thank checking station: ', station ,'please wait beep 

if want see if there data in table meets conditions, query it:

in pseudo-code

if "select count(*) scan prefix = ? , code_id = ? , ..." == 0:     execute("insert scan....") 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -