My project has two fields: Email, ICNumber. while adding a new entry into table, i need to check that this two fields must not existed in the database.
One way is to create a criteriacondition, doing a selection.
Is there a better way? the Find Function? I realize if i assign the two fields to find="true", and use like following code, it didnt work:
Customer cst = new Customer();
cst.Email = "we@gmail.com";
if (cst.find())
{
Info.Text = "Email existed";
return;
}
cst = new Customer();
cst.ICNumber = "11111";
if (cst.find())
{
Info.Text = "IC Number Existed";
return;
}
-----------------------------------
the problem is the cst.find() never return true even the same email existed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The find method uses all of the attributes with find="true" to locate an object (just like as compound key).
If you run the program in debug you would see the where condition of the SQL clause being something like
select ... where t1.email=@p1 and t1.icnumber=@p2
The retrievecriteria is the best option. (VB code follows)
dim rc as CRetrieveCriteria
rc.classmap = cst.GetClassMap
rc.WhereCondition.addSelectEqualTo("Email",cst.Email)
'The third parameter being true adds the equality check using an OR condition
rc.WhereCondition.addSelectEqualTo("ICNumber",cst.Email,True)
dim cc as CCursor = rc.perform()
if cc.HasElements then
info.text = "Email or ICNumber is in use"
end if
the sql where clause generated would be something like
select ... where t1.email=@p1 or t1.icnumber=@p2
I hope that is what you are after.
- Richard.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have learnt a lot abt the framework by using it. but still, i feel that a better tutorial or a better sample application shall be provided in your web site. Maybe I can contribute a bit on this.
Regards,
Timothy
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Documentation is the next thing I'm working on. I'm going to make a release candidate of the latest code available soon, and will then get stuck into knocking out some proper documentation before a official release of the next version.
A users guide has been started (usersguide.sh5 in CVS) using HelpMaker from vizacc. Feel free to download it and look at whats in there and the structure I'm aiming for. I need feedback to make sure I'm going in the right direction.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Need help for following issue:
My project has two fields: Email, ICNumber. while adding a new entry into table, i need to check that this two fields must not existed in the database.
One way is to create a criteriacondition, doing a selection.
Is there a better way? the Find Function? I realize if i assign the two fields to find="true", and use like following code, it didnt work:
Customer cst = new Customer();
cst.Email = "we@gmail.com";
if (cst.find())
{
Info.Text = "Email existed";
return;
}
cst = new Customer();
cst.ICNumber = "11111";
if (cst.find())
{
Info.Text = "IC Number Existed";
return;
}
-----------------------------------
the problem is the cst.find() never return true even the same email existed.
The find method uses all of the attributes with find="true" to locate an object (just like as compound key).
If you run the program in debug you would see the where condition of the SQL clause being something like
select ... where t1.email=@p1 and t1.icnumber=@p2
The retrievecriteria is the best option. (VB code follows)
dim rc as CRetrieveCriteria
rc.classmap = cst.GetClassMap
rc.WhereCondition.addSelectEqualTo("Email",cst.Email)
'The third parameter being true adds the equality check using an OR condition
rc.WhereCondition.addSelectEqualTo("ICNumber",cst.Email,True)
dim cc as CCursor = rc.perform()
if cc.HasElements then
info.text = "Email or ICNumber is in use"
end if
the sql where clause generated would be something like
select ... where t1.email=@p1 or t1.icnumber=@p2
I hope that is what you are after.
- Richard.
Thanks. Richard. That is what I need.
I just misunderstood the usage of find function.
I have learnt a lot abt the framework by using it. but still, i feel that a better tutorial or a better sample application shall be provided in your web site. Maybe I can contribute a bit on this.
Regards,
Timothy
Any help is appreciated.
Documentation is the next thing I'm working on. I'm going to make a release candidate of the latest code available soon, and will then get stuck into knocking out some proper documentation before a official release of the next version.
A users guide has been started (usersguide.sh5 in CVS) using HelpMaker from vizacc. Feel free to download it and look at whats in there and the structure I'm aiming for. I need feedback to make sure I'm going in the right direction.