DBStorage provides three ways to retrieve data from the database:
To retrieve a row based on the value stored in the column that you designated as the table’s key in your initial call to InitStorage, you can use the GetData method to retrieve the column.
For example, assume the following call to InitStorage:
REM -- Create a storage object for the order forms (shopper's basket)
Set mscsOrderFormStorage = Server.CreateObject("Commerce.DBStorage")
Call mscsOrderFormStorage.InitStorage(MSCSSite.DefaultConnectionString, "Clocktower_basket", "shopper_id", "Commerce.OrderForm", "marshalled_order", "date_changed")
This call to InitStorage specifies the shopper_id column as the key. The following call to GetData returns the row that contains the order form being used by the specified customer:
set mscsOrderForm = mscsOrderFormStorage.GetData(null, ShopperID)
In this example, the GetData method searches the Shopper_id
column of the Clocktower_basket
table for the specified shopper ID.
To retrieve a single row of data, where an arbitrary column or group of columns contain a specified set of values, use the LookupData method. To use this method, first initialize two arrays to contain the column names and sought values, respectively.
The following example looks for the record in which the product_color
column contains green
. Two arrays are created, each containing a single item only, to store column names and values:
Column(0) = "product_color"
Value(0) = "green"
Set Obj = Storage.LookupData(Null, Column, Value)
In the preceding example, the Column
parameter designates the table column in which to look for the color green
. If the arrays contain more than one element, LookupData searches for a row in which all of the column/value pairs match.
If the LookupData method finds the row containing the column/value pair that you specify, then it returns a Dictionary object initialized with the contents of that row. Otherwise, it returns Null.
If LookupData finds more than one row containing the data that you specified, then it still returns Null. Consequently, unless you are searching for a column value that is sure to be unique for the column you are searching, you should use the LookupMultipleData method instead. LookupMultipleData returns a SimpleList object containing a list of Dictionary objects. Each Dictionary object lists the rows in which the specified column contains the specified data.
You would use LookupMultipleData to search for all previous receipts saved for a particular customer, for example.