Rogue Wave Views Data Access Package API Reference Guide |
Rogue Wave Views Documentation Home |
Database access class. More...
#include <ilviews/dataccess/dbms/cursor.h>
Public Member Functions | |
IlInt | defineParam (const char *paramName, const IliDatatype *type) |
Defines a parameter. More... | |
IlBoolean | errorRaised () const |
Indicates if the last call to one of the select() , execute() , parse() , or fetchNext() member functions failed. More... | |
IlBoolean | execute (const char *stmt, IlInt *pRowCount=0) |
Executes a SQL statement. More... | |
IlBoolean | execute (IlInt *pRowCount=0) |
Executes a parsed SQL statement. More... | |
IlBoolean | fetchNext () |
Positions the cursor on the next row in the result set. More... | |
IliBinary | getBinaryValue (IlInt colno) const |
Returns a binary value. More... | |
IlInt | getBufferedRowsCount () const |
Returns the number of buffered rows. More... | |
IliDate | getDateValue (IlInt colno) const |
Returns a date value. More... | |
IlDouble | getDoubleValue (IlInt colno) const |
Returns a double value. More... | |
IliErrorMessage | getErrorMessage () const |
Returns the error message relative to the last call to one of the select() , execute() , parse() or fetchNext() member functions. More... | |
IlFloat | getFloatValue (IlInt colno) const |
Returns a float value. More... | |
IlInt | getIntegerValue (IlInt colno) const |
Returns an integer value. More... | |
IlBoolean | getOutputParam (IlInt paramno, IliValue &val) const |
Retrieves the value of the output parameter. More... | |
IlInt | getParamIndex (const char *paramName) const |
Returns the position of the defined parameter. More... | |
const char * | getParsedStatement () const |
Returns the SQL statement that has been successfully parsed. More... | |
const IliSchema * | getSchema () const |
Returns the schema of the current result set. More... | |
IliSQLSession & | getSQLSession () const |
Returns the IliSQLSession which the cursor belongs to. More... | |
const char * | getStringValue (IlInt colno) const |
Returns a string value. More... | |
IlBoolean | getValue (IlInt colno, IliValue &val) |
Returns a value. More... | |
IlBoolean | hasTuple () const |
Indicates if the cursor is currently positioned on a valid row in the result set. More... | |
IlBoolean | isNull (IlInt colno) const |
Indicates if the value is null. More... | |
IlBoolean | parse (const char *stmt, IlBoolean useBoundVars=IlTrue) |
Parses an SQL statement for future execution. More... | |
IlBoolean | select (const char *stmt) |
Executes a SQL SELECT statement. More... | |
IlBoolean | select () |
Executes a parsed SQL SELECT statement. More... | |
IlBoolean | setBufferedRowsCount (IlInt count) |
Sets the number of buffered rows. More... | |
IlBoolean | setParam (IlInt paramno, const IliValue &val) |
Sets the value of the parameter. More... | |
Public Member Functions inherited from IliRefCounted | |
IlInt | getRefCount () const |
Returns the reference count of the object. Initially, this property is set to 0 . More... | |
void | lock () const |
Increments the reference count of the object. | |
void | unLock () const |
Decrements the reference count of the object. More... | |
Friends | |
class | IliSQLSession |
Additional Inherited Members | |
Protected Member Functions inherited from IliRefCounted | |
virtual | ~IliRefCounted () |
This is the virtual destructor of the IliRefCounted class. More... | |
Database access class.
Library: dbaccess
The IliSQLCursor
class allows you to submit SQL statements to a database and to retrieve any result sets produced by these statements. Before you can use an IliSQLCursor
object, you must have an IliSQLSession
object that is connected to a database.
About Parsing and Executing
An alternative way to submit an SQL statement to a database is to request that an SQL statement is parsed before being executed any number of times. Although this technique is a little more sophisticated, it provides some added benefits. Firstly, if an SQL statement is to be submitted more than once, it reduces the overall processing time: the parsing of the statement is only done once. Secondly, it allows the use of SQL statements containing parameters.
A parameter is an identifier prefixed by a colon (for example, :name
) that appears in the text of an SQL statement instead of a literal value. It may be considered as a kind of variable. A statement containing parameters can be parsed, when values can be specified for the parameters, and then executed.
Once a statement has been parsed, it can be executed any number of times, each time with a different set of values for the parameters.
About result set
Once an SQL SELECT
statement has been successfully executed using one of the two select()
member functions, it leaves a result set available for inspection through the cursor. A result set is an ordered collection of rows. Each of these rows conforms to the same schema.
At any given point in time, the cursor is positioned either before the first row, on a row, or after the last row. At the beginning of the inspection process, just after one of the select()
member functions has been called, the cursor is positioned before the first row. Each call to the fetchNext()
member function moves the cursor to the next row. When all rows have been seen, a call to fetchNext()
positions the cursor after the last row. The hasTuple()
member function can be called to determine if the cursor is positioned on a row (as opposed to being positioned before the first row or after the last row).
About values
Once the cursor is positioned on a valid row, the member functions in this section can be used to retrieve the values of the columns of the row. A column is identified by its position in the schema of the result set, starting from 0
.
IliDatatype
, IliErrorMessage
, IliSchema
, IliSQLSession
, IliValue
.Accessors provide a scriptable and uniform way to inspect and modify an object by using its base class methods IlvValueInterface::queryValue()
, IlvValueInterface::queryValues()
, IlvValueInterface::changeValue()
, IlvValueInterface::changeValues()
. This class defines the following accessors:
Name | Type | Equivalent methods |
---|---|---|
bufferedRowsCount | Int | getBufferedRowsCount() , setBufferedRowsCount() |
columnsCount | Int | getSchema()->getColumnsCount() |
lastExecuteRowsCount | Int | See [lastExecuteRowsCount] below. |
sqlSession | IliSQLSession | getSQLSession() |
[lastExecuteRowsCount] Contains the number of database rows that were affected by the last non SELECT
SQL statement submitted. This is typically useful with SQL UPDATE
and DELETE
statements.
Name | Return type | Equivalent methods |
---|---|---|
execute(String statement) | Boolean | execute(statement) |
fetchNext() | Boolean | fetchNext() |
getColumn(String name) | Object | See [getColumn] below. |
getColumnAt(Int index) | Object | See [getColumn] below. |
getErrorMessage() | IliErrorMessage | getErrorMessage() |
hasTuple() | Boolean | hasTuple() |
isErrorRaised() | Boolean | errorRaised() |
select(String statement) | Boolean | select(statement) . See [select] below. |
[getColumn] Returns the column named name or at position index in the result set produced by the last SQL statement submitted. Returns null
if no such column exists, if there is no current result set, or if there is no current row.
Note that since the result set columns become properties of the IliSQLCursor
object, they can be directly accessed. For example:
[select] Here is an example in Rogue Wave Views Script, omitting error checking:
IlInt IliSQLCursor::defineParam | ( | const char * | paramName, |
const IliDatatype * | type | ||
) |
Defines a parameter.
This member function must be called exactly once for each parameter in the SQL statement that has been parsed. All defined parameters are lost the next time one of the parse()
, select(const char*)
, or execute(const char*, IlInt*)
member functions is called. Initially, the parameter value is set to 0
.
paramName | The parameter name, that must not include the colon prefix. |
type | The parameter type. |
IlBoolean IliSQLCursor::errorRaised | ( | ) | const |
Indicates if the last call to one of the select()
, execute()
, parse()
, or fetchNext()
member functions failed.
You can use the ForwardErrorToGlobalSink()
function of the IliSQLSession
class to forward the error to the global error sink.
IlTrue if the last call to one of the
select(),
execute(),
parse(), or
fetchNext()` member functions failed. In this case, an error message is available through the getErrorMessage()
member function. Executes a SQL statement.
stmt | Any SQL statement except the SQL SELECT statement. |
pRowCount | If not 0 , it will receive the number of rows affected by the execution of the statement, when applicable. |
IlTrue
if successful. Executes a parsed SQL statement.
It may be called for any SQL statement except the SQL SELECT
statement. This member function can be called any number of times as long as the SQL statement remains parsed.
pRowCount | If not 0 , it will receive the number of rows affected by the execution of the statement, when applicable. |
IlTrue
if successful. IlBoolean IliSQLCursor::fetchNext | ( | ) |
Positions the cursor on the next row in the result set.
IlTrue
if successful. To determine if the result has been exhausted, you can call the hasTuple()
member function. Returns a binary value.
colno | The value position. |
IliBinary
object. IlInt IliSQLCursor::getBufferedRowsCount | ( | ) | const |
Returns the number of buffered rows.
1
, which means that each call to fetchNext()
requests one row from the database API. Setting the value of this property to N, where N > 1, has the effect that the first call to fetchNext()
will request N
rows at once from the database API. The N-1 succeeding calls to fetchNext()
will simply move a mark into an internal buffer where all N rows are stored. The N+1 call to fetchNext()
will then request the next N rows, and so on. Returns a date value.
colno | The value position. |
IliDate
object. Returns a double value.
colno | The value position. |
0.0
. IliErrorMessage IliSQLCursor::getErrorMessage | ( | ) | const |
Returns the error message relative to the last call to one of the select()
, execute()
, parse()
or fetchNext()
member functions.
You can use the ForwardErrorToGlobalSink()
function of the IliSQLSession
class to forward the error to the global error sink.
select()
, execute()
, parse()
or fetchNext()
member functions. Returns a float value.
colno | The value position. |
0.0
. Returns an integer value.
colno | The value position. |
0
. Retrieves the value of the output parameter.
paramno | The parameter position returned by one of the defineParam() or getParamIndex() member functions. |
val | The value. |
IlTrue
if successful. IlInt IliSQLCursor::getParamIndex | ( | const char * | paramName | ) | const |
Returns the position of the defined parameter.
paramName | The parameter name, it should not include the colon prefix. |
-1
if no such parameter is defined. const char* IliSQLCursor::getParsedStatement | ( | ) | const |
Returns the SQL statement that has been successfully parsed.
0
if no parsed statement is active. const IliSchema* IliSQLCursor::getSchema | ( | ) | const |
Returns the schema of the current result set.
IliSQLSession& IliSQLCursor::getSQLSession | ( | ) | const |
Returns the IliSQLSession
which the cursor belongs to.
IliSQLSession
which the cursor belongs to. const char* IliSQLCursor::getStringValue | ( | IlInt | colno | ) | const |
Returns a string value.
colno | The value position. |
0
. Returns a value.
colno | The value position. |
val | The value. |
IlTrue
if successful. IlBoolean IliSQLCursor::hasTuple | ( | ) | const |
Indicates if the cursor is currently positioned on a valid row in the result set.
IlTrue
if the cursor is currently positioned on a valid row in the result set. If this is the case, you can call any of the member functions described in the next section to inspect the values of the current row. Indicates if the value is null.
colno | The value position. |
IlTrue
if the value is null. Parses an SQL statement for future execution.
Once an SQL statement has been successfully parsed, it can be executed any number of times. The effects of parsing a statement will be lost if, later on, one of the parse()
, select(const char*)
, or execute(const char*, IlInt*)
member functions is called.
After calling this member function, you should call the defineParam()
member function for each parameter that appears in the statement.
stmt | The SQL statement. |
useBoundVars | Reserved for future use and must always be set to IlTrue . |
IlTrue
if successful. IlBoolean IliSQLCursor::select | ( | const char * | stmt | ) |
Executes a SQL SELECT
statement.
The result set of the SQL SELECT
execution statement can be inspected with the fetchNext()
member function. Note that the result set will remain available until the next call to one of the execute()
, select()
or parse()
member functions.
stmt | The SQL statement. |
IlTrue
if successful. IlBoolean IliSQLCursor::select | ( | ) |
Executes a parsed SQL SELECT
statement.
The result set of the SQL SELECT
statement execution can be inspected by the fetchNext()
member function. Note that the result set will remain available until the next call to one of the execute()
, select()
, or parse()
member functions.
This member function can be called any number of times as long as the SQL SELECT
statement remains parsed.
IlTrue
if successful. Sets the number of buffered rows.
count | The count. |
Sets the value of the parameter.
paramno | The parameter position returned by one of the defineParam() or getParamIndex() member functions. It should not be confused with the position of the parameter in the SQL statement. |
val | The value. The type of the value must be the same as the type that was specified when the defineParam() member function was called. |
IlTrue
if successful. © Copyright 2018, Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave is a registered trademark of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.