Get records according to regex from SQLite db in QT (C ++)
I am trying to fetch records from a database SQLite
using QSqlDatabase
and QSqlQuery
in QT/C++
. My request would look like this:
select * from tableName where columnName REGEXP 'regex'
Some sources create a function named REGEXP
, but I couldn't find any hint related to QT/C++
.
Can anyone help me?
source to share
As described here , you need to provide some native C / C ++ code that exports the regex capability to SQL. You do this by calling the sqlite3_create_function_v2 function , which is part of the SQL library written in C.
Since QSqlDatabase is a generic SQL wrapper designed to support a large number of SQL engines, the functions provided are the lowest common denominator of all of them. Thus, you cannot access sqlite3_create_function_v2
from Qt.
If you need to use REGEXP in your Qt application, you need to use the regular C sqlite library throughout your project. A C ++ wrapper around SQLite is recommended, but from my own experience there is nothing great there, so we develop our own. Digging into SQLite can be a big hassle, especially when you start to combine different C ++ build systems. So be forewarned and ask yourself if you really need REGEXP.
source to share