I have a situation in such a way that variable value has to be returned based on multiple condition. Initially it is set to passed parameter value. Below is just an algo,
create proc checkFlag (ppleid int, pflag bit, loginid int)
begin
declare vflag bit;
declare vhasRights bit;
declare vIsLocked bit;
declare vlockedUid int;
set vflag=pflag; // assign as passed param
if (vflag = 0)
then
select id, name,vflag as 'IsEditable'
from peopletable
where id=ppleid;
else
-- algo to check whether loginid has rights to edit
if (vhasrights = 1)
then
-- sql statements to check whether record is not write locked into vIsAlreadyLocked
if (vIsAlreadyLocked = 1)
then
--- sql statements to check whether locked user is login user in vlockedUid
if (vlockedUid = ploginid)
then
set vflag =1;
else
set vflag=0;
end if;
else
set vflag=0;
end if;
select id, name,vflag as 'IsEditable'
from peopletable
where id=ppleid;
end if;
end;
A. Sp. call withing sqleditor call checkflag(values.....); returns appropriate value
B. Sp. call from c#
internal void ReadPpl()
{
bool initFlag=<flag based on client end condition>;
. code for creating connection and command of type storedproc
.
MysqlParameter prm=new parameter("pflag", initFlag);
.
.
. cmd.parameter(prm)
using (mysqldatareader rdr=cmd.ExecuteReader())
{
if (rdr.HasRows())
{
rdr.Read();
**bool IsWritable=Convert.ToBoolean(Convert.ToInt32(rdr["IsEditable"])); // This is the line that returns value as passed parameter but not based on conditions in db and params **
}
Any help will be appreciated.
Thanks in advance.