sqlite3 - lastrowid() alternative or syntax without using execute in sqlite python? -
in sqlite3 in python, i'm trying make program new row in table written inserted next, needs printed out. read documentation here insert should used in execute() statement. problem program i'm making asks user his/her information , primary key id assigned member his/her id number must displayed. in other words, execute("insert") statement must not executed first id keys wrong assignment of member.
i first thought lastrowid can run without using execute("insert") noticed gave me value "none". read documentation in sqlite3 in python , googled alternatives solve problem.
i've read through google somewhere select last_insert_rowid() can used alright ask syntax of in python? i've tried coding this
nextid = con.execute("select last_insert_rowid()")
but gave me cursor object output ""
i've been thinking of making table there 1 value. value of lastrowid of main table whenever there new input of data in main table. value gets inserted , overwritten in table every time there new set of data needs input in main table , next row id needed, access table 1 value.
or there alternative , easier way of doing this?
any appreciated bows deeply
you guess next id if query table before asking user his/her information select max(id) + 1 newid desiredtable
.
before inserting new data (including new id), start transaction, rollback if insert failes (because process faster same operation) , ask user again. if eveything ok commit.
Comments
Post a Comment