Jump to content

SQLite LAST_INSERT_ROWID() problem


Recommended Posts

Posted
    local ID = dbExec(db, "SELECT LAST_INSERT_ROWID() FROM joinHistory") 

this returns false for me, even though the database isn't empty.

i'm trying to create an auto_increment column, but just found out that sqlite doesn't support auto_increment, it's only supported by MySQL.

any help?

Posted

SQLite supports auto-increment. A column declared "INTEGER PRIMARY KEY" will auto-increment.

You can use last_insert_rowid() without specifying a table.

SELECT LAST_INSERT_ROWID() 

Posted

Also, you can't use dbExec to get the ID. You'll have to use dbQuery + dbPoll as follows:

local result = dbPoll(dbQuery(db, "SELECT LAST_INSERT_ROWID() AS `ID`"), -1) 
outputChatBox(result.ID) 

("FROM joinHistory" isn't necessary according to the SQLite documentation btw)

Posted

I didn't even notice that he was using dbExec.

dbExec never returns results, it only executes the given query.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...