Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

using python I'm trying to insert ADMIN_ID as None in to a database in SQL and my date_time that converted into a suitable format into a table

this works but i cant seem to get the other format to work

conn=sqlite3.connect("Jakson.db")
("Database Opened successfully")

conn.execute('INSERT INTO SMITH(EXPIRE) VALUES (?)',  [date_time])

i know that the date_time will work becasue ive already tested it on its own in a another database but i can seem to get this one to work

#conn=sqlite3.connect("Jakson.db")
#print("Database Opened successfully")
#conn.execute("""
#CREATE TABLE SMITH(
#ADMIN_ID INTEGER PRIMARY KEY AUTOINCREMENT  NOT NULL ,
#EXPIRE DATE
#)
#""")
import datetime 
import pytz
import sqlite3

today = datetime.datetime.now()
date_time = today.strftime("%m/%d/%Y")

conn=sqlite3.connect("Jakson.db")
("Database Opened successfully")

conn.execute('INSERT INTO SMITH VALUES (:ADMIN_ID, :EXPIRE)',
         {
         'ADMIN_ID': None,
         'EXPIRE':[date_time]
          }) 

InterfaceError: Error binding parameter :EXPIRE – probably unsupported type.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the following:

conn.execute('INSERT INTO SMITH VALUES (:ADMIN_ID, :EXPIRE)',
             {
             'ADMIN_ID': None,
             'EXPIRE': date_time
              })

[date_time] should be without brackets.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading