@Test public void testGetConvertPhrase() { DBDatabaseDriver driver = new DBDatabaseDriverMySQL(); assertEquals("CAST(? AS UNSIGNED)", driver.getConvertPhrase(DataType.BOOL, null, null)); assertEquals("CAST(? AS UNSIGNED)", driver.getConvertPhrase(DataType.BOOL, null, "test")); assertEquals("CAST(? AS SIGNED)", driver.getConvertPhrase(DataType.INTEGER, null, null)); assertEquals("CAST(? AS SIGNED)", driver.getConvertPhrase(DataType.INTEGER, null, "test")); assertEquals("CAST(? AS DECIMAL)", driver.getConvertPhrase(DataType.DECIMAL, null, null)); assertEquals("CAST(? AS DECIMAL)", driver.getConvertPhrase(DataType.DECIMAL, null, "test")); assertEquals("CAST(? AS DECIMAL)", driver.getConvertPhrase(DataType.FLOAT, null, null)); assertEquals("CAST(? AS DECIMAL)", driver.getConvertPhrase(DataType.FLOAT, null, "test")); assertEquals("CAST(? AS DATE)", driver.getConvertPhrase(DataType.DATE, null, null)); assertEquals("CAST(? AS DATE)", driver.getConvertPhrase(DataType.DATE, null, "test")); assertEquals("CAST(? AS DATETIME)", driver.getConvertPhrase(DataType.TIMESTAMP, null, null)); assertEquals("CAST(? AS DATETIME)", driver.getConvertPhrase(DataType.DATETIME, null, "test")); assertEquals("CAST(? AS CHAR CHARACTER SET cp1250)", driver.getConvertPhrase(DataType.VARCHAR, null, "CHARACTER SET cp1250")); assertEquals("CAST(? AS CHAR)", driver.getConvertPhrase(DataType.VARCHAR, null, null)); assertEquals("CAST(? AS BLOB)", driver.getConvertPhrase(DataType.BLOB, null, null)); assertEquals("CAST(? AS BLOB)", driver.getConvertPhrase(DataType.BLOB, null, "test")); assertEquals("?", driver.getConvertPhrase(DataType.AUTOINC, null, null)); assertEquals("?", driver.getConvertPhrase(DataType.AUTOINC, null, "test")); }
@Override public String getConvertPhrase(DataType destType, DataType srcType, Object format) { switch(destType) { case BOOL: return "CAST(? AS UNSIGNED)"; case INTEGER: return "CAST(? AS SIGNED)"; case DECIMAL: return "CAST(? AS DECIMAL)"; case FLOAT: return "CAST(? AS DECIMAL)"; case DATE: return "CAST(? AS DATE)"; case DATETIME: case TIMESTAMP: return "CAST(? AS DATETIME)"; case TEXT: case VARCHAR: case CHAR: if (format != null) { return "CAST(? AS CHAR " + format.toString() + ")"; } else { return "CAST(? AS CHAR)"; } case BLOB: return "CAST(? AS BLOB)"; default: log.error("getConvertPhrase: unknown type " + destType); return "?"; } }
DBDatabaseDriverMySQL extends DBDatabaseDriver { @Override public String getConvertPhrase(DataType destType, DataType srcType, Object format) { switch(destType) { case BOOL: return "CAST(? AS UNSIGNED)"; case INTEGER: return "CAST(? AS SIGNED)"; case DECIMAL: return "CAST(? AS DECIMAL)"; case FLOAT: return "CAST(? AS DECIMAL)"; case DATE: return "CAST(? AS DATE)"; case DATETIME: case TIMESTAMP: return "CAST(? AS DATETIME)"; case TEXT: case VARCHAR: case CHAR: if (format != null) { return "CAST(? AS CHAR " + format.toString() + ")"; } else { return "CAST(? AS CHAR)"; } case BLOB: return "CAST(? AS BLOB)"; default: log.error("getConvertPhrase: unknown type " + destType); return "?"; } } }
DBDatabaseDriverMySQL extends DBDatabaseDriver { @Override public String getConvertPhrase(DataType destType, DataType srcType, Object format) { switch(destType) { case BOOL: return "CAST(? AS UNSIGNED)"; case INTEGER: return "CAST(? AS SIGNED)"; case DECIMAL: return "CAST(? AS DECIMAL)"; case FLOAT: return "CAST(? AS DECIMAL)"; case DATE: return "CAST(? AS DATE)"; case DATETIME: case TIMESTAMP: return "CAST(? AS DATETIME)"; case TEXT: case VARCHAR: case CHAR: if (format != null) { return "CAST(? AS CHAR " + format.toString() + ")"; } else { return "CAST(? AS CHAR)"; } case BLOB: return "CAST(? AS BLOB)"; default: log.error("getConvertPhrase: unknown type " + destType); return "?"; } } DBDatabaseDriverMySQL(); }
DBDatabaseDriverMySQL extends DBDatabaseDriver { @Override public String getConvertPhrase(DataType destType, DataType srcType, Object format) { switch(destType) { case BOOL: return "CAST(? AS UNSIGNED)"; case INTEGER: return "CAST(? AS SIGNED)"; case DECIMAL: return "CAST(? AS DECIMAL)"; case FLOAT: return "CAST(? AS DECIMAL)"; case DATE: return "CAST(? AS DATE)"; case DATETIME: case TIMESTAMP: return "CAST(? AS DATETIME)"; case TEXT: case VARCHAR: case CHAR: if (format != null) { return "CAST(? AS CHAR " + format.toString() + ")"; } else { return "CAST(? AS CHAR)"; } case BLOB: return "CAST(? AS BLOB)"; default: log.error("getConvertPhrase: unknown type " + destType); return "?"; } } 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 public String getConvertPhrase(DataType destType, DataType srcType, Object format) { switch(destType) { case BOOL: return "CAST(? AS UNSIGNED)"; case INTEGER: return "CAST(? AS SIGNED)"; case DECIMAL: return "CAST(? AS DECIMAL)"; case FLOAT: return "CAST(? AS DECIMAL)"; case DATE: return "CAST(? AS DATE)"; case DATETIME: case TIMESTAMP: return "CAST(? AS DATETIME)"; case TEXT: case VARCHAR: case CHAR: if (format != null) { return "CAST(? AS CHAR " + format.toString() + ")"; } else { return "CAST(? AS CHAR)"; } case BLOB: return "CAST(? AS BLOB)"; default: log.error("getConvertPhrase: unknown type " + destType); return "?"; } } 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);  }