|
|
|
NOTE: This Design document is subject to change at any time. |
Query
Syntax: <QUERY property-list/>
Provides access to a database via Microsoft's ADO libraries. A Query should be associated with a particular Connection object that points to the actual database being accessed. Then the Text property is set to the SQL query that you wish to execute.
When used in the ZML layout file, a DataSource is used to point to the Query, and data-aware controls then point to the DataSource. zApp handles all of the internal database operations.
You can also create a Query object using the core.createobject("Query") method. Once the Connection and Text properties have been set, you can use the Open method to execute the query is and make the matching records available in the dataset. The Item property can then be used to retrieve or set values in the current record. Various other methods can be used to step through the records to manipulate the Dataset.
Example:
Using Dataset in the ZML file
Code: |
<CONNECTION Name="MUDList" Filename="mudlist.mdb"/>
<QUERY Name="MUDData" Connection="MUDList"
Text="SELECT * FROM mudlist WHERE Title LIKE 'a%'"/>
<DATASOURCE Name="MUDSource" Dataset="MUDData" Active="true"/>
<NAVIGATOR DataSource="MUDSource" Align="top"/>
<EDIT DataSource="MUDSource" Field="Title" Align="top"/>
<EDIT DataSource="MUDSource" Field="Host" Align="top"/> |
This is a bit verbose, so zApp also allows to nest these objects and if the DataSource property of a control is missing, the last DataSource defined will be used. For example, the following code does the same thing as the previous example:
Code: |
<CONNECTION Filename="mudlist.mdb">
<QUERY Text="SELECT * FROM mudlist WHERE Title LIKE 'a%'">
<DATASOURCE Name="MUDSource" Active="true"/>
</QUERY>
</CONNECTION>
<NAVIGATOR Align="top"/>
<EDIT Field="Title" Align="top"/>
<EDIT Field="Host" Align="top"/> |
Here is an example of using a Query object directly in a script.
Code: |
Conn = core.AddControl("Connection", "MUDList")
Conn.Filename = "mudlist.mdb"
SQL = core.CreateObject( "Query", "MUDList")
SQL.Text = "SELECT * FROM mudlist WHERE Title LIKE 'a%'"
SQL.Open
Msgbox SQL.Item("Title") |
Usage Tips
- Remember that even when using the ZML layout, you need to activate your data connections somewhere. Typically you will need some sort of Script code like
Code: |
DataSource.Active = true |
to make your datasource active and enable the data-aware controls that use the datasource. Or you can set the Active property in the <DATASOURCE> tag as we have done in these examples.
|
|