Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

? is not recognized as parameter in '?' #316

Closed
alfianpp opened this issue Nov 24, 2019 · 10 comments
Closed

? is not recognized as parameter in '?' #316

alfianpp opened this issue Nov 24, 2019 · 10 comments

Comments

@alfianpp
Copy link

Hello,
I am using sqflite: ^1.1.7+2
I experienced something strange when I run this code:

db.query(
   tableName,
   where: 'title LIKE \'%?%\'',
   whereArgs: [search],
);

I got error:

DatabaseException(Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters.) sql 'SELECT * FROM anime WHERE title LIKE '%?%'' args [a]}

I tried to change it to:

db.query(
   tableName,
   where: "title LIKE '%?%'",
   whereArgs: [search],
);

but still got same error.
But, if I do like this:

db.query(
   tableName,
   where: 'title LIKE \'%$search%\'',
);

It working.
Sorry if this question asked already,

@alextekartik
Copy link
Contributor

I think the percent character should be in the parameter, not in the query. Can you try something like this:

db.query(
   tableName,
   where: "title LIKE ?",
   whereArgs: ['%$search%'],
);

@alfianpp
Copy link
Author

Okay, it working, thank you.

@liemvo
Copy link

liemvo commented Jul 6, 2020

@alextekartik
My query as below:

db.query(tableName,
          columns: [_columnId, _columnWord, _columnContent],
          where: "$_columnWord LIKE ?",
          whereArgs: ['$query%'],
          orderBy: '$_columnId desc');

Then I got the error:
E/SQLiteLog(22392): (11) statement aborts at 11: [SELECT id, word, content FROM table WHERE word LIKE ? ORDER BY id desc] database disk image is malformed

@alextekartik
Copy link
Contributor

That sounds like a different issue. database disk image is malformed means your database is not a SQLite file or corrupted. To isolate the issue, does calling await db.getVersion() work?

@liemvo
Copy link

liemvo commented Jul 6, 2020

I can query the items from this table without any errors, but after performing the above command then I got the error.

@alextekartik
Copy link
Contributor

It looks like a database corruption issue: https://sqliteviewer.com/blog/database-disk-image-malformed

Your query looks fine to me.

@liemvo
Copy link

liemvo commented Jul 7, 2020

When I replace the where condition:

 where: "$_columnWord = ?",
 whereArgs: [query]

It works without error but the result is only one item that is the reason I want to use the like :(.

Thank you for your message.

@alextekartik
Copy link
Contributor

It seems that when the database is corrupted it does not fail for all queries. Why it fails on this one I don't know. You should try to fix the database (https://www.sqlite.org/faq.html#q21) first. If you want can either attach your db file or send it to me (alex@tekartik.com) so I can take a closer look.

This is different from the original issue so it might be better to create a new issue to continue tracking this.

@liemvo
Copy link

liemvo commented Jul 10, 2020

Thank you for helping, I solve the problem by fixing my database.

@alextekartik
Copy link
Contributor

@liemvo Great! I'll be interested in knowing the steps (external tool, pragma...) you did in case someone else encounter this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants