Results 1 to 6 of 6

Thread: SQLite DATETIME fieldtype

  1. #1
    Join Date
    Dec 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default SQLite DATETIME fieldtype

    When i test this code:

    Qt Code:
    1. QSqlDatabase m_dbSQLite = QSqlDatabase::addDatabase("QSQLITE");
    2. QDir baseDir = QDir(qApp->applicationDirPath());
    3.  
    4. #if defined(Q_OS_WIN)
    5. if (baseDir.dirName().toLower() == "debug" || baseDir.dirName().toLower() == "release")
    6. baseDir.cdUp();
    7. #elif defined(Q_OS_MAC)
    8. if (baseDir.dirName() == "MacOS") {
    9. baseDir.cdUp();
    10. baseDir.cdUp();
    11. baseDir.cdUp();
    12. }
    13. #endif
    14. m_dbSQLite.setDatabaseName(baseDir.absolutePath()+"/Datas/Bels.sqlite");
    15. if(m_dbSQLite.open())
    16. {
    17. QSqlQuery query = QSqlQuery();
    18.  
    19. query.exec("SELECT [Birthdate] FROM Patients");
    20. QSqlRecord rec = query.record();
    21. QSqlField fld = rec.field("Birthdate");
    22.  
    23. qDebug() << fld.type();
    24. }
    To copy to clipboard, switch view to plain text mode 
    QVariant::QString is return while the field type is DATETIME. Why?

    Thanks

  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: SQLite DATETIME fieldtype

    I don't think the type of your field is DATETIME since SQLite only supports NULL, INTEGER, REAL, BLOB and TEXT. And usually a date/time is stored as TEXT in SQLite.

    EDIT: Try to play with the date() function of SQLite.

  3. #3
    Join Date
    Dec 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: SQLite DATETIME fieldtype

    In SQLite Manager (plugin Firefox) the type DATETIME exist, but your respons tell me that is not a real DATETIME type because data are stored in format TEXT.
    Thank you.

  4. #4
    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: SQLite DATETIME fieldtype

    Quote Originally Posted by phildu44 View Post
    In SQLite Manager (plugin Firefox) the type DATETIME exist
    Strange, but according to the docs (http://sqlite.org/datatype3.html) there isn't such a type.

  5. #5
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SQLite DATETIME fieldtype

    Hi, had the same problem before. For now I'm using QDateTime::toTime_t() and store that in SQLite as INTEGER. When I need to show the exact date I just need to perform the reverse operation. Hope that helps.
    -- Tanuki

    per cauda vel vaculus cauda

  6. #6
    Join Date
    Dec 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: SQLite DATETIME fieldtype

    Thanks. That help me for use in code. The problem persist when I'm using a model/view because field is not formatted correctly (integer or string YYYY-MM-DDTHH:MM:SS).

    The solution is tu use MySQL.

Similar Threads

  1. steps to connect to SQLite from Q
    By Qt Coder in forum Qt Programming
    Replies: 3
    Last Post: 8th July 2009, 12:12
  2. Qt SQLite user functions
    By cevou in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2009, 19:43
  3. sqlite version in Qt
    By janus in forum Newbie
    Replies: 4
    Last Post: 5th February 2009, 14:18
  4. SQLite
    By cyberboy in forum Installation and Deployment
    Replies: 1
    Last Post: 15th April 2008, 19:46
  5. sqlbrowser and sqlite
    By janus in forum Installation and Deployment
    Replies: 2
    Last Post: 31st March 2008, 14:59

Tags for this Thread

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.