public static String[] arraySplit(String s, char separatorChar) { return arraySplit(s, separatorChar, true); }
/** * Overwrite the user name. The user name is case-insensitive and stored in * uppercase. English conversion is used. * * @param name the user name */ public void setUserName(String name) { this.user = StringUtils.toUpperEnglish(name); }
@Override public String getSQL(boolean isDistributed) { if (table == null) { return "*"; } return StringUtils.quoteIdentifier(table) + ".*"; }
@Override public String getSQL() { String s; if (type == Value.CLOB) { s = getString(); return StringUtils.quoteStringSQL(s); } byte[] buff = getBytes(); s = StringUtils.convertBytesToHex(buff); return "X'" + s + "'"; }
/** * Convert a string to a SQL literal. Null is converted to NULL. The text is * enclosed in single quotes. If there are any special characters, the method * STRINGDECODE is used. * * @param s the text to convert. * @return the SQL literal */ public static String quoteStringSQL(String s) { if (s == null) { return "NULL"; } int length = s.length(); StringBuilder buff = new StringBuilder(length + 2); buff.append('\''); for (int i = 0; i < length; i++) { char c = s.charAt(i); if (c == '\'') { buff.append(c); } else if (c < ' ' || c > 127) { // need to start from the beginning because maybe there was a \ // that was not quoted return "STRINGDECODE(" + quoteStringSQL(javaEncode(s)) + ")"; } buff.append(c); } buff.append('\''); return buff.toString(); }
@Override public String getCreateSQL() { StringBuilder buff = new StringBuilder("ALTER TABLE "); buff.append(table.getSQL()).append(" ADD CONSTRAINT "); if (table.isHidden()) { buff.append("IF NOT EXISTS "); } buff.append(getSQL()); if (comment != null) { buff.append(" COMMENT ").append(StringUtils.quoteStringSQL(comment)); } buff.append(" CHECK").append(StringUtils.enclose(expr.getSQL())).append(" NOCHECK"); return buff.toString(); }
break; case LTRIM: result = ValueString.get(StringUtils.trim(v0.getString(), true, false, v1 == null ? " " : v1.getString())); break; case TRIM: result = ValueString.get(StringUtils.trim(v0.getString(), true, true, v1 == null ? " " : v1.getString())); break; case RTRIM: result = ValueString.get(StringUtils.trim(v0.getString(), false, true, v1 == null ? " " : v1.getString())); break; case SUBSTR: break; case XMLATTR: result = ValueString.get(StringUtils.xmlAttr(v0.getString(), v1.getString())); break; case XMLNODE: { String content = v2 == null ? null : v2 == ValueNull.INSTANCE ? null : v2.getString(); boolean indent = v3 == null ? true : v3.getBoolean(); result = ValueString.get(StringUtils.xmlNode(v0.getString(), attr, content, indent)); break; .get(StringUtils.pad(v0.getString(), v1.getInt(), v2 == null ? null : v2.getString(), true)); break; case LPAD: result = ValueString .get(StringUtils.pad(v0.getString(), v1.getInt(), v2 == null ? null : v2.getString(), false)); break;
private void rewriteSql(boolean toReplicationMode) { if (session.isRoot()) { oldHostIds = db.getHostIds(); if (parameters != null && parameters.containsKey("hostIds")) { newHostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true); } else { if (toReplicationMode) newHostIds = NetEndpointManagerHolder.get().getReplicationEndpoints(db); else newHostIds = NetEndpointManagerHolder.get().getShardingEndpoints(db); } String hostIds = StringUtils.arrayCombine(oldHostIds, ',') + "," + StringUtils.arrayCombine(newHostIds, ','); db.getParameters().put("hostIds", hostIds); rewriteSql(); } else { if (super.isTargetEndpoint(db)) { oldHostIds = db.getHostIds(); HashSet<String> oldSet = new HashSet<>(Arrays.asList(oldHostIds)); if (parameters != null && parameters.containsKey("hostIds")) { String[] hostIds = StringUtils.arraySplit(parameters.get("hostIds"), ',', true); HashSet<String> newSet = new HashSet<>(Arrays.asList(hostIds)); newSet.removeAll(oldSet); newHostIds = newSet.toArray(new String[0]); } else { DbException.throwInternalError(); } } } }
@Override public String getSQL() { return StringUtils.quoteStringSQL(value); }
String[] keyValuePairs = StringUtils.arraySplit(options, ' ', false); for (String pair : keyValuePairs) { if (pair.length() == 0) { String key = StringUtils.trim(pair.substring(0, index), true, true, " "); String value = pair.substring(index + 1); char ch = value.length() == 0 ? 0 : value.charAt(0);
/** * Read a string. * * @return the value */ @Override public String readString() throws IOException { int len = in.readInt(); if (len == -1) { return null; } StringBuilder buff = new StringBuilder(len); for (int i = 0; i < len; i++) { buff.append(in.readChar()); } String s = buff.toString(); s = StringUtils.cache(s); return s; }
ResultSet rs = meta.getTables(null, StringUtils.escapeMetaDataPattern(schemaName), StringUtils.escapeMetaDataPattern(tableName), new String[] { "TABLE" }); if (!rs.next()) { return; rs = meta.getPrimaryKeys(null, StringUtils.escapeMetaDataPattern(schemaName), tableName); while (rs.next()) { String c = rs.getString("COLUMN_NAME"); key.add(toUpper ? StringUtils.toUpperEnglish(c) : c); rs = meta.getIndexInfo(null, StringUtils.escapeMetaDataPattern(schemaName), tableName, true, true); while (rs.next()) { int pos = rs.getShort("ORDINAL_POSITION"); key.add(toUpper ? StringUtils.toUpperEnglish(c) : c);
buff.append("(\n"); buff.append(StringUtils.indent(nested, 4, false)); if (enclose) { buff.append(')'); buff.append(StringUtils.unEnclose(joinCondition.getSQL())); String plan = StringUtils.quoteRemarkSQL(planBuff.toString()); if (plan.indexOf('\n') >= 0) { plan += "\n"; buff.append(StringUtils.indent("/* " + plan + " */", 4, false)); buff.append(StringUtils.unEnclose(joinCondition.getSQL())); String condition = StringUtils.unEnclose(filterCondition.getSQL()); condition = "/* WHERE " + StringUtils.quoteRemarkSQL(condition) + "\n*/"; buff.append(StringUtils.indent(condition, 4, false));
/** * Format a byte array to the Java source code that represents this object. * * @param x the byte array to convert * @return the Java source code */ protected static String quoteBytes(byte[] x) { if (x == null) { return "null"; } return "org.lealone.util.StringUtils.convertHexToBytes(\"" + StringUtils.convertBytesToHex(x) + "\")"; }
/** * Indents a string with 4 spaces. * * @param s the string * @return the indented string */ public static String indent(String s) { return indent(s, 4, true); }
/** * In a string, replace block comment marks with /++ .. ++/. * * @param sql the string * @return the resulting string */ public static String quoteRemarkSQL(String sql) { sql = replaceAll(sql, "*/", "++/"); return replaceAll(sql, "/*", "/++"); }
buff.appendExceptFirst(","); buff.append('\n'); buff.append(StringUtils.indent(exprList[i].getSQL(isDistributed), 4, false)); buff.append("\nWHERE ").append(StringUtils.unEnclose(condition.getSQL())); g = g.getNonAliasExpression(); buff.appendExceptFirst(", "); buff.append(StringUtils.unEnclose(g.getSQL(isDistributed))); for (Expression g : group) { buff.appendExceptFirst(", "); buff.append(StringUtils.unEnclose(g.getSQL(isDistributed))); buff.append("\nHAVING ").append(StringUtils.unEnclose(h.getSQL(isDistributed))); } else if (havingIndex >= 0) { Expression h = exprList[havingIndex]; buff.append("\nHAVING ").append(StringUtils.unEnclose(h.getSQL(isDistributed))); for (SelectOrderBy o : orderList) { buff.appendExceptFirst(", "); buff.append(StringUtils.unEnclose(o.getSQL())); buff.append("\nLIMIT ").append(StringUtils.unEnclose(limitExpr.getSQL(isDistributed))); if (offsetExpr != null) { buff.append(" OFFSET ").append(StringUtils.unEnclose(offsetExpr.getSQL(isDistributed))); buff.append("\nSAMPLE_SIZE ").append(StringUtils.unEnclose(sampleSizeExpr.getSQL()));
private String identifier(String s) { if (database.getMode().lowerCaseIdentifiers) { s = s == null ? null : StringUtils.toLowerEnglish(s); } return s; }
} else if (equalsToken("X", name)) { read(); byte[] buffer = StringUtils.convertHexToBytes(currentValue.getString()); r = ValueExpression.get(ValueBytes.getNoCopy(buffer)); } else if (equalsToken("E", name)) { text = StringUtils.replaceAll(text, "\\\\", "\\"); read(); r = ValueExpression.get(ValueString.get(text));
trimmed = trimmed.substring(0, trimmed.length() - 1); String lower = StringUtils.toLowerEnglish(trimmed); if ("exit".equals(lower) || "quit".equals(lower)) { break; boolean addToHistory = true; if (statement == null) { if (StringUtils.isNumber(line)) { int pos = Integer.parseInt(line); if (pos == 0 || pos > history.size()) {