sqflite:如何制作“选择表”,例如word%word%;询问

发布于 2025-01-17 19:49:15 字数 860 浏览 0 评论 0原文

相同的值中有两个或多个实例,

例如:

'INSERT INTO todos(title, entidad, categoria, emision) VALUES ("title1", "e1", "fire, water, sky", "emi1"');

我是Flutter和SQFlite的新手,并且在“类别”列中有多个实例,在某些插入物中,我在 类别列

我想要的是编码查询类型“像” SQLite句子,其中包含我想要的单词。

我只有此代码在我的dbhelper.dart中,它可以正常工作。

Future<List<todo>> categoriaIdiomas() async {
    final db = await initializeDB();

    //this is the query
    final List<Map<String, dynamic>> queryResult =
        await db.rawQuery('SELECT * FROM todos WHERE categoria=?', ['water']);

    Map<String, dynamic> result = {};

    for (var r in queryResult) {
      result.addAll(r);
    }

    return queryResult.map((e) => todo.fromMap(e)).toList();
  }

我想知道如何在sqflite中制作这样的事情:

选择todos,其中类似于'%water%'>的todos”

I am new to flutter and SQFlite, and I have multiple instances in my 'category' column, in some inserts I have two or more instances in the same value separated by ","

For example:

'INSERT INTO todos(title, entidad, categoria, emision) VALUES ("title1", "e1", "fire, water, sky", "emi1"');

In that example I inserted two values ​​in the categories column

What i want is to code a query type "like" SQLite sentence, that contains the word i want.

I only have this code inside my dbhelper.dart, it works fine.

Future<List<todo>> categoriaIdiomas() async {
    final db = await initializeDB();

    //this is the query
    final List<Map<String, dynamic>> queryResult =
        await db.rawQuery('SELECT * FROM todos WHERE categoria=?', ['water']);

    Map<String, dynamic> result = {};

    for (var r in queryResult) {
      result.addAll(r);
    }

    return queryResult.map((e) => todo.fromMap(e)).toList();
  }

I would like to know how to make something like this in sqflite:

"SELECT todos WHERE categoria LIKE '%water%'"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谈情不如逗狗 2025-01-24 19:49:15

首先,删除 categoria 列中单词之间的空格,然后使用运算符 LIKE

await db.rawQuery("SELECT * FROM todos WHERE ',' || categoria || ',' LIKE '%,' || ? || ',%'", ["water"]);

First, remove the spaces between the words in column categoria and then use the operator LIKE:

await db.rawQuery("SELECT * FROM todos WHERE ',' || categoria || ',' LIKE '%,' || ? || ',%'", ["water"]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文