Running Stored Procedures

Question:
In the Tastrade sample framework and application that ships with Visual FoxPro, I only see examples of running stored procedures in a VFP database from a rule or validation of a table. How can I run some from a form? (I have Visual FoxPro 6.0.)

Answer:
Stored procedures can be called from anywhere as long as the database is open and is the currently active database in the datasession.

Enter the following two commands from the command window:

 CREATE DATABASE TESTMODIFY PROCEDURES

This creates a database called “test” and opens the stored procedures for the database. Now put this in the following stored procedure:

 PROCEDURE TestProcMESSAGEBOX("Hi")ENDPROC

Save and close the stored procedures window.

Enter the following command from the command window:
CLOSE DATA. You have now created a database with a stored procedure, and have closed the database.

Try the following command from the command window:
?TestProc(). You will receive the error “File ‘TestProc’ does not exist.”

Enter the following commands from the command window:

 OPEN DATA TESTSET DATABASE TO TEST?TestProc()

Now you will receive the messagebox because the database is open and is the active database.

Note that if you have more than one database open at the same time in the same datasession, only stored procedures from the currently active (e.g., SET DATABASE TO ) will be available.

For example, create another database called “test2” that does not have a stored procedure called testproc and execute the following commands from the command window:

 CLOSE DATA ALLOPEN DATABASE TESTOPEN DATABASE TEST2SET DATABASE TO TEST* The following line shows * the messagebox because the * database "test" is * the active database ?TestProc()  SET DATABASE TO TEST2* The following line generates * an error because the * active database (test2) does * not have a stored procedure * called testproc. ?TestProc() 

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: