Thanks, this explanation makes it easier to understand what you are tryingto 
achieve.

I do not see any binding in your code, so let us assume you are not binding anything and just executing the query, this rework of your code should be the easiest:

bool delete_emp(int key, string name = "")
{
        string query = "DELETE FROM `emp` WHERE (`key`="+intToStr(key)+")";

        if(name.length() > 0)
        {
                //needs to delete specific row. by unique key.
                query = query + " AND (`name`="+quotedStr(name)+")";
        }

        query = query + ";";  // Just add ending SQL delimeter - (pedanticness)

        return sqlite3_execute(fDBHandle, query);
}


The above assumes your version of whatever language this is (looks like a C or JAVA / FLEX version of sorts) has a function that makes integers into strings (replace intToStr() with the correct one) and a function which can encode and double quotations for SQL (replace quotedStr() with whatever does that for you) and use whatever you normally use to execute the queries if it isn't sqlite3_execute.

Hoping this all makes sense.

Pseudo-code for quotedStr() // just incase you dont have such a thing yet - It needs to double up on quotes found and enclose it all in a set of quotes.

string quotedStr(sOriginStr) {
    for ( n = sOriginStr.length()-1;  n > 0;  n-- ) {
        if ( sOriginStr[n] = "'" )  insert ( sOriginStr(n, "'");
    }
    return "'" + sOriginStr + "'";
}

where "'" is a single quote enclosed in double-quotes (incase that was not 
obvious)




On 2013/11/18 14:24, d b wrote:
Hi RSmith,

   Thanks. Still, I could not delete with single query.


create table if not exists emp(key integer not null, name text not null ,
personaldata text not null, unique(key, name));
insert into emp (key, name, personaldata) values(1, 'a', 'z');
insert into emp (key, name, personaldata) values(1, 'b', 'zz');
insert into emp (key, name, personaldata) values(2, 'c', 'y');
insert into emp (key, name, personaldata) values(3, 'd', 'yy');
insert into emp (key, name, personaldata) values(1, 'e', 'yyy');

bool delete_emp(int key, string name = "")
{
         string query = ???;

         if(name.length() > 0)
         {
             //needs to delete specific row. by unique key.
         }
         else
         {
             //needs to delete rows belongs to key
         }
}


On Mon, Nov 18, 2013 at 2:13 PM, d b <va230...@gmail.com> wrote:

Hi Luis,

Those are parameters.

This is the query after replacing with ?1 and ?2.

delete from emp where key = '123' and (case when name = 'abc' is null THEN
1 else name = 'abc' end);

It covered  "delete from emp where key = '123' and name = 'abc';" but not
other query.

I tried with "select  (case when name = 'abc' is null THEN 1 else name =
'abc' end) from emp;"  query. It's always going to else portion when 'abc'
doesn't exist in table. Any suggestions?

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to