#include <QtCore>
#include <QtSql>
#include <QDebug>
void createTestData()
{
db.setDatabaseName("test.db");
if (db.open()) {
query.exec("create table irisdata ("
"userid varchar(20), "
"iriscode1 blob, "
"iriscode2 blob, "
"iriscode3 blob, "
"primary key(userid) )");
if (query.prepare( "insert into irisdata ("
"userid, iriscode1, iriscode2, iriscode3) "
"values (?, ?, ?, ?)" )) {
for (int i=0; i<100; ++i) {
query.
bindValue(0,
QString("User %1").
arg(i
));
query.bindValue(1, blobData1);
query.bindValue(2, blobData2);
query.bindValue(3, blobData3);
query.exec();
}
}
}
}
{
if (query.prepare(
"select userid from irisdata "
"where iriscode1 = ? OR iriscode2 = ? or iriscode3 = ?") ) {
query.bindValue(0, ba);
query.bindValue(1, ba);
query.bindValue(2, ba);
if (query.exec()) {
while (query.next())
qDebug() << "Found" << query.value(0).toString();
}
}
}
int main(int argc, char *argv[])
{
createTestData();
queryTestData
(QByteArray(10, 0x00
));
// does not exist}
#include <QtCore>
#include <QtSql>
#include <QDebug>
void createTestData()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (db.open()) {
QSqlQuery query;
query.exec("create table irisdata ("
"userid varchar(20), "
"iriscode1 blob, "
"iriscode2 blob, "
"iriscode3 blob, "
"primary key(userid) )");
if (query.prepare( "insert into irisdata ("
"userid, iriscode1, iriscode2, iriscode3) "
"values (?, ?, ?, ?)" )) {
for (int i=0; i<100; ++i) {
QByteArray blobData1(i+1, 'a');
QByteArray blobData2(i+1, 'b');
QByteArray blobData3(i+1, 0x83);
query.bindValue(0, QString("User %1").arg(i));
query.bindValue(1, blobData1);
query.bindValue(2, blobData2);
query.bindValue(3, blobData3);
query.exec();
}
}
}
}
void queryTestData(const QByteArray &ba)
{
QSqlDatabase db = QSqlDatabase::database();
QSqlQuery query;
if (query.prepare(
"select userid from irisdata "
"where iriscode1 = ? OR iriscode2 = ? or iriscode3 = ?") ) {
query.bindValue(0, ba);
query.bindValue(1, ba);
query.bindValue(2, ba);
if (query.exec()) {
while (query.next())
qDebug() << "Found" << query.value(0).toString();
}
}
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
createTestData();
queryTestData(QByteArray(3, 'a')); // user 2
queryTestData(QByteArray(5, 'b')); // user 4
queryTestData(QByteArray(10, 0x83)); // user 9
queryTestData(QByteArray(10, 0x00)); // does not exist
}
To copy to clipboard, switch view to plain text mode
Should work against a Mysql or other database also.
Bookmarks