E
enders
Hi,
I have the following SQL :
Select AutoID, TS, Object, ActionType, ID, Property, OldValue,
NewValue From Changes.
When I use the commandbuilder (both OLEDB and SQL) I get the following
result back (for delete) :
(SQL)
"DELETE FROM Changes WHERE ( (AutoID = @p1) AND (TS = @p2) AND ((@p3
= 1 AND Object IS NULL) OR (Object = @p4)) AND ((@p5 = 1 AND
ActionType IS NULL) OR (ActionType = @p6)) AND ((@p7 = 1 AND ID IS
NULL) OR (ID = @p8)) AND ((@p9 = 1 AND Property IS NULL) OR (Property
= @p10)) AND ((@p11 = 1 AND OldValue IS NULL) OR (OldValue = @p12))
AND ((@p13 = 1 AND NewValue IS NULL) OR (NewValue = @p14)) )"
(OLEDB)
"DELETE FROM Changes WHERE ( (AutoID = ?) AND (TS = ?) AND ((? = 1
AND Object IS NULL) OR (Object = ?)) AND ((? = 1 AND ActionType IS
NULL) OR (ActionType = ?)) AND ((? = 1 AND ID IS NULL) OR (ID = ?))
AND ((? = 1 AND Property IS NULL) OR (Property = ?)) AND ((? = 1 AND
OldValue IS NULL) OR (OldValue = ?)) AND ((? = 1 AND NewValue IS NULL)
OR (NewValue = ?)) )"
The SQL I was expecting was :
(replace all ? = 1 by ? is NULL)
"DELETE FROM Changes WHERE ( (AutoID = ?) AND (TS = ?) AND ((? is
NULL AND Object IS NULL) OR (Object = ?)) AND ((? is NULL AND
ActionType IS NULL) OR (ActionType = ?)) AND ((? is NULL AND ID IS
NULL) OR (ID = ?)) AND ((? is NULL AND Property IS NULL) OR (Property
= ?)) AND ((? is NULL AND OldValue IS NULL) OR (OldValue = ?)) AND ((?
is NULL AND NewValue IS NULL) OR (NewValue = ?)) )"
Since ? = 1 will always fail during an update (delete or update) I get
an concurrency exception back. I will try to replace th ? = 1 by ? is
NULL and
see if that works. I am open for any other suggestions.
I am using VS 2003.NET with all .NET patches.
Table script
CREATE TABLE [Changes] (
[AutoID] [bigint] IDENTITY (1, 1) NOT NULL ,
[TS] [timestamp] NOT NULL ,
[Object] [nvarchar] (50) NOT NULL ,
[ActionType] [nvarchar] (50) NOT NULL ,
[ID] [nvarchar] (50) NOT NULL ,
[Property] [nvarchar] (50) NULL ,
[OldValue] [nvarchar] (50) NULL ,
[NewValue] [nvarchar] (50) NULL ,
CONSTRAINT [PK_Changes] PRIMARY KEY CLUSTERED
(
[AutoID],
[TS]
) ON [PRIMARY]
) ON [PRIMARY]
GO
I have the following SQL :
Select AutoID, TS, Object, ActionType, ID, Property, OldValue,
NewValue From Changes.
When I use the commandbuilder (both OLEDB and SQL) I get the following
result back (for delete) :
(SQL)
"DELETE FROM Changes WHERE ( (AutoID = @p1) AND (TS = @p2) AND ((@p3
= 1 AND Object IS NULL) OR (Object = @p4)) AND ((@p5 = 1 AND
ActionType IS NULL) OR (ActionType = @p6)) AND ((@p7 = 1 AND ID IS
NULL) OR (ID = @p8)) AND ((@p9 = 1 AND Property IS NULL) OR (Property
= @p10)) AND ((@p11 = 1 AND OldValue IS NULL) OR (OldValue = @p12))
AND ((@p13 = 1 AND NewValue IS NULL) OR (NewValue = @p14)) )"
(OLEDB)
"DELETE FROM Changes WHERE ( (AutoID = ?) AND (TS = ?) AND ((? = 1
AND Object IS NULL) OR (Object = ?)) AND ((? = 1 AND ActionType IS
NULL) OR (ActionType = ?)) AND ((? = 1 AND ID IS NULL) OR (ID = ?))
AND ((? = 1 AND Property IS NULL) OR (Property = ?)) AND ((? = 1 AND
OldValue IS NULL) OR (OldValue = ?)) AND ((? = 1 AND NewValue IS NULL)
OR (NewValue = ?)) )"
The SQL I was expecting was :
(replace all ? = 1 by ? is NULL)
"DELETE FROM Changes WHERE ( (AutoID = ?) AND (TS = ?) AND ((? is
NULL AND Object IS NULL) OR (Object = ?)) AND ((? is NULL AND
ActionType IS NULL) OR (ActionType = ?)) AND ((? is NULL AND ID IS
NULL) OR (ID = ?)) AND ((? is NULL AND Property IS NULL) OR (Property
= ?)) AND ((? is NULL AND OldValue IS NULL) OR (OldValue = ?)) AND ((?
is NULL AND NewValue IS NULL) OR (NewValue = ?)) )"
Since ? = 1 will always fail during an update (delete or update) I get
an concurrency exception back. I will try to replace th ? = 1 by ? is
NULL and
see if that works. I am open for any other suggestions.
I am using VS 2003.NET with all .NET patches.
Table script
CREATE TABLE [Changes] (
[AutoID] [bigint] IDENTITY (1, 1) NOT NULL ,
[TS] [timestamp] NOT NULL ,
[Object] [nvarchar] (50) NOT NULL ,
[ActionType] [nvarchar] (50) NOT NULL ,
[ID] [nvarchar] (50) NOT NULL ,
[Property] [nvarchar] (50) NULL ,
[OldValue] [nvarchar] (50) NULL ,
[NewValue] [nvarchar] (50) NULL ,
CONSTRAINT [PK_Changes] PRIMARY KEY CLUSTERED
(
[AutoID],
[TS]
) ON [PRIMARY]
) ON [PRIMARY]
GO