Skip to content

Commit

Permalink
0001101: sqlite create tables doesn't work because a transaction is i…
Browse files Browse the repository at this point in the history
…n process and the database is locked

0001100: sqlite create tables quotes create_timestamp default values
  • Loading branch information
chenson42 committed Mar 8, 2013
1 parent ec381ef commit 8795694
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 79 deletions.
Expand Up @@ -674,7 +674,6 @@ public List<String> findOfflineNodeIds(long minutesOffline) {
}
}
}
log.info("Returning offline list");
return offlineNodeList;
}

Expand Down
Expand Up @@ -1853,19 +1853,32 @@ protected void writeColumnDefaultValue(Table table, Column column, StringBuilder
* Prints the default value of the column.
*/
protected void printDefaultValue(Object defaultValue, int typeCode, StringBuilder ddl) {
if (defaultValue != null) {
boolean shouldUseQuotes = !TypeMap.isNumericType(typeCode);

if (shouldUseQuotes) {
// characters are only escaped when within a string literal
ddl.append(databaseInfo.getValueQuoteToken());
ddl.append(escapeStringValue(defaultValue.toString()));
ddl.append(databaseInfo.getValueQuoteToken());
} else {
ddl.append(defaultValue.toString());
}
boolean isNull = defaultValue == null;
String defaultValueStr = mapDefaultValue(defaultValue, typeCode);
boolean shouldUseQuotes = !isNull && !TypeMap.isNumericType(typeCode) &&
!(TypeMap.isDateTimeType(typeCode)
&& (defaultValueStr.toUpperCase().startsWith("TO_DATE(")
|| defaultValueStr.toUpperCase().startsWith("SYSDATE")
|| defaultValueStr.toUpperCase().startsWith("SYSTIMESTAMP")
|| defaultValueStr.toUpperCase().startsWith("CURRENT_TIMESTAMP")
|| defaultValueStr.toUpperCase().startsWith("CURRENT_DATE")));

if (shouldUseQuotes) {
// characters are only escaped when within a string literal
ddl.append(databaseInfo.getValueQuoteToken());
ddl.append(escapeStringValue(defaultValueStr));
ddl.append(databaseInfo.getValueQuoteToken());
} else {
ddl.append(defaultValueStr);
}
}

protected String mapDefaultValue(Object defaultValue, int typeCode) {
if (defaultValue == null) {
defaultValue = "NULL";
}
return defaultValue.toString();
}

/**
* Prints that the column is an auto increment column.
Expand Down
Expand Up @@ -42,7 +42,6 @@
import org.jumpmind.db.model.IIndex;
import org.jumpmind.db.model.ModelException;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.model.TypeMap;
import org.jumpmind.db.platform.AbstractDdlBuilder;

/*
Expand Down Expand Up @@ -173,26 +172,6 @@ protected void writeColumnDefaultValueStmt(Table table, Column column, StringBui
}
}

@Override
protected void printDefaultValue(Object defaultValue, int typeCode, StringBuilder ddl) {
if (defaultValue != null) {
String defaultValueStr = defaultValue.toString();
boolean shouldUseQuotes = !TypeMap.isNumericType(typeCode)
&& !defaultValueStr.startsWith("TO_DATE(")
&& !defaultValue.equals("CURRENT_TIMESTAMP")
&& !defaultValue.equals("CURRENT_TIME") && !defaultValue.equals("CURRENT_DATE");

if (shouldUseQuotes) {
// characters are only escaped when within a string literal
ddl.append(databaseInfo.getValueQuoteToken());
ddl.append(escapeStringValue(defaultValueStr));
ddl.append(databaseInfo.getValueQuoteToken());
} else {
ddl.append(defaultValueStr);
}
}
}

@Override
public void writeExternalIndexDropStmt(Table table, IIndex index, StringBuilder ddl) {
ddl.append("DROP INDEX IF EXISTS ");
Expand Down
Expand Up @@ -36,7 +36,6 @@
import org.jumpmind.db.model.Database;
import org.jumpmind.db.model.ForeignKey;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.model.TypeMap;
import org.jumpmind.db.platform.AbstractDdlBuilder;

/*
Expand Down Expand Up @@ -279,26 +278,6 @@ protected void processChange(Database currentModel, Database desiredModel,
change.apply(currentModel, delimitedIdentifierModeOn);
}

@Override
protected void printDefaultValue(Object defaultValue, int typeCode, StringBuilder ddl) {
if (defaultValue != null) {
String defaultValueStr = defaultValue.toString();
boolean shouldUseQuotes = !TypeMap.isNumericType(typeCode)
&& !defaultValueStr.equalsIgnoreCase("CURRENT_TIMESTAMP")
&& !defaultValueStr.equalsIgnoreCase("CURRENT_DATE");


if (shouldUseQuotes) {
// characters are only escaped when within a string literal
ddl.append(databaseInfo.getValueQuoteToken());
ddl.append(escapeStringValue(defaultValueStr));
ddl.append(databaseInfo.getValueQuoteToken());
} else {
ddl.append(defaultValueStr);
}
}
}

/*
* Processes the change of the primary key of a table.
*/
Expand Down
Expand Up @@ -39,7 +39,6 @@
import org.jumpmind.db.model.Database;
import org.jumpmind.db.model.IIndex;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.model.TypeMap;
import org.jumpmind.db.platform.AbstractDdlBuilder;
import org.jumpmind.db.platform.PlatformUtils;

Expand Down Expand Up @@ -244,30 +243,6 @@ public void writeExternalIndexDropStmt(Table table, IIndex index, StringBuilder
printEndOfStatement(ddl);
}

@Override
protected void printDefaultValue(Object defaultValue, int typeCode, StringBuilder ddl) {
boolean isNull = defaultValue == null;
if (defaultValue == null) {
defaultValue = "NULL";
}
String defaultValueStr = defaultValue.toString();
boolean shouldUseQuotes = !isNull && !TypeMap.isNumericType(typeCode)
&& !defaultValueStr.startsWith("TO_DATE(")
&& !defaultValueStr.equalsIgnoreCase("SYSDATE")
&& !defaultValueStr.equalsIgnoreCase("SYSTIMESTAMP")
&& !defaultValueStr.equalsIgnoreCase("CURRENT_TIMESTAMP")
&& !defaultValueStr.equalsIgnoreCase("CURRENT_DATE");

if (shouldUseQuotes) {
// characters are only escaped when within a string literal
ddl.append(databaseInfo.getValueQuoteToken());
ddl.append(escapeStringValue(defaultValueStr));
ddl.append(databaseInfo.getValueQuoteToken());
} else {
ddl.append(defaultValueStr);
}
}

@Override
protected String getNativeDefaultValue(Column column) {
if ((column.getMappedTypeCode() == Types.BIT)
Expand Down
Expand Up @@ -6,6 +6,7 @@
import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.IIndex;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.model.TypeMap;
import org.jumpmind.db.platform.AbstractDdlBuilder;

public class SqliteDdlBuilder extends AbstractDdlBuilder {
Expand Down Expand Up @@ -97,4 +98,32 @@ protected void dropTable(Table table, StringBuilder ddl, boolean temporary, bool
printIdentifier(getTableName(table.getName()), ddl);
printEndOfStatement(ddl);
}

@Override
protected String mapDefaultValue(Object defaultValue, int typeCode) {
if (TypeMap.isDateTimeType(typeCode) && defaultValue != null) {
String defaultValueStr = defaultValue.toString();
if (defaultValueStr.toUpperCase().startsWith("SYSDATE")
|| defaultValueStr.toUpperCase().startsWith("CURRENT_DATE")) {
return "CURRENT_DATE";
} else if (defaultValueStr.toUpperCase().startsWith("SYSTIMESTAMP")
|| defaultValueStr.toUpperCase().startsWith("CURRENT_TIMESTAMP")) {
return "CURRENT_TIMESTAMP";
} else if (defaultValueStr.toUpperCase().startsWith("SYSTIME")
|| defaultValueStr.toUpperCase().startsWith("CURRENT_TIME")) {
return "CURRENT_TIME";
} else if(defaultValueStr.contains("('")) {
int beginIndex = defaultValueStr.indexOf("('");
int lastIndex = defaultValueStr.lastIndexOf(")");
if (lastIndex > beginIndex) {
return defaultValueStr.substring(beginIndex, lastIndex);
} else {
return defaultValueStr.substring(beginIndex);
}
}
}
return super.mapDefaultValue(defaultValue, typeCode);
}


}
Expand Up @@ -851,6 +851,8 @@ protected boolean script(CsvData data) {
protected boolean create(CsvData data) {
String xml = null;
try {
transaction.commit();

statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS);
xml = data.getParsedData(CsvData.ROW_DATA)[0];
log.info("About to create table using the following definition: {}", xml);
Expand Down

0 comments on commit 8795694

Please sign in to comment.