Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MyDB] Fixing bugs 8377 and 8485 #520

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public RecordTemplate getRecordTemplate(DbTable dbTable,
}
}

if (newRecord && column.isAutoIncrement()) {
continue;
}

GenericFieldTemplate ft = new GenericFieldTemplate(FIELD_PREFIX
+ columnName, fieldType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Properties;
import java.util.Vector;

import com.silverpeas.util.StringUtil;
import org.silverpeas.mydb.control.DriverManager;

import com.silverpeas.form.DataRecord;
Expand Down Expand Up @@ -548,11 +549,15 @@ public DbTable getDbTable() throws MyDBException {

//In jdbc Oracle, override mapping between DATE and java.sql.Date instead of DATE and java.sql.Timestamp
int dataType = rs.getInt(DbColumn.DATA_TYPE);
if (DateField.TYPE.equalsIgnoreCase(rs.getString("TYPE_NAME"))) {
int dataSize = rs.getInt(DbColumn.COLUMN_SIZE);
String typeName = rs.getString("TYPE_NAME");
if (DateField.TYPE.equalsIgnoreCase(typeName)) {
dataType = java.sql.Types.DATE;
} else if ("bool".equalsIgnoreCase(typeName)) {
dataType = Types.BOOLEAN;
dataSize = 10;
}

int dataSize = rs.getInt(DbColumn.COLUMN_SIZE);
int nullable = rs.getInt(DbColumn.NULLABLE);
boolean isNull = (nullable == 1);
String defaultValue = rs.getString(DbColumn.COLUMN_DEF);
Expand Down Expand Up @@ -677,6 +682,8 @@ public DbTable getDbTable() throws MyDBException {
"myDB.MSG_CANNOT_GET_TABLE_LINE", "TableName="
+ tableName, e);
}
} else if (dbTable.getColumn(i).getDataType() == Types.BOOLEAN) {
value = value.equals("f") ? "false" : "true";
}
dbLine.addData(columnsNames[i], value);
i++;
Expand Down Expand Up @@ -855,7 +862,7 @@ public String createDbLine() {
int psIndex = 1;
for (int i = 0, n = columnsNames.length; i < n; i++) {
columnName = columnsNames[i];
value = formParameters[i][1];
value = getValueFromForm(columnName);
dbColumn = dbTable.getColumn(columnName);
dataType = dbColumn.getDataType();
setValueByType(value, dataType, psIndex);
Expand All @@ -873,6 +880,15 @@ public String createDbLine() {
return null;
}

private String getValueFromForm(String columnName) {
for (int i=0; i<formParameters.length; i++) {
if (columnName.equalsIgnoreCase(formParameters[i][0])) {
return formParameters[i][1];
}
}
return "";
}

/**
* @return An error message caused by the line update attempt. The line is updated if no error
* occurred.
Expand Down Expand Up @@ -908,7 +924,7 @@ public String updateDbData() {
int psIndex = 1;
for (int i = 0, n = columnsNames.length; i < n; i++) {
columnName = columnsNames[i];
value = formParameters[i][1];
value = getValueFromForm(columnName);
dbColumn = dbTable.getColumn(columnName);
dataType = dbColumn.getDataType();
setValueByType(value, dataType, psIndex);
Expand Down Expand Up @@ -1328,7 +1344,7 @@ private void setValueByType(String value, int dataType, int index)
break;

case Types.BOOLEAN:
prepStmt.setBoolean(index, Boolean.getBoolean(value));
prepStmt.setBoolean(index, StringUtil.getBooleanValue(value));
break;

case Types.TIME:
Expand Down