Search in sources :

Example 1 with Function

use of org.sqlite.Function in project translationstudio8 by heartsome.

the class TMDatabaseImpl method replaceTMOrTBConditionSql.

/**
	 * (non-Javadoc)
	 * @see net.heartsome.cat.database.DBOperator#replaceTMOrTBConditionSql(java.lang.String, java.lang.String, boolean,
	 *      boolean, boolean, java.lang.String, java.lang.String[])
	 */
public String replaceTMOrTBConditionSql(String sql, String strSearch, boolean isCaseSensitive, boolean isApplyRegular, boolean isIgnoreMark, String srcLang, String[] arrFilter) {
    strSearch = strSearch == null ? "" : strSearch;
    StringBuffer strCondition = new StringBuffer();
    if (srcLang != null) {
        strCondition.append(" AND A.LANG='" + srcLang + "'");
    } else {
        return null;
    }
    try {
        Function.create(conn, "sqliteRegexp", new Function() {

            protected void xFunc() {
                try {
                    if (args() == 2) {
                        String input = value_text(0);
                        String regex = value_text(1);
                        if (Pattern.matches(regex, input)) {
                            result(1);
                        } else {
                            result(0);
                        }
                    } else {
                        error("");
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (SQLException e) {
        e.printStackTrace();
    }
    if (isApplyRegular) {
        strCondition.append(" AND sqliteRegexp('" + (isIgnoreMark ? "A.PURE" : "A.CONTENT") + "','" + strSearch + "')==1");
    } else {
        strCondition.append(" AND " + (isIgnoreMark ? "A.PURE" : "A.CONTENT") + " LIKE '%" + /*TextUtil.cleanStringByLikeWithMsSql(*/
        strSearch + /*)*/
        "%'");
    }
    if (arrFilter != null) {
        StringBuffer strFilter = new StringBuffer(arrFilter[1] + " '%" + /*TextUtil.cleanStringByLikeWithMsSql(*/
        arrFilter[2] + /*)*/
        "%'");
        // 过滤条件要加在源语言中
        if (arrFilter[0].equalsIgnoreCase(srcLang)) {
            sql = Utils.replaceString(sql, "__TABLE_TEXTDATA__", "");
            strFilter.insert(0, " AND A.PURE ");
            strCondition.append(strFilter.toString());
        } else {
            sql = Utils.replaceString(sql, "__TABLE_TEXTDATA__", " ,TEXTDATA B ");
            strCondition.append(" AND A.GROUPID=B.GROUPID AND B.TYPE='M' AND B.LANG='" + arrFilter[0] + "'");
            strFilter.insert(0, " AND B.PURE ");
            strCondition.append(strFilter.toString());
        }
    } else {
        sql = Utils.replaceString(sql, "__TABLE_TEXTDATA__", "");
    }
    sql = Utils.replaceString(sql, "__CONDITION__", strCondition.toString());
    return sql;
}
Also used : CommonFunction(net.heartsome.cat.common.util.CommonFunction) Function(org.sqlite.Function) SQLException(java.sql.SQLException)

Aggregations

SQLException (java.sql.SQLException)1 CommonFunction (net.heartsome.cat.common.util.CommonFunction)1 Function (org.sqlite.Function)1