Results 1 to 2 of 2

Thread: SQL date queries

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default SQL date queries

    Hi,

    I'm trying to query the week of the year on a MySQL server.

    Qt Code:
    1. QString qQuery = "select WEEKOFYEAR(CURDATE())";
    2. QSqlQuery qSQLQuery(m_qBD);
    3. bool bRes = qSQLQuery.exec(qQuery);
    4. QSqlRecord qRecord= qSQLQuery.record();
    5. int iCols = qRecord.count(); //Returns me "1"
    6. QString qWeekDay = qSQLQuery.value(0).toString();
    To copy to clipboard, switch view to plain text mode 

    The result "qWeekDay" is an empty QString.
    I have tryied it to a SQL Server via ODBC driver:
    Qt Code:
    1. QString qQuery = "select DATEPART(weekday, GETDATE())";
    2. QSqlQuery qSQLQuery(m_qBD);
    3. bool bRes = qSQLQuery.exec(qQuery);
    4. QSqlRecord qRecord = qSQLQuery.record();
    5. int iCols = qRecord.count();
    6. QString qWeekDay = qSQLQuery.value(0).toString();
    To copy to clipboard, switch view to plain text mode 
    And I'm getting the same value, an empty QString.

    I know that QDate let me obtaing this information but I want to query the DB Server to get always the same values on different workstations.

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SQL date queries[solved]

    Hi,

    I have forgotten that have to call "qSQLQuery.next()" before getting the value.
    Òscar Llarch i Galán

Similar Threads

  1. SQL queries and slots
    By fnmblot in forum Newbie
    Replies: 8
    Last Post: 26th April 2007, 01:20

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.