return _deleteCommand;
}
- private DbCommand CreateInsertCommand (bool option)
+ private DbCommand CreateInsertCommand (bool option, DataRow row)
{
if (QuotedTableName == String.Empty)
return null;
parameter = CreateParameter (_insertCommand, parmIndex++, schemaRow);
parameter.SourceVersion = DataRowVersion.Current;
ApplyParameterInfo (parameter, schemaRow, StatementType.Insert, false);
- //parameter.IsNullable = (bool) schemaRow ["AllowDBNull"];
columns.Append (GetQuotedString (parameter.SourceColumn));
- values.Append (parameter.ParameterName);
+
+ // Workaround for columns that may have a default/bound value and for now,
+ // the framework, don't provide a mechanism to read these values yet
+ // AllowDBNull and DataRow is used to workaround #385028 by using DEFAULT
+ string colName = schemaRow ["ColumnName"] as string;
+ bool allowDBNull = !schemaRow.IsNull ("AllowDBNull") & (bool) schemaRow ["AllowDBNull"];
+ if (!allowDBNull && row != null &&
+ (row [colName] == DBNull.Value || row [colName] == null)) {
+ values.Append ("DEFAULT");
+ } else {
+ values.Append (parameter.ParameterName);
+ }
}
sql = String.Format ("{0} ({1}) VALUES ({2})", command, columns.ToString (), values.ToString ());
else
parameter = CreateParameter (_updateCommand, parmIndex++, schemaRow);
parameter.SourceVersion = DataRowVersion.Original;
- parameter.IsNullable = allowNull;
+ //parameter.IsNullable = allowNull;
ApplyParameterInfo (parameter, schemaRow, StatementType.Update, true);
whereClause.Append (String.Format (clause2, GetQuotedString (parameter.SourceColumn), parameter.ParameterName));
[Browsable (false)]
public DbDataAdapter DataAdapter {
get { return _dbDataAdapter; }
- set { if (value != null) _dbDataAdapter = value; }
+ set { if (value != null)
+ SetRowUpdatingHandler (value);
+ _dbDataAdapter = value;
+ }
}
[DefaultValue ("")]
public DbCommand GetInsertCommand ()
{
- return GetInsertCommand (false);
+ return GetInsertCommand (false, null);
}
public DbCommand GetInsertCommand (bool option)
+ {
+ return GetInsertCommand (option, null);
+ }
+
+ internal DbCommand GetInsertCommand (bool option, DataRow row)
{
BuildCache (true);
if (_insertCommand == null || option)
- return CreateInsertCommand (option);
+ return CreateInsertCommand (option, row);
return _insertCommand;
}
try {
switch (args.StatementType) {
case StatementType.Insert:
- args.Command = GetInsertCommand ();
+ args.Command = GetInsertCommand (false, args.Row);
break;
case StatementType.Update:
args.Command = GetUpdateCommand ();