Parameter unsupported when inserting int

I try storing date and time in SQLite3 with the intention of retrieving the records using comparisons later e.g. SELECT * WHERE date1 < date2. I gave up trying to store datetime.datetime objects and decided to use a UNIX timestamp instead as they are just an int but I am still getting errors.

import sqlite3 as lite import datetime import time conn = lite.connect('dispatcher.db') cur = conn.cursor() query = "create table if not exists new_test (curent_dt)" cur.execute(query) conn.commit() now = datetime.datetime.now() - datetime.timedelta(minutes=60) temp = int(time.mktime(now.timetuple())) cur.execute('insert into new_test (curent_dt) values (? )', (temp)) conn.commit() conn.close() 

Returns error :

cur.execute('insert into new_test (curent_dt) values (? )', (temp)) ValueError: parameters are of unsupported type

3

3 Answers

Note the added comma after "temp" below:

cur.execute('insert into new_test (curent_dt) values (?)', (temp,)) 

The reason this happens is that (temp) is an integer but (temp,) is a tuple of length one containing temp.

2

your code with error :

temp = int(time.mktime(now.timetuple())) cur.execute('insert into new_test (curent_dt) values (? )', temp) 

your code without error :

temp = [(int(time.mktime(now.timetuple())))] cur.execute('insert into new_test (curent_dt) values (? )', temp) 

my code when it gave me the error :

all_stats_changed = change_health, change_damage, change_defense, change_cooldown c.executemany("INSERT INTO player_stats VALUES (?, ?, ?, ?)", all_stats_changed) 

my code when it works :

all_stats_changed = [(change_health, change_damage, change_defense, change_cooldown)] c.executemany("INSERT INTO player_stats VALUES (?, ?, ?, ?)", all_stats_changed) 

Basically, putting the code in a [()] resolves the issue.

changing that line with this

cur.execute('insert into new_test (curent_dt) values (?)',str(temp))
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like