REGEXP无法使用SQLITE执行QSqluery

时间:2022-12-25 04:15:03

I'm trying to do the following:

我正在尝试执行以下操作:

QSqlQueryModel *model = new QSqlQueryModel();
QSqlQuery *qry = new QSqlQuery(mydb);
QString qstr = "Select * from table WHERE Name REGEXP ";
qstr.append("'");
qstr.append(m_filterText);
qstr.append("'");
qry->prepare(qstr);
qry->exec();
model->setQuery(*qry);

It's not returning anything and the following error is recorded:

它没有返回任何内容,并记录以下错误:

No query Unable to fetch row

无查询无法获取行

Any idea on why this is happening? If I run this in sqlite3 shell, it works. Seems like the QSQLITE adapter is missing a REGEXP definition. Not sure.

知道为什么会这样吗?如果我在sqlite3 shell中运行它,它可以工作。好像QSQLITE适配器缺少REGEXP定义。不确定。

1 个解决方案

#1


0  

As mentioned in the comments you really should have a talk with Bobby Tables...

正如评论中提到的,你真的应该和Bobby Tables谈谈......

Besides that, SQLITE has a REGEXP operation defined but it's not implemented by SQLITE. So every framework etc has to do it separately. Unfortunately, Qt does not have it implemented thus your query, once defined right, will not work.

除此之外,SQLITE还定义了REGEXP操作,但它没有由SQLITE实现。所以每个框架都必须单独完成。不幸的是,Qt没有实现它,因此一旦定义正确,您的查询将无法工作。

You either have to implement REGEXP yourself or wait until Qt 5.10. Then Qt will provide a basic implementation: http://doc-snapshots.qt.io/qt5-dev/sql-driver.html#enable-regexp-operator.

您要么自己实施REGEXP,要么等到Qt 5.10。然后Qt将提供一个基本实现:http://doc-snapshots.qt.io/qt5-dev/sql-driver.html#enable-regexp-operator。

#1


0  

As mentioned in the comments you really should have a talk with Bobby Tables...

正如评论中提到的,你真的应该和Bobby Tables谈谈......

Besides that, SQLITE has a REGEXP operation defined but it's not implemented by SQLITE. So every framework etc has to do it separately. Unfortunately, Qt does not have it implemented thus your query, once defined right, will not work.

除此之外,SQLITE还定义了REGEXP操作,但它没有由SQLITE实现。所以每个框架都必须单独完成。不幸的是,Qt没有实现它,因此一旦定义正确,您的查询将无法工作。

You either have to implement REGEXP yourself or wait until Qt 5.10. Then Qt will provide a basic implementation: http://doc-snapshots.qt.io/qt5-dev/sql-driver.html#enable-regexp-operator.

您要么自己实施REGEXP,要么等到Qt 5.10。然后Qt将提供一个基本实现:http://doc-snapshots.qt.io/qt5-dev/sql-driver.html#enable-regexp-operator。