Navigation:  Samples >

Querydef Sample

Previous pageReturn to chapter overviewNext page

This example creates a new QueryDef object and appends it to the QueryDefs collection in the current database. Then the example enumerates all the QueryDef objects in the database and all the properties of the new QueryDef. See the methods and properties listed in the QueryDef summary topic for additional examples.

 

FUNCTION Start

LOCAL dbeng        AS DaoDBEngine

LOCAL db                AS DaoDatabase

LOCAL qdftest        AS DaoQueryDef

LOCAL uVar                AS USUAL

LOCAL i                AS INT

LOCAL oErr                AS USUAL

LOCAL cbOldErr        AS CODEBLOCK

Set COlor TO w+/b

cls

BEGIN SEQUENCE

 cbOldErr := ErrorBlock({|oErr|_Break(oErr)})

 dbEng        := DaoDbengine{}

 

 

 // Open the database.

 db := dbEng:OpenDatabase("\VO2Jet\Northwind.mdb",NIL,NIL,NIL)

 // Delete if it already exists

 BEGIN SEQUENCE

 db:QueryDefs:Delete("This is a test")

 END

 

 // Create a query definition.

 qdfTest := db:CreateQueryDef("This is a test","Select * from customers")

 ? "Name, # of parameters"        

 // Enumerate QueryDef objects.

 FOR i = 1 TO db:QueryDefs:Count

         ? db:QueryDefs:[Item,i]:Name, db:QueryDefs:[Item,i]:PARAMETERS_:Count

 NEXT

 wait

 // Enumerate built-in properties of qdfTest

 ? "qdfTest:Name          : ", qdfTest:Name

 ? "qdfTest:DateCreated   : ", qdfTest:DateCreated

 

 ? "qdfTest:LastUpdated   : ", qdfTest:LastUpdated

 ? "qdfTest:SQL           : ", qdfTest:SQL

 ? "qdfTest:ODBCTimeout   : ", qdfTest:ODBCTimeout

 ? "qdfTest:Updatable     : ", qdfTest:Updatable

 ? "qdfTest:Type          : ", qdfTest:Type

 ? "qdfTest:Connect       : ", qdfTest:Connect

 ? "qdfTest:ReturnsRecords: ", qdfTest:ReturnsRecords

 

 // Delete the query definition.

 db:QueryDefs:Delete("This is a test")

RECOVER USING oErr

 Eval(cbOldErr,oErr)        

END

Wait