Home > Mobile >  using python I'm trying to insert ADMIN_ID as None in to a database in SQL and my date_time tha
using python I'm trying to insert ADMIN_ID as None in to a database in SQL and my date_time tha

Time:02-11

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.

CodePudding user response:

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

figure it out had to remove the brackets [date_time]

CodePudding user response:

Use the following:

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

[date_time] should be without brackets.

  • Related