How to Verify Expression 
Author Message
 How to Verify Expression
I would like to verify an expression typed in by the user before
attemping to execute the expression.

For example, when executing a select statement, special characters

before executing the select statement.

FoxPro already does this in the expression builders found in the
development package.  I'd like something simular to this.

Anyone know how this is done?

Thanks!
Paul



Fri, 16 Feb 2001 03:00:00 GMT
 How to Verify Expression

Hi Moloch (is that your first name, or your last?)

Suppose your user's statement is in a variable 'cMacro', e.g.

cMacro = [select * from customers where name = 'M' into cursor q_cust]

The following code will prevent crashing of your application (I hope).
Moreover, it will enable you to give some feedback to the user about the
kind of error in the statement, if any.

nErr = 0
oldOnError = on( 'error' )
on error nErr = error()
&cMacro
on error &oldOnError
*
do case
case nErr = 0               && no error found
    wait window "Well done!"
otherwise
    wait window "Error " + ltrim( str( nErr ) ) + " in statement"
endcase

The macro will be executed if it's syntactically correct. To my opinion,
this can be regarded as a drawback. The above code should be the final part
of a routine, rather than the first part. Other checks should be done in
advance, to ensure that the user only gets access to certain data and
doesn't disturb your application's environment (think of your variables and
settings). You'll find out that it's a hack of a job to build such an
advanced generic (query) routine. But don't let that discourage you to do
it. You'll find e{*filter*}ment, enlightenment and great joy and happiness among
the path! <g>

Quote:

>I would like to verify an expression typed in by the user before
>attemping to execute the expression.
>For example, when executing a select statement, special characters

>before executing the select statement.



Sat, 17 Feb 2001 03:00:00 GMT
 How to Verify Expression
If you are building SQL select statements and you want to trap syntax
errors, put code in the error event of the object where the SQL
statement is run.  If the statement is incorrect, the error events
fires, then you can decide how resolve it.

Charlie



Sat, 17 Feb 2001 03:00:00 GMT
 How to Verify Expression
Howdy,

Thanks for the info.  I've considered this route but as you stated, we
would have to execute the statement to catch the error.  I'm trying to
avoid this because I'm working with large amounts of data.  I'd like
to catch syntax errors before executing a select statement on 500,000
records.

Any other thoughts :)

Thanks!
Paul

On Tue, 1 Sep 1998 00:11:48 +0200, "Peter de Valen?a"

Quote:

>Hi Moloch (is that your first name, or your last?)

>Suppose your user's statement is in a variable 'cMacro', e.g.

>cMacro = [select * from customers where name = 'M' into cursor q_cust]

>The following code will prevent crashing of your application (I hope).
>Moreover, it will enable you to give some feedback to the user about the
>kind of error in the statement, if any.

>nErr = 0
>oldOnError = on( 'error' )
>on error nErr = error()
>&cMacro
>on error &oldOnError
>*
>do case
>case nErr = 0               && no error found
>    wait window "Well done!"
>otherwise
>    wait window "Error " + ltrim( str( nErr ) ) + " in statement"
>endcase

>The macro will be executed if it's syntactically correct. To my opinion,
>this can be regarded as a drawback. The above code should be the final part
>of a routine, rather than the first part. Other checks should be done in
>advance, to ensure that the user only gets access to certain data and
>doesn't disturb your application's environment (think of your variables and
>settings). You'll find out that it's a hack of a job to build such an
>advanced generic (query) routine. But don't let that discourage you to do
>it. You'll find e{*filter*}ment, enlightenment and great joy and happiness among
>the path! <g>


>>I would like to verify an expression typed in by the user before
>>attemping to execute the expression.
>>For example, when executing a select statement, special characters

>>before executing the select statement.

The Unofficial Silent Hunter II Homepage
http://www.***.com/ :10021/P/ppowell/SilentHunterII/


Sat, 17 Feb 2001 03:00:00 GMT
 How to Verify Expression

Quote:

