Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual FoxPro
Expertise: Beginner
Sep 8, 1999

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 TEST
MODIFY PROCEDURES
This creates a database called "test" and opens the stored procedures for the database. Now put this in the following stored procedure:
 
PROCEDURE TestProc
MESSAGEBOX("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 TEST
SET 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 ALL
OPEN DATABASE TEST
OPEN DATABASE TEST2
SET 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() 
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date