the sqlite database table is created as:
<code> CREATE TABLE Books (id INTEGER PRIMARY KEY AUTOINCREMENT, path TEXT, hash blob);
CREATE UNIQUE INDEX path_uni ON Books(path);
CREATE UNIQUE INDEX hash_uni ON Books(hash);
</code>
<code> CREATE TABLE Books (id INTEGER PRIMARY KEY AUTOINCREMENT, path TEXT, hash blob);
CREATE UNIQUE INDEX path_uni ON Books(path);
CREATE UNIQUE INDEX hash_uni ON Books(hash);
</code>
CREATE TABLE Books (id INTEGER PRIMARY KEY AUTOINCREMENT, path TEXT, hash blob);
CREATE UNIQUE INDEX path_uni ON Books(path);
CREATE UNIQUE INDEX hash_uni ON Books(hash);
and after insert some data into the database, I tried querying the “hash” column as below:
<code>final int id = 1;
database?.query('Books', where: 'id= ?', whereArgs: [id]).then(
(rows) {
if (rows.isEmpty) {
// do something...
} else {
final hash = rows.first['hash'] as Uint8List;
print('hash: $hash'); // the printed hash is correct, 16 bytes array
// use the "hash" from query result as a known existed value to do the next query:
database?.query('Books', where: 'hash = ?', whereArgs: [hash]).then(
(rows) {
print('query hash: $rows'); // here print a empty list "[]"
});
}
});
</code>
<code>final int id = 1;
database?.query('Books', where: 'id= ?', whereArgs: [id]).then(
(rows) {
if (rows.isEmpty) {
// do something...
} else {
final hash = rows.first['hash'] as Uint8List;
print('hash: $hash'); // the printed hash is correct, 16 bytes array
// use the "hash" from query result as a known existed value to do the next query:
database?.query('Books', where: 'hash = ?', whereArgs: [hash]).then(
(rows) {
print('query hash: $rows'); // here print a empty list "[]"
});
}
});
</code>
final int id = 1;
database?.query('Books', where: 'id= ?', whereArgs: [id]).then(
(rows) {
if (rows.isEmpty) {
// do something...
} else {
final hash = rows.first['hash'] as Uint8List;
print('hash: $hash'); // the printed hash is correct, 16 bytes array
// use the "hash" from query result as a known existed value to do the next query:
database?.query('Books', where: 'hash = ?', whereArgs: [hash]).then(
(rows) {
print('query hash: $rows'); // here print a empty list "[]"
});
}
});
I can ensure all the table names and column names are correct without spelling error.
So, why is the hash-query result is empty?
I have tried use hexHash to query the database, and still get nothing back.
<code>final String hashToCheckHex = hash.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join('');
database?.query('Books', where: 'hex(hash) = ?', whereArgs: [hashToCheckHex]).then(
(rows) {
print('query hash: $rows'); // still get nothing.
});
</code>
<code>final String hashToCheckHex = hash.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join('');
database?.query('Books', where: 'hex(hash) = ?', whereArgs: [hashToCheckHex]).then(
(rows) {
print('query hash: $rows'); // still get nothing.
});
</code>
final String hashToCheckHex = hash.map((byte) => byte.toRadixString(16).padLeft(2, '0')).join('');
database?.query('Books', where: 'hex(hash) = ?', whereArgs: [hashToCheckHex]).then(
(rows) {
print('query hash: $rows'); // still get nothing.
});
New contributor
murphy.z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.