[pgsqlclient-checkins] pgsqlclient_10/PostgreSql.Data.PgSqlClient/source PgCommandBuilder.cs,1.6,1.7
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2003-09-28 18:57:11
|
Update of /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source In directory sc8-pr-cvs1:/tmp/cvs-serv4988 Modified Files: PgCommandBuilder.cs Log Message: Added changes for use the same format in the CommandText of the generated insert, delete, update commands that is used by the SqlClient data provider. Index: PgCommandBuilder.cs =================================================================== RCS file: /cvsroot/pgsqlclient/pgsqlclient_10/PostgreSql.Data.PgSqlClient/source/PgCommandBuilder.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PgCommandBuilder.cs 31 Aug 2003 12:59:36 -0000 1.6 --- PgCommandBuilder.cs 28 Sep 2003 18:56:54 -0000 1.7 *************** *** 38,42 **** private PgCommand updateCommand; private PgCommand deleteCommand; ! private string whereClausule; private string setClausule; private DataTable schemaTable; --- 38,44 ---- private PgCommand updateCommand; private PgCommand deleteCommand; ! private string separator; ! private string whereClausule1; ! private string whereClausule2; private string setClausule; private DataTable schemaTable; *************** *** 123,128 **** sqlUpdate = "UPDATE {0} SET {1} WHERE ( {2} )"; sqlDelete = "DELETE FROM {0} WHERE ( {1} )"; ! whereClausule = "(({0} IS NULL) OR ({0} = {1}))"; ! setClausule = "{0} = {1}"; quotePrefix = String.Empty; quoteSuffix = String.Empty; --- 125,132 ---- sqlUpdate = "UPDATE {0} SET {1} WHERE ( {2} )"; sqlDelete = "DELETE FROM {0} WHERE ( {1} )"; ! whereClausule1 = "(({0} IS NULL AND ${1} IS NULL) OR ({0} = ${2}))"; ! whereClausule2 = "({0} = ${1})"; ! setClausule = "{0} = ${1}"; ! separator = ", "; quotePrefix = String.Empty; quoteSuffix = String.Empty; *************** *** 349,357 **** if (fields.Length > 0) { ! fields.Append(", "); } if (values.Length > 0) { ! values.Append(", "); } --- 353,361 ---- if (fields.Length > 0) { ! fields.Append(separator); } if (values.Length > 0) { ! values.Append(separator); } *************** *** 364,385 **** PgParameter parameter = createParameter(schemaRow, i, false); - if (tableMapping != null) - { - if (tableMapping.ColumnMappings.Count > 0) - { - dsColumnName = tableMapping.ColumnMappings[parameter.SourceColumn].DataSetColumn; - } - else - { - dsColumnName = parameter.SourceColumn; - } - } - else - { - dsColumnName = parameter.SourceColumn; - } - if (row != null) { parameter.Value = row[dsColumnName]; } --- 368,374 ---- PgParameter parameter = createParameter(schemaRow, i, false); if (row != null) { + dsColumnName = getColumnName(tableMapping, schemaRow["BaseColumnName"].ToString()); parameter.Value = row[dsColumnName]; } *************** *** 424,455 **** if (sets.Length > 0) { ! sets.Append(", "); } // Build Field name and append it to the string sets.AppendFormat(setClausule, ! getQuotedIdentifier(schemaRow["BaseColumnName"]), ! "@param_" + i.ToString()); PgParameter parameter = createParameter(schemaRow, i, false); - if (tableMapping != null) - { - if (tableMapping.ColumnMappings.Count > 0) - { - dsColumnName = tableMapping.ColumnMappings[parameter.SourceColumn].DataSetColumn; - } - else - { - dsColumnName = parameter.SourceColumn; - } - } - else - { - dsColumnName = parameter.SourceColumn; - } - if (row != null) { parameter.Value = row[dsColumnName]; } --- 413,428 ---- if (sets.Length > 0) { ! sets.Append(separator); } // Build Field name and append it to the string sets.AppendFormat(setClausule, ! getQuotedIdentifier(schemaRow["BaseColumnName"]), i); PgParameter parameter = createParameter(schemaRow, i, false); if (row != null) { + dsColumnName = this.getColumnName(tableMapping, schemaRow["BaseColumnName"].ToString()); parameter.Value = row[dsColumnName]; } *************** *** 458,462 **** updateCommand.Parameters.Add(parameter); ! } } --- 431,435 ---- updateCommand.Parameters.Add(parameter); ! } } *************** *** 471,505 **** } ! where.AppendFormat(whereClausule, ! getQuotedIdentifier(schemaRow["BaseColumnName"]), ! "@param_" + i.ToString()); ! ! PgParameter parameter = createParameter(schemaRow, i, true); ! if (tableMapping != null) { ! if (tableMapping.ColumnMappings.Count > 0) ! { ! dsColumnName = tableMapping.ColumnMappings[parameter.SourceColumn].DataSetColumn; ! } ! else { ! dsColumnName = parameter.SourceColumn; } } else { ! dsColumnName = parameter.SourceColumn; ! } ! if (row != null) ! { ! parameter.Value = row[dsColumnName, DataRowVersion.Original]; ! } ! i++; ! updateCommand.Parameters.Add(parameter); ! } } --- 444,488 ---- } ! dsColumnName = this.getColumnName(tableMapping, schemaRow["BaseColumnName"].ToString()); ! string quotedId = getQuotedIdentifier(schemaRow["BaseColumnName"]); ! if ((bool)schemaRow["IsKey"]) { ! PgParameter parameter = createParameter(schemaRow, i, true); ! where.AppendFormat(whereClausule2, quotedId, i); ! ! if (row != null) { ! parameter.Value = row[dsColumnName, DataRowVersion.Original]; } + + updateCommand.Parameters.Add(parameter); } else { ! // Create parameters for this field ! int paramIndex1 = i; ! PgParameter parameter1 = createParameter(schemaRow, paramIndex1, true); ! int paramIndex2 = ++i; ! PgParameter parameter2 = createParameter(schemaRow, paramIndex2, true); ! // Add where clausule for this field ! where.AppendFormat(whereClausule1, ! quotedId, paramIndex1, paramIndex2); ! // Set parameter values ! if (row != null) ! { ! parameter1.Value = row[dsColumnName, DataRowVersion.Original]; ! parameter2.Value = row[dsColumnName, DataRowVersion.Original]; ! } ! // Add parameters to command parameter collectionb ! updateCommand.Parameters.Add(parameter1); ! updateCommand.Parameters.Add(parameter2); ! } ! ! i++; ! } } *************** *** 540,573 **** } ! where.AppendFormat(whereClausule, ! getQuotedIdentifier(schemaRow["BaseColumnName"]), ! "@param_" + i.ToString()); ! ! PgParameter parameter = createParameter(schemaRow, i, true); ! if (tableMapping != null) { ! if (tableMapping.ColumnMappings.Count > 0) ! { ! dsColumnName = tableMapping.ColumnMappings[parameter.SourceColumn].DataSetColumn; ! } ! else { ! dsColumnName = parameter.SourceColumn; } } else { ! dsColumnName = parameter.SourceColumn; ! } ! ! if (row != null) ! { ! parameter.Value = row[dsColumnName, DataRowVersion.Original]; } i++; - - deleteCommand.Parameters.Add(parameter); } } --- 523,566 ---- } ! dsColumnName = this.getColumnName(tableMapping, schemaRow["BaseColumnName"].ToString()); ! string quotedId = getQuotedIdentifier(schemaRow["BaseColumnName"]); ! if ((bool)schemaRow["IsKey"]) { ! PgParameter parameter = createParameter(schemaRow, i, true); ! where.AppendFormat(whereClausule2, quotedId, i); ! ! if (row != null) { ! parameter.Value = row[dsColumnName, DataRowVersion.Original]; } + + deleteCommand.Parameters.Add(parameter); } else { ! // Create parameters for this field ! int paramIndex1 = i; ! PgParameter parameter1 = createParameter(schemaRow, paramIndex1, true); ! int paramIndex2 = ++i; ! PgParameter parameter2 = createParameter(schemaRow, paramIndex2, true); ! ! // Add where clausule for this field ! where.AppendFormat(whereClausule1, ! quotedId, paramIndex1, paramIndex2); ! ! // Set parameter values ! if (row != null) ! { ! parameter1.Value = row[dsColumnName, DataRowVersion.Original]; ! parameter2.Value = row[dsColumnName, DataRowVersion.Original]; ! } ! ! // Add parameters to command parameter collectionb ! deleteCommand.Parameters.Add(parameter1); ! deleteCommand.Parameters.Add(parameter2); } i++; } } *************** *** 581,584 **** --- 574,600 ---- return deleteCommand; + } + + private string getColumnName(DataTableMapping tableMapping, string sourceColumn) + { + string dsColumnName; + + if (tableMapping != null) + { + if (tableMapping.ColumnMappings.Count > 0) + { + dsColumnName = tableMapping.ColumnMappings[sourceColumn].DataSetColumn; + } + else + { + dsColumnName = sourceColumn; + } + } + else + { + dsColumnName = sourceColumn; + } + + return dsColumnName; } |