-1
class int_db:
    def __init__(self, _id: str):
        self.conn = sqlite3.connect("int_db.db", isolation_level=None)
        self.cur = self.conn.cursor()
        sql_cmd = '''CREATE TABLE {}(name)'''.format(
            _id)
        self.cur.execute(sql_cmd)

    def insert_db(self, _id, name: str):
        sql_cmd = '''INSERT INTO {} VALUES ({})'''.format(_id, name)
        self.cur.execute(sql_cmd)
        self.conn.commit()
        self.conn.close()

the _id is value of "1241448952" how can I success this?

I want to make a table named by variable.

error:

sqlite3.OperationalError: near "1241448952": syntax error
심현규
  • 15
  • 2

1 Answers1

0

Despite the fact that it is not well documented. With SQLite you cannot create table starting with numeric characters.

You can try to add a prefix to _id in order to prevent the error: _id_new = "tbl" + str(_id)

NassimH
  • 462
  • 3
  • 13