Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt-Sql auto_increment of a field
Forum Updated to NodeBB v4.3 + New Features

Qt-Sql auto_increment of a field

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.9k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chrisw01
    wrote on 16 Sept 2017, 16:36 last edited by
    #1

    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
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on 16 Sept 2017, 17:04 last edited by mostefa
      #2

      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!

      1 Reply Last reply
      1
      • C Offline
        C Offline
        Chrisw01
        wrote on 16 Sept 2017, 17:12 last edited by
        #3

        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..

        1 Reply Last reply
        1
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 16 Sept 2017, 20:36 last edited by
          #4

          Hi,

          What documentation are you referring to ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          1/4

          16 Sept 2017, 16:36

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved