-
Aug 21st, 2017, 04:19 PM
#1
Thread Starter
Hyperactive Member
vbRichClient Create Table AUTO_INCREMENT
Hello,
Finally working with the vbrichclient SQL lite stuff ( never thought I would)...
Really Awesome framework.
I am able to create the table in a DB (file) I need and fill it with data, but in my case I need the ID/ primary key to be auto generated.
so when I do the .setInt32, or on the creating of the table how do I make it so the ID field is automatically generated?
Thanks
-
Aug 21st, 2017, 04:31 PM
#2
Thread Starter
Hyperactive Member
Re: vbRichClient Create Table AUTO_INCREMENT
Think I found it, call LastInsertAutoID on cConnection Object?
WP
-
Aug 21st, 2017, 05:07 PM
#3
Re: vbRichClient Create Table AUTO_INCREMENT
SQLite tables automatically create a field called "rowid" (unless WITHOUT ROWID) is specified that acts as a unique # for each row. Alternately, you can create your own autonumber column by declaring the field with INTEGER PRIMARY KEY keywords (e.g. CREATE TABLE mytable (myfield INTEGER PRIMARY KEY).
You don't need to set the value for these fields with SetInt32 or anything - just leave it out of any INSERT/UPDATE statements/commands and a # will be generated automatically.
See here for more info: https://sqlite.org/lang_createtable.html#rowid
-
Aug 21st, 2017, 07:32 PM
#4
Hyperactive Member
Re: vbRichClient Create Table AUTO_INCREMENT
Adding to what jbpro said:
by declaring "myfield INTEGER PRIMARY KEY", myfield become just an alias to the internal "rowid".
by declaring "myfield INTEGER PRIMARY KEY AUTOINCREMENT", sqlite guaranties that every new row will have a rowid that was never used before in that table.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|