我知道这是一个老问题,但如果你在使用Java编码并遇到了这个问题,这可能会有所帮助。您可以注册一个处理类似检查的函数。我从这篇文章中得到了贴士:
https://dev59.com/h07Sa4cB1Zd3GeqP7uYF#29831950
解决方案依赖于sqlite jdbc:
https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
在我的情况下,我只需要查看某个字符串是否作为另一个字符串的一部分存在(如'%mystring%'),因此我创建了Contains函数,但应该可以扩展此功能以使用正则表达式或其他方式进行更多类似SQL的检查。
要在SQL中使用该函数来查看MyCol是否包含“searchstring”,您需要执行以下操作:
select * from mytable where Contains(MyCol, 'searchstring')
以下是我的Contains函数:
public class Contains extends Function {
@Override
protected void xFunc() throws SQLException {
if (args() != 2) {
throw new SQLException("Contains(t1,t2): Invalid argument count. Requires 2, but found " + args());
}
String testValue = value_text(0).toLowerCase();
String isLike = value_text(1).toLowerCase();
if (testValue.contains(isLike)) {
result(1);
} else {
result(0);
}
}
}
要使用此功能,您必须先注册它。当您完成使用后,可以选择销毁它。以下是操作步骤:
public static void registerContainsFunc(Connection con) throws SQLException {
Function.create(con, Contains.class.getSimpleName(), new Contains());
}
public static void destroyContainsFunc(Connection con) throws SQLException {
Function.destroy(con, Contains.class.getSimpleName());
}