Room使用过程中遇到的问题记录

作者: waiwaaa | 来源:发表于2019-07-26 11:32 被阅读9次

1.关于查询

模糊查询查询可以用likeglob,具体用法

LIKE

LIKE用来匹配通配符指定模式的文本值。如果搜索表达式与模式表达式匹配,LIKE 运算符将返回真(true),也就是 1。这里有两个通配符与 LIKE 运算符一起使用,百分号(%)代表零个、一个或多个数字或字符。下划线(_)代表一个单一的数字或字符。这些符号可以被组合使用。

1、查找字段A以AAA开头的任意值
  select * from table_name where 字段A like 'AAA%'
2、查找字段A任意位置包含AAA的任意值
  select * from table_name where 字段A like '%AAA%'
3、查找字段A第二位和第三位为 AA 的任意值
  select *from table_name where 字段A like '_AA%'
4、查找字段A以 A 开头,且长度至少为 3 个字符的任意值
  select * from table_name where 字段A like 'A_%_%'
5、查找字段A以 A 结尾的任意值
  select *from table_name where 字段A like '%A'
6、查找字段A第二位为 A,且以 B 结尾的任意值
  select *from table_name where 字段A like '_A%B'
7、查找字段A长度为 5 位数,且以 A 开头以 B 结尾的任意值(A,B中间三个下划线)
  select *from table_name where 字段A like 'A___B'

GLOB

SQLite 的 GLOB 运算符是用来匹配通配符指定模式的文本值。如果搜索表达式与模式表达式匹配,GLOB 运算符将返回真(true),也就是 1。与 LIKE 运算符不同的是,GLOB 是大小写敏感的,对于下面的通配符,它遵循 UNIX 的语法。
星号(*)代表零个、一个或多个数字或字符。问号(?)代表一个单一的数字或字符。这些符号可以被组合使用。
1、查找字段A以AAA开头的任意值
  select * from table_name where 字段A GLOB 'AAA*'
2、查找字段A任意位置包含AAA的任意值
  select * from table_name where 字段A GLOB '*AAA*'
3、查找字段A第二位和第三位为 AA 的任意值
  select *from table_name where 字段A GLOB '?AA*'
4、查找字段A以 A 开头,且长度至少为 3 个字符的任意值
  select * from table_name where 字段A GLOB 'A?*?*'
5、查找字段A以 A 结尾的任意值
  select *from table_name where 字段A GLOB '*A'
6、查找字段A第二位为 A,且以 B 结尾的任意值
  select *from table_name where 字段A GLOB '?A*B'
7、查找字段A长度为 5 位数,且以 A 开头以 B 结尾的任意值(A,B中间三个下划线)
  select *from table_name where 字段A GLOB 'A???B'

在room中,真接写 LIKE '% :key %'或者 "LIKE '%"+:key+“% '"都有问题,正确写法如下:
@Query("SELECT * FROM tb_use WHERE Name LIKE '%' || :name || '%')
参考

2.Room升级问题

androidx.room 数据库升级Migration ,创建表及更改表时,字段为Integer(包括boolean)需设置NOT NULL
不然报 :java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/user/0/com.xxxx/databases/.....

java.lang.IllegalStateException: Migration didn't properly handle ChatRecordSchedule(xxx.model.ChatRecordSchedule).
TableInfo{name='ChatRecordSchedule', columns={wechatAccountId=Column{name='wechatAccountId', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1}, chatId=Column{name='chatId', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=2}, last=Column{name='last', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, bottom=Column{name='bottom', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, from=Column{name='from', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, to=Column{name='to', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, state=Column{name='state', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, type=Column{name='type', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=3}}, foreignKeys=[], indices=[]}
 Found:
TableInfo{name='ChatRecordSchedule', columns={wechatAccountId=Column{name='wechatAccountId', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=1}, chatId=Column{name='chatId', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=2}, last=Column{name='last', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, bottom=Column{name='bottom', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}, from=Column{name='from', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, to=Column{name='to', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=0}, state=Column{name='state', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=0}, type=Column{name='type', type='INTEGER', affinity='3', notNull=true, primaryKeyPosition=3}}, foreignKeys=[], indices=[]}

相关文章

  • Room使用过程中遇到的问题记录

    1.关于查询 模糊查询查询可以用like或glob,具体用法 LIKE LIKE用来匹配通配符指定模式的文本值。如...

  • Room数据库迁移记录

    记录一下Room数据库迁移过程中遇到的问题。要迁移Room数据库,只要需要实现androidx.room.migr...

  • sql目录

    记录MySQL使用过程中(工作或者开发过程中遇到的问题) MySQL导出文件中遇到的问题 MySQL使用索引提高查...

  • 开源项目使用问题集锦

    本文用于记录一些开源项目,在使用过程中遇到的问题,如:GridView with Header and Foote...

  • MySql和Oracle的使用

    本文档是一个记录文档,会不定时更新使用过程中遇到的差异问题本文档记录MySql和Oracle在使用中要注意的问题,...

  • mysql常见实战例子

    1、前言 myql在实战使用过程中会遇到不同的场景,针对不同场景,使用方式需要整理记录,给以后遇到类似问题做参考使...

  • Canal数据堆积

    记录一下canal的问题。数据同步一直使用阿里开源的canal,最近使用过程中遇到一些问题,在这里记录一下。 原因...

  • Hive的坑

    概述 我们的Hive是HortonWorks提供的1.2.1, 本文档记录下我们在使用过程中遇到的问题和解决方法。...

  • 当决定使用 Ubuntu 来开发时

    本篇文章主要持续记录和总结 ubuntu 的必备基础和使用过程中遇到的各种问题 安装 下载 Ubuntu Kyli...

  • 【项目管理】在Jira中关闭问题

    工作中遇到Jira使用细节,在这里记录探讨和明确Jira使用过程中的两个问题 问题如何结束 问题包括人物,技术改造...

网友评论

    本文标题:Room使用过程中遇到的问题记录

    本文链接:https://www.haomeiwen.com/subject/izcuxctx.html