Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ BuildWhereClause()

int System.Data.Common.DbCommandBuilder.BuildWhereClause ( DataTableMapping mappings,
DataRow dataRow,
StringBuilder builder,
DbCommand command,
int parameterCount,
bool isUpdate )
inlineprivate

Definition at line 815 of file DbCommandBuilder.cs.

816 {
817 string value = string.Empty;
818 int num = 0;
819 builder.Append(" WHERE ");
820 builder.Append('(');
821 DbSchemaRow[] dbSchemaRows = _dbSchemaRows;
822 for (int i = 0; i < dbSchemaRows.Length; i++)
823 {
824 DbSchemaRow dbSchemaRow = dbSchemaRows[i];
825 if (dbSchemaRow != null && dbSchemaRow.BaseColumnName.Length != 0 && IncludeInWhereClause(dbSchemaRow, isUpdate))
826 {
827 builder.Append(value);
828 value = " AND ";
829 object value2 = null;
830 string text = _sourceColumnNames[i];
831 string value3 = QuotedColumn(dbSchemaRow.BaseColumnName);
832 if (mappings != null && dataRow != null)
833 {
834 value2 = GetColumnValue(dataRow, text, mappings, DataRowVersion.Original);
835 }
836 if (!dbSchemaRow.AllowDBNull)
837 {
838 builder.Append('(');
839 builder.Append(value3);
840 builder.Append(" = ");
841 builder.Append(CreateParameterForValue(command, GetOriginalParameterName(i), text, DataRowVersion.Original, parameterCount, value2, dbSchemaRow, isUpdate ? StatementType.Update : StatementType.Delete, whereClause: true));
842 parameterCount++;
843 builder.Append(')');
844 }
845 else
846 {
847 builder.Append('(');
848 builder.Append('(');
849 builder.Append(CreateParameterForNullTest(command, GetNullParameterName(i), text, DataRowVersion.Original, parameterCount, value2, dbSchemaRow, isUpdate ? StatementType.Update : StatementType.Delete, whereClause: true));
850 parameterCount++;
851 builder.Append(" = 1");
852 builder.Append(" AND ");
853 builder.Append(value3);
854 builder.Append(" IS NULL");
855 builder.Append(')');
856 builder.Append(" OR ");
857 builder.Append('(');
858 builder.Append(value3);
859 builder.Append(" = ");
860 builder.Append(CreateParameterForValue(command, GetOriginalParameterName(i), text, DataRowVersion.Original, parameterCount, value2, dbSchemaRow, isUpdate ? StatementType.Update : StatementType.Delete, whereClause: true));
861 parameterCount++;
862 builder.Append(')');
863 builder.Append(')');
864 }
865 if (IncrementWhereCount(dbSchemaRow))
866 {
867 num++;
868 }
869 }
870 }
871 builder.Append(')');
872 if (num == 0)
873 {
874 if (isUpdate)
875 {
876 if (ConflictOption.CompareRowVersion == ConflictOption)
877 {
878 throw ADP.DynamicSQLNoKeyInfoRowVersionUpdate();
879 }
880 throw ADP.DynamicSQLNoKeyInfoUpdate();
881 }
882 if (ConflictOption.CompareRowVersion == ConflictOption)
883 {
884 throw ADP.DynamicSQLNoKeyInfoRowVersionDelete();
885 }
886 throw ADP.DynamicSQLNoKeyInfoDelete();
887 }
888 return parameterCount;
889 }
object GetColumnValue(DataRow row, string columnName, DataTableMapping mappings, DataRowVersion version)
string CreateParameterForValue(DbCommand command, string parameterName, string sourceColumn, DataRowVersion version, int parameterCount, object value, DbSchemaRow row, StatementType statementType, bool whereClause)
string CreateParameterForNullTest(DbCommand command, string parameterName, string sourceColumn, DataRowVersion version, int parameterCount, object value, DbSchemaRow row, StatementType statementType, bool whereClause)
bool IncludeInWhereClause(DbSchemaRow row, bool isUpdate)
StringBuilder Append(char value, int repeatCount)

References System.Data.Common.DbCommandBuilder._dbSchemaRows, System.Data.Common.DbCommandBuilder._sourceColumnNames, System.Data.Common.DbSchemaRow.AllowDBNull, System.Text.StringBuilder.Append(), System.Data.Common.DbSchemaRow.BaseColumnName, System.Data.Common.DbCommandBuilder.CreateParameterForNullTest(), System.Data.Common.DbCommandBuilder.CreateParameterForValue(), System.Data.Common.ADP.DynamicSQLNoKeyInfoDelete(), System.Data.Common.ADP.DynamicSQLNoKeyInfoRowVersionDelete(), System.Data.Common.ADP.DynamicSQLNoKeyInfoRowVersionUpdate(), System.Data.Common.ADP.DynamicSQLNoKeyInfoUpdate(), System.Data.Common.DbCommandBuilder.GetColumnValue(), System.Data.Common.DbCommandBuilder.GetNullParameterName(), System.Data.Common.DbCommandBuilder.GetOriginalParameterName(), System.Text.RegularExpressions.i, System.Data.Common.DbCommandBuilder.IncludeInWhereClause(), System.Data.Common.DbCommandBuilder.IncrementWhereCount(), System.Data.Common.DbCommandBuilder.QuotedColumn(), System.text, and System.value.

Referenced by System.Data.Common.DbCommandBuilder.BuildDeleteCommand(), and System.Data.Common.DbCommandBuilder.BuildUpdateCommand().