strangerxxy
|
Posted: 04/12/2004, 2:31 AM |
|
Hello to all,
I have a question since i am new to CCS as follows:
I have a database (in mysql) where a table (order_classroom) should have unique records for three fields (order_date, classroom_id, classhour_id). I have an index in the database for those fields and of course i get an error back from the database when the unique rule is beeing broked. How can i make a validation rule in CCS so that the application checks the db and notifies me that the unique rule is about to beeing broken.
I looked up the forum at this link http://forums.codecharge.com/posts.php?post_id=37054 but its not clear to me. I really need some help on this topic so i want to thank in advance to u.
|
|
|
peterr
Posts: 5971
|
Posted: 04/12/2004, 10:48 AM |
|
I think that you should be able to use the "On Validate" event and set the error message there, like shown at http://docs.codecharge.com/studio/html/ProgrammingTechn...Validation.html
Though in the IF statement you may need to use the CCDLookup function to check if the field(s) already exists in the database.
I just checked the generated code after using the "Unique" property and I see that the generated code already has such CCDLookUp logic, therefore you can simply copy it from there. Set any field's "Unique" property to "Yes" and then search for the corresponding field name in the code, or for the phrase "is already in database".
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
strangerxxy
|
Posted: 04/12/2004, 1:45 PM |
|
Ok thank u peter thats very kind answering immediately. So i set the three fields to unique as u told me and i got the code i attached lower. The question is how do i combine this three statements to check for unique record for this three fields. Thank u in advance
if(CCDLookUp("COUNT(*)", "order_classroom", "order_date=" . $this->ds->ToSQL($this->ds->TextBox1->GetDBValue(), $this->ds->TextBox1->DataType) . $Where, $this->ds) > 0)
$this->TextBox1->Errors->addError("The value in field TextBox1 is already in database.");
$this->ds->ListBox2->SetValue($this->ListBox2->GetValue());
if(CCDLookUp("COUNT(*)", "order_classroom", "classhour_id=" . $this->ds->ToSQL($this->ds->ListBox2->GetDBValue(), $this->ds->ListBox2->DataType) . $Where, $this->ds) > 0)
$this->ListBox2->Errors->addError("The value in field ListBox2 is already in database.");
$this->ds->Id->SetValue($this->Id->GetValue());
if(CCDLookUp("COUNT(*)", "order_classroom", "classroom_id=" . $this->ds->ToSQL($this->ds->Id->GetDBValue(), $this->ds->Id->DataType) . $Where, $this->ds) > 0)
$this->Id->Errors->addError("The value in field Id is already in database.");
|
|
|
peterr
Posts: 5971
|
Posted: 04/12/2004, 2:18 PM |
|
You would need to construct the correct SQL statement as the first parameter of the CCDLookUp function.
Something like:
if(CCDLookUp("COUNT(*)", "order_classroom", "order_date=" . $this->ds->ToSQL($this->ds->TextBox1->GetDBValue(), $this->ds->TextBox1->DataType) . " AND classhour_id=" . $this->ds->ToSQL($this->ds->ListBox2->GetDBValue(), $this->ds->ListBox2->DataType) . " AND classroom_id=" . $this->ds->ToSQL($this->ds->Id->GetDBValue(), $this->ds->Id->DataType) . $Where, $this->ds) > 0)
$FormName->Errors->addError("The value in field Id is already in database.");
I do not program in PHP therefore you may need to finish and debug this statement.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
|