How to insert data into sqlite3 db?

  • 0
    How can you insert data into an autoincrement table, how can you skip this field? When inserting, an error occurs that the data type does not converge, since the first field is id and it is int.
    import sqlite3
    
    conn = sqlite3.connect("all.db")
    cursor = conn.cursor()
    
    def parser(link, separator='|'):
        f = open(link)
        text = f.read()
        text = text.split('\n')
        for i in range(len(text)):
            text[i] = tuple(text[i].split(separator))
        text = tuple(text)
        f.close()
        print(text)
        return text
    def create_table(name):
        cursor.execute("""CREATE TABLE {0} ({1} INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,{2} text,{3} text,{4} text,{5} text)""".format(name[0],name[1],name[2],name[3],name[4],name[5]))
        conn.commit()
    text=parser('C:\\Users\\sanya\\Documents\\БД\\test.txt')
    try:
        create_table(text[0])
    except:
        pass
    print(text)
    text=text[1:]
    text=list(text)
    print(text)
    cursor.executemany("INSERT INTO Test VALUES (?,?,?,?,?)",text)
    cursor.commit()

    Lines from file:
    Test | id | first_name | second_name | address | house
    lorem | ipsum | dolor | sit | amet
    consectetur | adipscing | elit | Phasellus | ultrices
    s | d || c | d
    Python William Matthews, Jul 2, 2019

  • 1 Answers
  • 0
    insert into table (column1, column2) values ​​(?,?) '

    id you miss
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!