Using Select and Where parameter = any\dontcare in MySQL with C# -
in mysql based c# code have implement , search filter on database, have written select * table (list of parameter conditions); problem want default "select all" particular parameter. select * table type=(any\don't care);
i want different rows types shown without filtering. same case happen if had omitted clause; cant omit clause in mine cause structure of query broken . . whole or missing "and" cause im using string builder concatenate query. ill post code below incase has better way of doing this;
str.append("select * "); str.append(" recording "); str.append(" "); switch (type) { case "audio": str.append(" , type = " + 1 + " "); break; case "video": str.append(" , type = " + 2 + " "); break; case "voip": str.append(" , type = " + 3 + " "); break; default: <**suggestion here**> break; } if (!(channelname == "")) { str.append("and channelname = '" + channelname + "' "); } if(!(channel == "all")) { str.append(" , channelid = '" + channel + "' "); } if (archive == "true") { str.append(" , archive = " + true + " "); } else if (archive == "false") { str.append(" , archive = " + true + " "); } str.append(" , starttime > '" + + "' , "); str.append("starttime < '" + + "' "); if (duration > 0) { str.append(" , (select timestampdiff(second,endtime,starttime))" + durationtype + " " + duration); } str.append(" ;"); sqltext = str.tostring();
here, if u can suggest statement in switch statement can display types has logic equivalent "type=anything" trick. , kno "type in (1,2,3, etc)" . . these fields user creatable many come later wanted general solution , kno can use select statement inside "type in (select bla bla)" . . wanted kno if mysql supports generic value parameters.
change this
str.append(" 1=1 ");
now rest of query can remain same. query become thing this
select * yourtable 1=1 , condition1 , condition2 ....
Comments
Post a Comment