Results 1 to 5 of 5

Thread: postgreSQL - Last Inserted ID

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2006
    Posts
    13
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default postgreSQL - Last Inserted ID

    I am using QT4.2.3 with PostgreSQL. I am having a following problem.

    This is how my table looks like...

    [first]

    id (sequence) (int8)
    fname
    lname

    When i did...

    QSqlQuery query;
    query.prepare("INSERT INTO first (fname, lname) VALUES (?, ?)");
    query.addBindValue(QString(Fname));
    query.addBindValue(QString(Lname))
    query.exec();

    I got a record inserted in my first table.
    But is there any way to retrieve the id after inserting the data in the [first], as it is a sequence?

    I have tried using a:

    QVariant variant=query.lastInsertId();
    int i=variant.toInt();

    but I am always getting 0 as a result...
    Doing something wrong?

    When I try a driver feature It says It is OK.
    Last edited by nnidza; 26th March 2007 at 22:09.

Similar Threads

  1. PostgreSQL plugin under Windows
    By aekilic in forum Newbie
    Replies: 1
    Last Post: 22nd January 2007, 06:43
  2. Replies: 5
    Last Post: 28th August 2006, 14:36
  3. PostgreSQL and Windows Community Version
    By graeme in forum Installation and Deployment
    Replies: 23
    Last Post: 20th April 2006, 19:29
  4. QT4 and Postgresql driver
    By alphaqt in forum Installation and Deployment
    Replies: 6
    Last Post: 27th February 2006, 15:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.