diff --git a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/SqlSerialization.java b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/SqlSerialization.java index bc9389ebc1..6f95365b3e 100644 --- a/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/SqlSerialization.java +++ b/timbuctoo-instancev4/src/main/java/nl/knaw/huygens/timbuctoo/v5/serializable/serializations/SqlSerialization.java @@ -15,20 +15,22 @@ public class SqlSerialization extends FlatTableSerialization { private List columns; protected final PrintWriter writer; protected boolean firstLine = true; + private int id = 0; public SqlSerialization(OutputStream outputStream) throws IOException { writer = new PrintWriter(outputStream); } protected void initialize(List columnHeaders) throws IOException { - this.columnHeaders = ""; + this.columnHeaders = "id"; columns = new ArrayList(); for (String columnHeader : columnHeaders) { + columnHeader = columnHeader.replaceAll("\\.", "_"); columns.add(columnHeader); this.columnHeaders += ", " + columnHeader; this.columnHeaders += ", " + columnHeader + "_type"; } - this.columnHeaders = this.columnHeaders.substring(2); + // this.columnHeaders = this.columnHeaders.substring(2); } protected void setTableName(String tableName) { @@ -42,6 +44,7 @@ protected void writeCreateTable() { } writer.println("DROP TABLE " + tableName + ";"); String createTableString = "CREATE TABLE " + tableName + " (\n"; + createTableString += "id integer UNIQUE NOT NULL,\n"; for (String column: columns) { createTableString += column + " text,\n"; createTableString += column + "_type text,\n"; @@ -56,7 +59,8 @@ protected void writeRow(List values) throws IOException { writeCreateTable(); firstLine = false; } - String columnValues = ""; + id++; + String columnValues = id + ""; for (Value value : values) { if (value == null) { columnValues += ", DEFAULT"; @@ -67,7 +71,7 @@ protected void writeRow(List values) throws IOException { } } writer.println("INSERT INTO " + this.tableName + " (" + columnHeaders + - ") VALUES (" + columnValues.substring(2) + ");"); + ") VALUES (" + columnValues + ");"); } @Override