我知道这是一个老问题,但如果您使用 Java 编码并遇到此问题,这可能会有所帮助。您可以注册一个处理类似检查的函数。我收到了这篇帖子的提示:https://stackoverflow.com/a/29831950/1271573
我依赖sqlite jdbc的解决方案:https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
在我的情况下,我只需要查看某个字符串是否作为另一个字符串的一部分存在(例如 '%mystring%'),所以我创建了一个 Contains 函数,但应该可以扩展它以执行更多 sql - 使用正则表达式或其他东西进行检查。
要在 SQL 中使用该函数来查看 MyCol 是否包含“搜索字符串”,您可以这样做:
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());
}