Home > Archive > Visual FoxPro SQL Queries > January 2006 > Simple problem???









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Simple problem???
Rotsj

2006-01-18, 8:25 pm

Hi,
i'm using vfp9 and mysql as my database.
I use the sqlexec command to insert, update and delete records. After i
execute, i want to know if everything works fine, so i thought i use:

PROCEDURE errhand
= AERROR(aErrorArray)
CLEAR
FOR n = 1 TO 7
? aErrorArray(n) && Store this in a log file
ENDFOR
CLEAR ERROR

if i put "ON ERROR DO errhand" before the sqlexec, the on error doesn't seem
to recognise when a error occurs. If i create an error with the sqlexec and
manually call the errhand procedure, it works fine.

Any solutions?

Rotsj
P.s. how can you check the existence of an array. As the aerror function
creates the aErrorArray, there will be no array if there was no error. If i
then call the procedure i get an error anyway, that the aErrorArray does not
exist. If you try the TYPE function on a non existing array, you also get
errors.


Olaf Doschke

2006-01-18, 8:25 pm

> if i put "ON ERROR DO errhand" before the sqlexec, the on error doesn't
> seem
> to recognise when a error occurs.

This will at least not catch errors of the mysql server.
It would only detect false parameters of sqlexec eg.

> If i create an error with the sqlexec and
> manually call the errhand procedure, it works fine.

Well, then maybe the errhand procedure is not know
when you issue ON ERROR DO errhand.
You need SET PROCEDURE.

But if you want to catch errors of a single command,
why not make use of TRY...CATCH...FINALLY
instead? A general error handler like ON ERROR
is the worse alternative.

> P.s. how can you check the existence of an array. As the aerror function
> creates the aErrorArray, there will be no array if there was no error. If
> i
> then call the procedure i get an error anyway, that the aErrorArray does
> not
> exist. If you try the TYPE function on a non existing array, you also get
> errors.

TYPE("myArray[1]")#"U"
Type unlike Vartype expects the variable (or expression!) as a string.
Therefore you can also test nonexistence, wheras Vartype errors if
the variable does not exist.

lnRows = AERROR(....)

if lnRows >0
*process array
else
* no rows, no array
endif

Any VFP function creating an array returns the array size/number of rows.

Read the help on AERROR. Read the help on Errorhandling (especially
"Error Handler Priority").

Bye, Olaf.


Jack Jackson

2006-01-18, 8:25 pm

On Wed, 18 Jan 2006 22:52:10 +0100, "Rotsj" <r.knipscheer@home.nl>
wrote:

>Hi,
>i'm using vfp9 and mysql as my database.
>I use the sqlexec command to insert, update and delete records. After i
>execute, i want to know if everything works fine, so i thought i use:
>
>PROCEDURE errhand
>= AERROR(aErrorArray)
>CLEAR
>FOR n = 1 TO 7
>? aErrorArray(n) && Store this in a log file
>ENDFOR
>CLEAR ERROR
>
>if i put "ON ERROR DO errhand" before the sqlexec, the on error doesn't seem
>to recognise when a error occurs. If i create an error with the sqlexec and
>manually call the errhand procedure, it works fine.
>
>Any solutions?


SQLEXEC does not cause an error to occur. I have a procedure that
does my SQLEXEC calls - I always call that procedure instead of
calling SQLEXEC directly. In that procedure:

nErr = SQLEXEC(.....)
IF ( m.nErr < 0 )
ERROR 1526 && Issue the ODBC error message
ENDIF

>
>Rotsj
>P.s. how can you check the existence of an array. As the aerror function
>creates the aErrorArray, there will be no array if there was no error. If i
>then call the procedure i get an error anyway, that the aErrorArray does not
>exist. If you try the TYPE function on a non existing array, you also get
>errors.


TYPE will not give an error for a non-existent array. In general, you
could use TYPE('aErrorArray') != 'U'. For this specific case, AERROR
returns the number of rows created in the array so you could test that
for > 0:

PROCEDURE errhand
LOCAL nError, n
LOCAL ARRAY aErrorArray[1]
nError = AERROR(m.aErrorArray)
IF m.nError > 0
CLEAR
FOR n = 1 TO m.nError
? aErrorArray(m.n) && Store this in a log file
ENDFOR
CLEAR ERROR
ENDIF
Kurt Grassl

2006-01-23, 3:24 am

Hi,

> TYPE("myArray[1]")#"U"



btw. the TYPE-function has since VFP 9 a second paramter
? TYPE("myArray", 1)
gives 'A' or 'U'.

Kurt


Olaf Doschke

2006-01-23, 8:25 pm

> btw. the TYPE-function has since VFP 9 a second paramter
> ? TYPE("myArray", 1)
> gives 'A' or 'U'.

or 'C' for collection.

I see, especially being able to test for a collection is a nice feature.

Bye, Olaf.


AA

2006-01-26, 5:01 pm

SQLEXEC, SQLSTRINCONNECT and SQLCONNECT return -1 if there's an ODBC or
server error. You can then use AERROR to read the error message. If the fist
row of the array reads 1526 it's an ODBC error.
-Anders

"Rotsj" <r.knipscheer@home.nl> skrev i meddelandet
news:dqmd96$nvb$1@ne
ws6.zwoll1.ov.home.nl...
> Hi,
> i'm using vfp9 and mysql as my database.
> I use the sqlexec command to insert, update and delete records. After i
> execute, i want to know if everything works fine, so i thought i use:
>
> PROCEDURE errhand
> = AERROR(aErrorArray)
> CLEAR
> FOR n = 1 TO 7
> ? aErrorArray(n) && Store this in a log file
> ENDFOR
> CLEAR ERROR
>
> if i put "ON ERROR DO errhand" before the sqlexec, the on error doesn't
> seem
> to recognise when a error occurs. If i create an error with the sqlexec
> and
> manually call the errhand procedure, it works fine.
>
> Any solutions?
>
> Rotsj
> P.s. how can you check the existence of an array. As the aerror function
> creates the aErrorArray, there will be no array if there was no error. If
> i
> then call the procedure i get an error anyway, that the aErrorArray does
> not
> exist. If you try the TYPE function on a non existing array, you also get
> errors.
>
>



Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com