How to Use the NODATA and NOREQUERY Clauses of USE (129077)



The information in this article applies to:

  • Microsoft Visual FoxPro for Windows 3.0

This article was previously published under Q129077

SUMMARY

The NOQUERY and NODATA clauses of the USE command are used with local and remote views. A view is an updatable set of records that is stored in a database. Once a view is created, you can open it with the USE command. This article provides an example that illustrates the use of the NODATA and NOQUERY clauses.

MORE INFORMATION

The NOQUERY and NODATA clauses allow you to open a query without [ downloading the data. They can be useful when you have a large set of records, and you want to verify the structure of the result set before you download the data. The NOREQUERY clause is used in conjunction with the USE <view> AGAIN command. It prevents FoxPro from re-querying the data if you open the view in another work area. Use the REQUERY() function when you need to retrieve the data.

The following example illustrates how to use the NODATA and NOREQUERY clauses on a local view. A parameterized view is created with the CREATE SQL VIEW command and opened with a USE...NODATA command. No records are displayed. Then the same view is opened in another work area with the USE.. AGAIN NOREQUERY command. Note that it is not updated until the REQUERY() function is executed. To run this example, copy and paste the following code into a program file, and then run it.
   LOCAL nViews, cCity

   OPEN DATA SYS(2004) + 'samples\data\testdata'
   * Creates an array that holds the names of all the views in the database
   nViews = ADBOBJECTS(a_View, 'VIEW')
   IF nViews > 0
      IF ASCAN(a_View, 'COMPANY_VIEW') > 0
         DELETE VIEW Company_view
      ENDIF
   ENDIF

   cCity = 'London'
   CREATE SQL VIEW Company_view AS ;
      SELECT cust_id, company, city ;
      FROM customer ;
      WHERE city = ?cCity

   IF USED('Company_view')
      USE IN Company_view
   ENDIF

   * Open the view without downloading the data:
   SELECT 0
   USE Company_view NODATA
   BROWSE NOWAIT
   =MESSAGEBOX(IIF(RECCOUNT() = 0, 'No data yet.', 'Now we have data'))

   * Download the data:
   ?REQUERY()
   SHOW WINDOW Company_View REFRESH
   =MESSAGEBOX(IIF(RECCOUNT() = 0, 'No data yet.', 'Now we have data'))

   * Modify the value of the parameter:
   cCity="Paris"
   SELECT 0
   USE Company_view AGAIN NOREQUERY
   BROWSE NOWAIT
   =MESSAGEBOX("City is "+cCity+chr(13)+"Query is not updated")
   ?REQUERY()
   =MESSAGEBOX("City is "+cCity+chr(13)+"Query is updated")
				

REFERENCES

Visual FoxPro for Windows "Developer's Guide," version 3.0, Chapter 8, "Creating Multi-Table Views."

Modification Type:MajorLast Reviewed:2/12/2000
Keywords:kbcode KB129077