Results 1 to 3 of 3

Thread: Problem using SQLite3 with regular expressions

  1. #1
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Problem using SQLite3 with regular expressions

    Hello!
    Facts:
    SQLite3-Database -> created by myself
    used driver -> QSQLITE
    connection -> ok, because statments before and after the problem are working fine

    What do I do:
    I try to delete some data, which doesn't fit into my regular expression

    Qt Code:
    1. #include <QRegExp>
    2. #include <QSqlError>
    3. #include <QString>
    4. #include <QStringList>
    5. #include <QSqlQueryModel>
    6. #include <QSqlRecord>
    7. #include "cb_database/cb_database.h"
    8.  
    9. #define DB_NMEA "nmea"
    10. ...
    11.  
    12. cb_database db; //Class which handles a SQLite3-Database
    13. db.open("xyz.db"); //Path to database
    14. QRegExp dateFormat;
    15. QRegExp timeFormat;
    16.  
    17. //Format of a correct date -> ddmmyy
    18. dateFormat.setPattern("([0][1-9]|[1-2][0-9]|[3][0-1])"
    19. "([0][1-9]|[1][0-2])[0-9]{2}");
    20. //Format of a correct time -> hhmmss.00
    21. timeFormat.setPattern("([0-1][0-9]|[2][0-3])([0-5][0-9]){2}\\.[0]{2}");
    22.  
    23. QString reg;
    24. reg=QObject::tr("DELETE FROM %0 WHERE "
    25. "(time REGEXP '%1')=0 "
    26. "OR (date REGEXP '%2')=0 "
    27. "OR date='010680'")
    28. .arg(DB_NMEA)
    29. .arg(timeFormat.pattern()).arg(dateFormat.pattern());
    30. db.query(reg);
    31. test=db.lastQuery();
    32. qDebug() << test->lastError();
    33. qDebug() << reg;
    34. ...
    To copy to clipboard, switch view to plain text mode 

    Problem:
    The statement seems to be correct, because I have tested this one with a opensource SQLite-Database-browser. I happens exactly what I expected. But when I try the same statement in my Qt-Application, nothing happens. The count of the rows in the table doesn't change. So the Problem must be in the code or maybe QSQLite-Driver.

    Result:
    qDebug Statement-> "DELETE FROM nmea WHERE (time REGEXP '([0-1][0-9]|[2][0-3])([0-5][0-9]){2}\.[0]{2}')=0 OR (date REGEXP '([0][1-9]|[1-2][0-9]|[3][0-1])([0][1-9]|[1][0-2])[0-9]{2}')=0 OR date='010680'"
    qDebug ERROR -> QSqlError(1, "Unable to execute statement", "no such function: REGEXP")

    The Error shows that the function I use doesn't exist, but the documentation says that it exists.

    Question:
    Does somebody has an idea what to do now?

  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: Problem using SQLite3 with regular expressions

    As far as I remember you have to turn ICU on to have regular expression support in SQLite. Obviously you haven't done that or you are using the "wrong" driver.

    To be sure, you are using the driver you compiled, use an other identifier than QSQLITE. To turn ICU on use the SQLITE_ENABLE_ICU switch. On how to build you can use the our wiki article [WIKI]Building QSQLITE driver with AES-256 encryption support[/WIKI] as a guideline.


    EDIT: Which documentation says, that the SQLite driver has default regular expression support?

  3. #3
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem using SQLite3 with regular expressions

    Little misunderstanding, the SQLite dokumentation said that SQLite support regular expressions.

    Thanks for the advice, I will try that...

Similar Threads

  1. Regular Expression Problem
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2009, 09:41
  2. Sqlite3 window problem
    By giusepped in forum Qt Programming
    Replies: 11
    Last Post: 7th November 2008, 02:18
  3. problem: inserting a BLOB into sqlite3 with QT4.3
    By oscar in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2007, 12:38
  4. QValidator, regular expressions and QLineEdit
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 8th August 2007, 01:25
  5. Qt regular expressions!!
    By notsonerdysunny in forum Qt Programming
    Replies: 9
    Last Post: 1st April 2007, 12:56

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.