@Test public void appendSQLTextValue() { CompanyDB db = new CompanyDB(); DBDatabaseDriver driver = new DBDatabaseDriverMySQL(); db.open(driver, null); Departments TD = db.DEPARTMENT; DBCommand cmd = db.createCommand(); cmd.select(TD.count()); cmd.where(TD.NAME.is("\\LCI\\")); assertTrue(cmd.getSelect().endsWith(("`NAME`='\\\\LCI\\\\'"))); cmd = db.createCommand(); cmd.select(TD.count()); cmd.where(TD.NAME.is("'")); assertTrue(cmd.getSelect().contains("`NAME`=''''")); cmd = db.createCommand(); cmd.select(TD.count()); cmd.where(TD.NAME.is("Tarkk\\'ampujankatu")); assertTrue(cmd.getSelect().contains("`NAME`='Tarkk\\\\''ampujankatu'")); }
@Override protected void appendSQLTextValue(StringBuilder buf, String value) { if (value.indexOf('\'') >= 0 || value.indexOf('\\') >= 0) { int len = value.length(); for (int i = 0; i < len; i++) { if (value.charAt(i) == '\'') { buf.append("''"); } else if (value.charAt(i) == '\\') { buf.append("\\\\"); } else { buf.append(value.charAt(i)); } } } else { buf.append(value); } }
DBDatabaseDriverMySQL extends DBDatabaseDriver { @Override protected void appendSQLTextValue(StringBuilder buf, String value) { if (value.indexOf('\'') >= 0 || value.indexOf('\\') >= 0) { int len = value.length(); for (int i = 0; i < len; i++) { if (value.charAt(i) == '\'') { buf.append("''"); } else if (value.charAt(i) == '\\') { buf.append("\\\\"); } else { buf.append(value.charAt(i)); } } } else { buf.append(value); } } }
DBDatabaseDriverMySQL extends DBDatabaseDriver { @Override protected void appendSQLTextValue(StringBuilder buf, String value) { if (value.indexOf('\'') >= 0 || value.indexOf('\\') >= 0) { int len = value.length(); for (int i = 0; i < len; i++) { if (value.charAt(i) == '\'') { buf.append("''"); } else if (value.charAt(i) == '\\') { buf.append("\\\\"); } else { buf.append(value.charAt(i)); } } } else { buf.append(value); } } DBDatabaseDriverMySQL(); }
DBDatabaseDriverMySQL extends DBDatabaseDriver { @Override protected void appendSQLTextValue(StringBuilder buf, String value) { if (value.indexOf('\'') >= 0 || value.indexOf('\\') >= 0) { int len = value.length(); for (int i = 0; i < len; i++) { if (value.charAt(i) == '\'') { buf.append("''"); } else if (value.charAt(i) == '\\') { buf.append("\\\\"); } else { buf.append(value.charAt(i)); } } } else { buf.append(value); } } DBDatabaseDriverMySQL(); String getDatabaseName(); void setDatabaseName(String databaseName); String getCharacterSet(); void setCharacterSet(String characterSet); String getEngine(); void setEngine(String engine); boolean isUseSequenceTable(); void setUseSequenceTable(boolean useSequenceTable); String getSequenceTableName(); void setSequenceTableName(String sequenceTableName); @Override void attachDatabase(DBDatabase db, Connection conn); @Override DBCommand createCommand(DBDatabase db); @Override /** * Creates a combined command that supports limit() and skip() * @param left the first DBCommandExpr object * @param keyWord the key word between the two DBCommandExpr objects * @param right the second DBCommandExpr object * @return the new DBCommandExpr object */ DBCommandExpr createCombinedCommand(DBCommandExpr left, String keyWord, DBCommandExpr right); @Override boolean isSupported(DBDriverFeature type); @Override String getSQLPhrase(int phrase); @Override String getConvertPhrase(DataType destType, DataType srcType, Object format); @Override Object getNextSequenceValue(DBDatabase db, String seqName, int minValue, Connection conn); @Override DBColumnExpr getNextSequenceValueExpr(DBTableColumn column); @Override java.sql.Timestamp getUpdateTimestamp(Connection conn); @Override void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script); }
DBDatabaseDriverMySQL extends DBDatabaseDriver { @Override protected void appendSQLTextValue(StringBuilder buf, String value) { if (value.indexOf('\'') >= 0 || value.indexOf('\\') >= 0) { int len = value.length(); for (int i = 0; i < len; i++) { if (value.charAt(i) == '\'') { buf.append("''"); } else if (value.charAt(i) == '\\') { buf.append("\\\\"); } else { buf.append(value.charAt(i)); } } } else { buf.append(value); } } DBDatabaseDriverMySQL(); String getDatabaseName(); void setDatabaseName(String databaseName); String getCharacterSet(); void setCharacterSet(String characterSet); String getEngine(); void setEngine(String engine); boolean isUseSequenceTable(); void setUseSequenceTable(boolean useSequenceTable); String getSequenceTableName(); void setSequenceTableName(String sequenceTableName); @Override void attachDatabase(DBDatabase db, Connection conn); @Override DBCommand createCommand(DBDatabase db); @Override /** * Creates a combined command that supports limit() and skip() * @param left the first DBCommandExpr object * @param keyWord the key word between the two DBCommandExpr objects * @param right the second DBCommandExpr object * @return the new DBCommandExpr object */ DBCommandExpr createCombinedCommand(DBCommandExpr left, String keyWord, DBCommandExpr right); @Override boolean isSupported(DBDriverFeature type); @Override String getSQLPhrase(int phrase); @Override String getConvertPhrase(DataType destType, DataType srcType, Object format); @Override Object getNextSequenceValue(DBDatabase db, String seqName, int minValue, Connection conn); @Override DBColumnExpr getNextSequenceValueExpr(DBTableColumn column); @Override java.sql.Timestamp getUpdateTimestamp(Connection conn); @Override void getDDLScript(DBCmdType type, DBObject dbo, DBSQLScript script);  }