Qt-Sql auto_increment of a field
Solved
General and Desktop
-
Hi,
I'm having some issues with an auto_increment in Qt5.9.1. My SQL Statement is as follows.
"create table if not exists ACCOUNTS_PAYABLE(`Entry Number` int identity(100, 1) primary key, `Invoice Number` text, `Vendor Name` text, Amount text, `Payment Method` text, Department text, Status text, Description text)"
Which if I 've read the docs right should create an integer based entry starting at 100 and increment by one every time something is added to the table. When I inspect the database that column has nothing in it.
I have even tried the following with no luck.
"create table if not exists ACCOUNTS_PAYABLE(`Entry Number` int AUTO_INCREMENT primary key DEFAULT 1, `Invoice Number` text, `Vendor Name` text, Amount text, `Payment Method` text, Department text, Status text, Description text)" ~~ With the same outcome, and again when I inspect the database it shows the column type as int auto_increment with default of 1. Using Qt 5.9.1 on Windows 7 with mingw compiler. Thanks
-
Hi @Chrisw01
I think that you can do something like this:
"create table if not exists ACCOUNTS_PAYABLE(`Entry Number` int NOT NULL AUTO_INCREMENT identity primary key, `Invoice Number` text, `Vendor Name` text, Amount text, `Payment Method` text, Department text, Status text, Description text)AUTO_INCREMENT=100;"
AUTO_INCREMENT can be placed after the ")";
I hope this can help you!
-
Hi, and thanks.. After creating the table in a SQL Editor I have come up with this..
create table if not exists ACCOUNTS_PAYABLE (`Entry Number` INTEGER PRIMARY KEY AUTOINCREMENT DEFAULT 1)
When most of the Documentation I've seen and examples all use AUTO_INCREMENT. The above code works as expected.
Thanks again..
-
Hi,
What documentation are you referring to ?