tags:

views:

49

answers:

2

I am getting a string from HttpContext.Current.Request["key"] which i then do split(',') if its not null.

Now i would like to write a sql statement deleting any msgId (long/Int64) that matches the keys, how should i write it? The only way i unserstand is to convert the string[] to long[] then loop a SQL statement. Is there a better way?

PS: Using sqlite ATM but will be switching to another SQL engine. (i havent chosen the server yet so i dont know which)

+1  A: 
DELETE FROM table WHERE id IN (1,2,3,keys)

Would that do it?

Ben Hughes
Yes it would :). Do you happen to know how to write that in a style similar to DELETE FROM table WHERE id IN @someType command.Parameters.Add("@someType", DbType.????).Value = LongArray;
acidzombie24
unfortunately no, I'm a rails hack, so we don't do the whole "database safety" or "data integrity" thing. hopefully someone else can help
Ben Hughes
Thats fine, i am looking at the DbType.Stuff and it appears theres no option (maybe binary but thats a long shot or a bad hack).
acidzombie24
A: 

I would suggest you use Ben's solution above, but with a little change. I have observed that when you use many items in sql (it was with sql 2000, don't know if its still an issue with sql 2005) in statement the query tends to go slow. Try multiple delete statements in number of items in the 'in' statement exceeds 100.

Ex: DELETE FROM table WHERE id IN (1,2,3 ... n)
    DELETE FROM table WHERE id IN (1,2,3 ... n)

If you are not expecting many items then there is no need to do this.

Shafqat Ahmed