Omnis Studio v10.1 Basic Web Dev
IT
it at plastipol.com
Thu Sep 17 06:31:28 EDT 2020
Hi,
In the table superclass I have a method $TestForAUniqueIndexValue
Begin statement
Sta: {SELECT count(*)}
Sta: {FROM [$cinst.$servertablenames()]}
Sta: {WHERE [mid(nam(pFieldname);pos('.';nam(pFieldname))+1;len(nam(pFieldname)))] = @[pFieldname]}
End statement
Get statement lvSQL
Do $cinst.$statementobject.$execdirect(lvSQL)
Do $cinst.$sqlerror
Do $cinst.$statementobject.$fetchinto(lvCount)
If lvCount=0
Calculate #F as 1 ;; No rows with the values in the field passed therefore Test for a Unique Value is True
Else
Calculate #F as 0 ;; Rows with the values in the field passed therefore Test for a Unique Value is False
End If
Quit method #F
pFieldname is a FieldReference parameter
Usually if I want to test for a duplicated value in the window field I have this method behind the field.
On evAfter
If ivInsert
Do ivMaestro.[con("$TestForAUniqueIndexValue(";$cobj().$dataname;")")] Returns #F
If flag false
OK message (Icon,Sound bell) {Esta referencia ya existe !}
Quit event handler (Discard event)
End If
End If
ivMaestro is a row defined from a table with a superclass containing the method $TestForAUniqueIndexValue
This works perfect. Hope this helps.
regards
xavier
> El 17 sept 2020, a las 12:14, Martin Obongita via omnisdev-en <omnisdev-en at lists.omnis-dev.com> escribió:
>
> Dear Rocco,
> I have amended the code thus:
>
>
> Begin statement
>
> Sta:SELECT description FROM departments
>
> Sta:WHERE description = @[pDepartmentDescription]
>
> End statement
>
> If kTrue
>
> OK message 'Duplicate department'
>
> Quit method kFalse
> End If
> When I execute this method, the flag is set to kTrue and yet there is no matching record. The same script in sql query browser returns zero records.
>
> Regards,Martin.
>
>
>
>
>
>
> On Thursday, September 17, 2020, 12:20:36 PM GMT+3, Phil (OmnisList) via omnisdev-en <omnisdev-en at lists.omnis-dev.com> wrote:
>
> Hi Martin,
>
> Was it a typo in the email, or is there no space between select and
> name, I think that won't help.
>
> and as Rocco said, you only need the name='xx' in the where clause.
>
> regards
> Phil Potter
> Based in Chester in the UK.
>
> On 17/09/2020 07:54, Martin Obongita via omnisdev-en wrote:
>> Dear All,
>> I have a department sql table with columns “id” and“name”
>> In the “departments” table class I have a method to checkfor duplicate “name” column.
>>
>> I therefore pass a parameter of the old name and the newname to check for an existing department name.
>>
>> Begin statement
>>
>> Sta:SELECTname FROM departments
>>
>> Sta:WHERE name= @[pDepartmentName] AND name <> @[pDepartmentNameOld]
>>
>> End statement
>>
>> When I execute the method, the flag is set to kTrue andyet there is no matching record found.
>>
>> I have run this statement in the sql query builder in thedatabase and no record is found.
>> Where am I missing something?
>> Best regards,Martin Obongita.
>>
> _____________________________________________________________
> Manage your list subscriptions at http://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
>
> _____________________________________________________________
> Manage your list subscriptions at http://lists.omnis-dev.com
> Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
More information about the omnisdev-en
mailing list