>If you are building SQL select statements and you want to trap syntax
>errors, put code in the error event of the object where the SQL
>statement is run.  If the statement is incorrect, the error events
>fires, then you can decide how resolve it.

Thanks for the tip. I'll certainly try it in VFP. Is there also an event
that'll act on the pressing of the ESC key?

P.



Mon, 19 Feb 2001 03:00:00 GMT
 How to Verify Expression

Quote:
>Thanks for the info.  I've considered this route but as you stated, we
>would have to execute the statement to catch the error.  I'm trying to
>avoid this because I'm working with large amounts of data.  I'd like
>to catch syntax errors before executing a select statement on 500,000
>records.

Try this:

***** Code begins here *************

m.cMacro = <your expression, string format>

if IsValid(m.cMacro)
        SELECT etc...
endif

FUNCTION IsValid
LPARAMETER pExpr
LOCAL lcOldError, lcCorrect

m.lcOldError = on("error")
m.lcCorrect  = .T.
on error m.lcCorrect = .F.

=evaluate(m.pExpr)

on error &lcOldError
return m.lcCorrect

**** End code ********************

Hope this helps you.
-------------------------------------------------
Greetings: Jorge
----------------
"As the right hemisphere of the brain controls
 the left side of the body then only left-handers
 are in their right minds"  (8
-------------------------------------------------



Tue, 20 Feb 2001 03:00:00 GMT
 How to Verify Expression
It will work.

LOCAL lcExpr

..... code to get expression

IF type('lcExpr')#'L'
        messageBox("it's bad",64)
        return .f.
ELSE
        .... It's ok
ENDIF


Quote:
>Hi Moloch (is that your first name, or your last?)

>Suppose your user's statement is in a variable 'cMacro', e.g.

>cMacro = [select * from customers where name = 'M' into cursor q_cust]

>The following code will prevent crashing of your application (I hope).
>Moreover, it will enable you to give some feedback to the user about the
>kind of error in the statement, if any.

>nErr = 0
>oldOnError = on( 'error' )
>on error nErr = error()
>&cMacro
>on error &oldOnError
>*
>do case
>case nErr = 0               && no error found
>    wait window "Well done!"
>otherwise
>    wait window "Error " + ltrim( str( nErr ) ) + " in statement"
>endcase

>The macro will be executed if it's syntactically correct. To my opinion,
>this can be regarded as a drawback. The above code should be the final part
>of a routine, rather than the first part. Other checks should be done in
>advance, to ensure that the user only gets access to certain data and
>doesn't disturb your application's environment (think of your variables and
>settings). You'll find out that it's a hack of a job to build such an
>advanced generic (query) routine. But don't let that discourage you to do
>it. You'll find e{*filter*}ment, enlightenment and great joy and happiness among
>the path! <g>


>>I would like to verify an expression typed in by the user before
>>attemping to execute the expression.
>>For example, when executing a select statement, special characters

>>before executing the select statement.

MAX CHEN

P.R.China


Wed, 21 Feb 2001 03:00:00 GMT
 How to Verify Expression
That's ok if the expression is a function that returns a logical...
(i.e. table1.field1 > 'Foo'), where TYPE( table1.field1) = 'C'
... but if you're generating clauses for a command, such as 'INDEX ON ... TAG
...',
then I'm afraid you'll have to go the route of the 'ON ERROR' routine mentioned
earlier.


Mon, 26 Feb 2001 03:00:00 GMT
 
 [ 8 post ] 

 Relevant Pages 

1. How to Verify Expression once again....

2. Referencing expressions in other expressions in a single select statement

3. ORA-01790: expression must have same datatype as corresponding expression

4. Verifying ADO recordset changes

5. how to verify the database support Unicode

6. Manually scripting VERIFY after BACKUP

7. verifying permissions.

8. Need SQL code to verify Username and Password

9. Filegroup backup fails when verify is set

10. How to verify MSDTC install on Win95 client?

11. backupexec verify problem

12. How to verify IIS is installed


 
Powered by phpBB® Forum Software