How to insert an id in android SQLITE?

Asked

Viewed 336 times

1

I am trying to insert the same id that I get from the server database in the android database through sqlite, however, it is generating an id of its own, I am using auto increment in Primary key, I have tried to use Unique and tried not to declare anyone as Primary key, but error when trying to insert in the mobile bank, only works when I put Primary key, but generates autoincrement that does not need

  • It would be more convenient and safer to have a separate column, for example id_server to store the original id. Whether you like it or not, Sqlite will need its own index. You may not even declare Primary key, but either way internally Sqlite will have a primary column.

  • I thought so too, but I was trying not to do it that way

  • Declaring or not a primary column in Sqlite only changes whether the internal ID is associated with a "first name" column or not. If you really want to not have the "default" primary key, you have to define WITHOUT ROWID when creating the table, but then you need to define your own PK. The AUTOINCREMENT you can omit in the table creation, regardless of whether or not you have PK defined (even to save some resources).

  • I’ll do it that way anyway, if someone comes up with another better solution... kkk

  • I don’t understand what could be better for what you’re asking. Basically the WITHOUT ROWID + its own PK must solve its own indices. And I honestly think that what you want to do is actually no better than letting DB have its own key, but then only you who are designing the application that really knows what’s best for your case.

  • is that I needed to keep a chunk of the server database, replicated exactly the same on android, because then the project will go ahead, so there are no problems for maintenance I was trying not to use another column, but I believe your solution is not bad no ;D

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.