Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Constraint Error Handling with ADO and SQL
Message
From
18/06/2001 11:33:23
 
 
To
15/06/2001 18:49:57
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Miscellaneous
Thread ID:
00519999
Message ID:
00520629
Views:
16
>>In further inspection, the Status property does get populated in this circumstance. This property should return 11 (adFieldSchemaViolation) for the offending field object.
>>
>>Can you post more details as to how you are checking the status field?
>
>I mean status property.


Hi Again,

Here is some sample code. The problem lies in the HandleConstraint Function and is highlighted in red bold :

Thanks for your help.

Regards,

Gerry
#DEFINE adfilterconflictingrecords 5

* Create the Connection
ON ERROR erroradohandler(orecordset)

oconnection = CREATEOBJECT("ADODB.Connection")
oconnection.errors.CLEAR
orecordset = CREATEOBJECT("ADODB.Recordset")
oconnection.OPEN("Provider=SQLOLEDB;Server=GerryDeskTop;Database=FocusTest;User Id=SA;Password=;")

*Example 1 - Create Database Constraint Error
WITH orecordset
   .activeconnection = oconnection
   && Optimisitic Locking
   .locktype = 4 							
   .OPEN("customer")
   .addnew
   && Record Not Allowed. Error should be raised here
   .FIELDS(0).VALUE=1111
   .FIELDS(1).VALUE=" " 
   && Effect All      				
   .updatebatch(3)							
ENDWITH

FUNCTION erroradohandler(lorecordset)
   LOCAL lnerrornumber
   * Have We Got Errors in the Errors Collection of The Connection Object
   WITH lorecordset.activeconnection.errors
      IF .COUNT > 0
         FOR lcnt = 1 TO .COUNT
            lnerrornumber = .ITEM(lcnt).NUMBER
            DO CASE
               &&& Constraint Error. This Line executes OK
               CASE  lnerrornumber = -2147217873				
                  IF handleconstraint(lorecordset)
                     RETURN .T.
                  ELSE
                     RETURN .F.
                  ENDIF
               OTHERWISE
                  WAIT WINDOW "Unknown Error"
            ENDCASE
         ENDFOR
      ENDIF
   ENDWITH
ENDFUNC


FUNCTION handleconstraint(lorecordset)
   LOCAL lnrecordcount lcoldfilter lorecord
&& We Should have Records in the ADO Record Sets Filter

   WITH lorecordset
       &&& Hold old Filter
      lcoldfilter = .FILTER
	  &&& Set Filter
      .FILTER = adfilterconflictingrecords						
      lnrecordcount = .recordcount
      &&& If we Have Records in Filter .......
      IF lnrecordcount > 0										
       &&& Ensure we at 1st Record
         IF !.BOF								    .movefirst
         ENDIF
         &&& Scan Records in Filter
         DO WHILE !.EOF	
         &&& Examine status code in each field										
            FOR lncnt = 1 TO .FIELDS.COUNT	

                &&& HERE IS THE PROBLEM.  STATUS PROPERTY IS ALWAYS ZERO


	               lnstatuscode = .FIELDS(lncnt-1).STATUS  
            ENDFOR
            .movenext
         ENDDO
      ENDIF
   ENDWITH
ENDFUNC
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform