SQL auto increment

engvidal

Member
Licensed User
Longtime User
Hi

I am trying to insert 3 edittext values to a db with auto increment id.

The code is:

B4X:
SQL1.Initialize(File.DirInternal,"sql_list.sql", True)    ' runs ok

SQL1.ExecNonQuery("CREATE TABLE sql_list (_id INTEGER AUTO_INCREMENT PRIMARY KEY, name TEXT , mail TEXT, phone INTEGER)")     'runs OK

SQL1.ExecNonQuery("INSERT INTO sql_list (name,mail,phone) VALUES( 'TestName'', '1@test.com', 55511234)")   ' runs OK.
            
SQL1.ExecNonQuery2("INSERT INTO sql_list VALUES (name,mail,phone)", Array As Object (edittext1.Text, edittext2.Text, edittext3.Text))   

'DO NOT RUN>>> 
'SQLITE EXCEPTION: NO SUCK COLUMN: name: , WHILE COMPILING....

Thanks

Vidal
 

mangojack

Expert
Licensed User
Longtime User
B4X:
SQL1.ExecNonQuery("CREATE TABLE IF NOT EXISTS MyTable (ID INTEGER PRIMARY KEY, name TEXT, mail TEXT, phone)")

'always using NULL for first field will create auto increment ID
SQL1.ExecNonQuery("INSERT INTO MyTable VALUES (NULL,'John Smith', '1@test.com',55511234) ")

Sorry .. thought it was a problem with auto Increment
 
Last edited:
Upvote 0

mangojack

Expert
Licensed User
Longtime User
maybe try ..
B4X:
SQL1.ExecNonQuery2("INSERT INTO sql_list VALUES (Null,?, ?, ?)", Array As Object (edittext1.Text, edittext2.Text, edittext3.Text))

Cheers mj
 
Upvote 0
Top