SQL::ResultSet Object
Description
SQL::ResultSet Object properties and methods.
Discussion
When a SQL query returns one or more rows of data, you can use the ResultSet object to get the description of the result set and to navigate within the rows of the results to retrieve the data.
- Name
- Description
- More about the SQL::ResultSet Object
While working in the Interactive window, after creating the rs SQL::ResultSet object, you could type.
Using the StreamingMode property
In this example, we are using the NextRow() function to test for the existence of data. Normally, we would not want to do this as it would read the data values of the first row and not include them in the output string. Setting StreamingMode to .t. turns off the data fetch so the row data is still available.
The script below shows what happens when you reposition the result set prior to calling a streaming mode function (such as ToString(), ToOpenTable()). Note that when in non-streaming mode, the data for the row positioned to is loaded into memory. This can cause the first row to be omitted when a streaming function is called. To avoid this, if you call positioning functions such as NextRow() or GoToRow(), you will want to set the StreamingMode property to true.
If you actually retrieve data using the Data() or DataIsNull() function, you must re-execute the query before calling a streaming function.
dim cn as sql::Connection ?cn.open("::Name::AADemo-Northwind") = .T. ?cn.execute("select * from categories") = .T. 'nextrow() moves you to row 1 AND fetches the data into local buffers so row 1 is excluded ?cn.resultset.nextrow() = .T. ?cn.resultset.tostring() = 2 Condiments Sweet and savory sauces, relishes, spreads, and seasonings <Binary Data> 3 Confections Desserts, candies, and sweet breads <Binary Data> 4 Dairy Products Cheeses <Binary Data> 5 Grains/Cereals Breads, crackers, pasta, and cereal <Binary Data> 6 Meat/Poultry Prepared meats <Binary Data> 7 Produce Dried fruit and bean curd <Binary Data> 8 Seafood Seaweed and fish <Binary Data> ?cn.execute("select * from categories") = .T. 'Setting StreamingMode to .t. causes the NextRow() call to skip reading the data. cn.ResultSet.StreamingMode = .t. ?cn.resultset.nextrow() = .T. ?cn.resultset.tostring() = 1 Beverages Soft drinks, coffees, teas, beers, and ales <Binary Data> 2 Condiments Sweet and savory sauces, relishes, spreads, and seasonings <Binary Data> 3 Confections Desserts, candies, and sweet breads <Binary Data> 4 Dairy Products Cheeses <Binary Data> 5 Grains/Cereals Breads, crackers, pasta, and cereal <Binary Data> 6 Meat/Poultry Prepared meats <Binary Data> 7 Produce Dried fruit and bean curd <Binary Data> 8 Seafood Seaweed and fish <Binary Data> ?cn.execute("select * from categories where true = false") = .T. ?cn.resultset.nextrow() = .F. ?cn.resultset.tostring() = ""
Properties
- ActiveLinkDBFRowSyntaxCharacter
ActiveLinkDBFRowSyntax property
- CallResultSQL::CallResult
Detailed status of the result of the call.
- ColumnCountNumeric
Default = 0. The number of columns in the result set.
- ColumnInfoSQL::DataTypeInfo[]
An array of SQL::DataTypeInfo column descriptions.
- CurrentRowSQL::Row
Returns the current row as an object.
- CurrentRowIndexNumeric
Default = 0. The number of the current row.
- DBFRowSyntaxCharacter
Default = "". The syntax required to create an Alpha Anywhere .DBF table with the same columns.
- RowCountNumeric
Default = 0. The number of rows in the result set. -1 If not known. Do not rely on this value, as not all drivers support it. Walk the ResultSet with .NextRow() instead.
- SizeToFitLogical
When set to true, DBFRowSyntax will return lengths adjusted based on the actual data.
Notes:
1. Call UpdateStatistics before getting the DBFRowSyntax.
2. If the longest column is zero length, the default length is 15.
Size to fit will limit the size of inserted or updated fields on imported or linked tables to the maximum size of the previous values.
- StreamingModeLogical
When set to true, fetches will NOT populate internal data values.
Notes:
1. This is an advanced feature and should be used only in combination with streaming functions such as ToString and ToOpenTable to turn off autofetching of values.
2. Many of the streaming functions will reset the value of this property to false after completion. Set this property before calling any function that requires it to be set to .t.
See "Using the StreamingMode property" for more information.
- TableInfoSQL::TableInfo[]
Not always available. An array of SQL::TableInfo table descriptions returned by the query.
- TableInfoCountNumeric
The number of elements in .TableInfo.
- QuerySourceCharacter
QuerySource property
- QueryArgumentsCharacter
QueryArguments property
Methods
- ColumnNumber Method
Get the number of the column named.
- Data Method
Get the data for the column name or index specified.
- DataAsGeography Method
Takes data retrieved from a database and returns a .NET Geography object.
- DataIsNull Method
Determine whether a given element is Null.
- ExecutePostProcess Method
Execute portable SQL against a SQL::ResultSet, Allows for filtering after fetching a result set.
- FetchPage Method
Fetch a block of one or more rows into a local cache table. Note: This function is an advanced user feature and requires some understanding of caching for SQL.
- FormatData Method
Format the data for the column name, index or definition specified.
- GoToRow Method
Position to the row requested (backward movement is not supported by all databases).
- NextResult Method
Position to the next set of rows in the ResultSet (applies only when multiple results are returned).
- NextRow Method
The NextRow() method fetches the next row in the SQL::ResultSet.
- ToCSV Method
Convert a ResultSet to Comma Separated Variable format.
- ToCSVFile Method
Write a ResultSet to a file in Comma Separated Variable (CSV) format.
- ToDBF Method
Create a local copy of the result set in a .DBF table
- ToExcel Method
Convert ResultSet to an Excel 2003 format (.xls) or 2007 format (.xlsx) file.
- ToFormattedString Method
Copy the ResultSet to a string.
- ToGridComponentDataObject Method
Convert the ResultSet to a Grid Component DataObject data and field arrays.
- ToJSON Method
Convert a ResultSet to a JSON formatted string.
- ToJSONFile Method
Convert a ResultSet to JSON object and store in TargetFile
- ToJSONObjectSyntax Method
Convert a ResultSet to JSON object syntax.
- ToOpenTable Method
Fetch data from a result set to an open .DBF table
- ToPropertyArray Method
Convert the ResultSet to a property array.
- ToString Method
Copy the ResultSet to a string.
- ToTableInfo Method
Return the column definitions as a single SQL::TableInfo.
- ToXML Method
Convert ResultSet an XML formatted string.
See Also