Build-in field validation is not working

Posts   
 
    
dvanzo
User
Posts: 8
Joined: 05-Sep-2008
# Posted on: 13-Aug-2009 20:39:34   

I've connected to a Oracle Database. Generated the LLBLGen projects using the Adapter approuch. But I can't make the Build-in field validation to work.

I've tested in a table (GROUP) with two fields:

CD_GROUP: PK Varchar2(10) NOT NULL
DS_GROUP: Unique Varchar2(50) NOT NULL

Made a test application with only one form and one button that retreives a record, updates the DS_GROUP field to become null and tries to save it.


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Try
            Dim groupEntity As New DAL.Adapter.EntityClasses.TsGroupEntity
            groupEntity.CdGroup = "SPC2"        'I set the PK value for the record to fetch

            Dim daa As New DAL.Adapter.DatabaseSpecific.DataAccessAdapter
            daa.FetchEntity(groupEntity)        'Fetch the record

            'Entity Fields:
            '  groupEntity.CdGroup = "SPC2"  NOT NULL
            '  groupEntity.DsGroup = "SPC222"   NOT NULL

            groupEntity.DsGroup = String.Empty  ' Clear the description

            daa.SaveEntity(groupEntity)      'Try to save and an oracle client exeption is thrown
        Catch ex As Exception
            MessageBox.Show(ex.Message)      'Oracle's ORA-01407: no se puede actualizar ("BBR2"."TS_GROUP"."DS_GROUP") a un valor NULL
        End Try

    End Sub

But I keep on getting an exception with the Oracle's ORA-01407 instead of the Build-in field validation.

Any Help?

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 13-Aug-2009 21:35:02   

What happens if you try


 groupEntity.DsGroup = null ' Clear the description

The String.Empty value ("") is not the same as a null and I would not expect our validation to catch this.

I'm unsure why Oracle would throw an error about this though - unless it is treating nulls and empty strings as the same thing ?

Matt

dvanzo
User
Posts: 8
Joined: 05-Sep-2008
# Posted on: 13-Aug-2009 23:05:57   

By null you mean Nothing or DBNull.Value.

With Nothing does the same as String.Empty.

With DBNull.Value I get the "Value of type 'System.DBNull' cannot be converted to 'String'." compilation error.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Aug-2009 07:13:51   

I believe you sould use Nothing to set the field to null.

From the LLBLGen Pro Designer, do you see the field marked as not nullable (IsNullable == false)?

Have you set buildInValidationBypassMode to a value in the application configuration appsettings ?

Which LLBLGen Pro runtime library version are you using?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 14-Aug-2009 07:15:34   

In this case, "" and NULL are treated the same. Now, my guess is that the field isn't set (the field doesn't allow NULLS). If you check this:

groupEntity.Fields["DsGroup"].IsChanged

... it should be false after setting the field to NULL/""

You could confirm that by doing this:

success = groupEntity.SetNewFieldValue((int)GroupFieldIndex.DsGroup, null);

This post may be useful: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8734&StartAtMessage=0&#48486

David Elizondo | LLBLGen Support Team