Questions about Python DB

Asked 2 years ago, Updated 2 years ago, 88 views

import sqlite3

import datetime

DT_Now = datetime.datetime.now()

Today = "{}{}{}".format(DT_Now.year, DT_Now.month, DT_Now.day) information = sqlite3.connect("info.db") curs = information.cursor()

def CreateTable():

curs.execute("CREATE TABLE IF NOT EXISTS {}(number TEXT NOT NULL, name TEXT NOT NULL, howMuch INTEGER DEFAULT 0)".format(Today)) 

CreateTable()

Error: curs.execute ("CREATE TABLE IF NOT EXISTS {} (number TEXT NOT NULL, name TEXT NOT NULL, how Much INTEGER DEFAULT 0)"format(Today)) sqlite3.OperationalError: near "2022418": syntax error

I looked it up, but it doesn't come out well. What's wrong with this?

sqlite python-2.7

2022-09-20 10:49

1 Answers

I think the problem is the table name consisting of only numbers.


2022-09-20 10:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.