Results 1 to 4 of 4

Thread: about QSqlQuery ,how can i get columns

  1. #1
    Join Date
    Apr 2009
    Posts
    35
    Thanks
    9
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Android

    Default about QSqlQuery ,how can i get columns

    QSqlQuery query;
    query.exec("select * from table");



    how to know
    number of columns

    i see the help

    int QSqlQuery::size () const
    Returns the size of the result (number of rows returned), or -1 if the size cannot be determined or if the database does not support reporting information about query sizes. Note that for non-SELECT statements (isSelect() returns false), size() will return -1. If the query is not active (isActive() returns false), -1 is returned.


    but it return -1, i use sqlite database

    is there other ways to do
    Last edited by tsuibin; 1st March 2010 at 09:12.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: about QSqlQuery ,how can i get columns

    QSqlQuery::record() and QSqlRecord::count():
    Qt Code:
    1. query->record()->count();
    To copy to clipboard, switch view to plain text mode 
    (Assuming record is valid!)

  3. The following user says thank you to Lykurg for this useful post:

    tsuibin (2nd March 2010)

  4. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: about QSqlQuery ,how can i get columns

    If you created the table, you already know the number of columns. What is it you are trying to do?

  5. The following user says thank you to waynew for this useful post:

    tsuibin (2nd March 2010)

  6. #4
    Join Date
    Feb 2010
    Posts
    7
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: about QSqlQuery ,how can i get columns

    to find the column id tto use QSqlQuery::value() then look here
    QSqlQuery Reference
    your looking for QSqlQuery::record()

    now for finding the number of records return by you query you can do something like this

    Qt Code:
    1. q.exec("SELECT Count(*) FROM tablename WHERE condition");
    2. q.next();
    3. int numRows = q.value(0).toInt();
    4. //if you expect this query to return a massive number of records don use int for this purpose
    5.  
    6. //now run your original query
    To copy to clipboard, switch view to plain text mode 

    hope this helps
    artificial intelligence is no match for natural stupidity

Similar Threads

  1. QSqlquery
    By codeman in forum Qt Programming
    Replies: 10
    Last Post: 4th June 2009, 12:57
  2. what is going on a QSqlQuery?
    By mismael85 in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2008, 13:35
  3. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 14
    Last Post: 14th January 2008, 22:50
  4. QSqlQuery problem
    By MarkoSan in forum Qt Programming
    Replies: 11
    Last Post: 18th December 2007, 13:25
  5. QSqlQuery error
    By skuda in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2007, 08:43

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.