Running Stored Procedures

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:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as