Android Question Not autoincrement primary key

ivavilagu

Member
Licensed User
Longtime User
I created a DB with the "DB Browser for SQLite" software. At the picture attached you can see two tables with their primary keys fields.

If I insert a new register, the ID primary key field keeps empty

B4X:
SQL1.ExecNonQuery2("INSERT INTO referencia VALUES(null,?,?,?)", Array As Object(txtREFERENCIA.Text, txtMAQUINA.text, txtPUESTO.Text))

For i =0 To lstMOVIMIENTOS.Size - 1
SQL1.ExecNonQuery2("INSERT INTO movimientos VALUES(null,?,?,?)", Array As Object(1,  lstMOVIMIENTOS.GetItem(i), lstTMTP.GetItem(i)))
Next
 

Attachments

  • Captura de pantalla 2015-01-19 a las 10.56.02.png
    Captura de pantalla 2015-01-19 a las 10.56.02.png
    99.9 KB · Views: 603

Peter Simpson

Expert
Licensed User
Longtime User
Hello,
My first column in all my databases (SQLite, MySQL, MSSQL etc) is called id. In SQLite it would be created as follows, thus the id column will always auto increment.
B4X:
[id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
 
Upvote 0

ivavilagu

Member
Licensed User
Longtime User
Hello,
My first column in all my databases (SQLite, MySQL, MSSQL etc) is called id. In SQLite it would be created as follows, thus the id column will always auto increment.
B4X:
[id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,

I don´t think it´s a naming problem, but I´m not sure .
 
Upvote 0

ivavilagu

Member
Licensed User
Longtime User
I didn't say that it was. I was just saying that the above line is mandatory in all my databases and it works perfect, so just add AUTOINCREMENT NOT NULL and give it a go :)

Ups, Ok. The problem is that I had created the table with a external software. Is it possible to determine the primary key once the table has been created before?
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
That does not make any difference, I create all my databases with external software packages, for SQLite I use SQLite Administrator (I think).

Yes it is possible, you should be able to just add that in using your external software, and don't forget to add AUTOINCREMENT the correct field.
 
Last edited:
Upvote 0

ivavilagu

Member
Licensed User
Longtime User
Thank you!! you`re agree. In the software there is an autoincrement option, a little bit hidden but it´s works perfectly.

Thank you again man!
 
Upvote 0
Top