Details
-
Bug
-
Resolution: Cannot Reproduce
-
Not Evaluated
-
None
-
6.8.2
-
None
-
Using the first method can not find the result, using the second method can find the result. Here's why. When mid1[0] = "12345678901";
mid1[1] = "12345678901"; Change mid1[0] = "123456789";
If mid1[1] = "123456789", the preceding two methods can be queried. It feels like the first query method has a query length limit, but I already have enough length when creating the database table, so there is a BUG here.Using the first method can not find the result, using the second method can find the result. Here's why. When mid1[0] = "12345678901"; mid1[1] = "12345678901"; Change mid1[0] = "123456789"; If mid1[1] = "123456789", the preceding two methods can be queried. It feels like the first query method has a query length limit, but I already have enough length when creating the database table, so there is a BUG here.
Description
Using the first method can not find the result, using the second method can find the result.
int main(int argc, char* argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setDatabaseName("testdb"); db.setHostName("192.168.178.128"); db.setUserName("testuser"); db.setPassword("testuser"); if (!db.open()) { qDebug() << db.lastError(); return 0; } QSqlQuery query; QString createTableQuery = R"( CREATE TABLE IF NOT EXISTS account_information123 ( account VARCHAR(30) NOT NULL, pass_word VARCHAR(30) NOT NULL, role1_id VARCHAR(30), role1_name VARCHAR(30), role1_lv VARCHAR(30), role1_occupation VARCHAR(30), PRIMARY KEY (account) ); )"; if (!query.exec(createTableQuery)) { qDebug() << query.lastError(); return 0; } QString insertQuery = R"( INSERT INTO account_information123 (account, pass_word, role1_id, role1_name, role1_lv, role1_occupation) VALUES ('12345678901', '12345678901', '12345678901', '雷', '10', '2'); )"; if (!query.exec(insertQuery)) { qDebug() << query.lastError(); return 0; } QString mid1[2]; mid1[0] = "12345678901"; mid1[1] = "12345678901"; //The first query method { QSqlQuery q(db); q.prepare("SELECT role1_id, role1_name, role1_lv, role1_occupation " "FROM account_information123 WHERE account = :account AND pass_word = :pass_word "); q.bindValue(":account", mid1[0]); q.bindValue(":pass_word", mid1[1]); if (!q.exec() ||!q.next()) { qDebug() << q.lastError(); return 0; } QString message = QString("Role1 ID: %1, Name: %2, Level: %3, Occupation: %4\n") .arg(q.value("role1_id").toString()) .arg(q.value("role1_name").toString()) .arg(q.value("role1_lv").toString()) .arg(q.value("role1_occupation").toString()); qDebug() << "The result of the query using the first method:" << message; } //The second query method { QString queryString = QString("SELECT role1_id,role1_name,role1_lv,role1_occupation FROM account_information123 WHERE account=%1 && pass_word =%2") .arg(mid1[0]).arg(mid1[1]); QSqlQuery q(queryString, db); if (!q.exec() || !q.first()) { qDebug() << q.lastError(); return 1; } QString message; QSqlRecord record = q.record(); int columnCount = record.count(); for (int i = 0; i < columnCount; ++i) { message += q.value(i).toString(); message += "~"; } qDebug() << "The result of the query using the second method:" << message; } query.exec("DROP TABLE account_information123"); return 0; }
--> output:
The result of the query using the first method: "Role1 ID: 12345678901, Name: 雷, Level: 10, Occupation: 2\n"
The result of the query using the second method: "12345678901~雷~10~2~"