fix a bug introduced in postgres support that breaks inserts for mysql

This commit is contained in:
fjy 2013-07-23 13:21:14 -07:00
parent f09a43a8d9
commit fc65648809
1 changed files with 16 additions and 7 deletions

View File

@ -60,13 +60,22 @@ public class DbSegmentPublisher implements SegmentPublisher
@Override @Override
public Void withHandle(Handle handle) throws Exception public Void withHandle(Handle handle) throws Exception
{ {
handle.createStatement( String statement;
String.format( if (!handle.getConnection().getMetaData().getDatabaseProductName().contains("PostgreSQL")) {
"INSERT INTO %s (id, dataSource, created_date, start, \"end\", partitioned, version, used, payload) " statement = String.format(
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)", "INSERT INTO %s (id, dataSource, created_date, start, end, partitioned, version, used, payload) "
config.getSegmentTable() + "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
) config.getSegmentTable()
) );
} else {
statement = String.format(
"INSERT INTO %s (id, dataSource, created_date, start, \"end\", partitioned, version, used, payload) "
+ "VALUES (:id, :dataSource, :created_date, :start, :end, :partitioned, :version, :used, :payload)",
config.getSegmentTable()
);
}
handle.createStatement(statement)
.bind("id", segment.getIdentifier()) .bind("id", segment.getIdentifier())
.bind("dataSource", segment.getDataSource()) .bind("dataSource", segment.getDataSource())
.bind("created_date", new DateTime().toString()) .bind("created_date", new DateTime().toString())