Class luasql.exasol.Cursor
This class represents a cursor that allows retrieving rows from a result set.
Local Functions
luasql.exasol.cursor.col_index_provider(col_index) | This result table index provider returns the column index. |
luasql.exasol.cursor.create_col_name_provider(column_names) | This function creates a result table index provider that returns the column name. |
luasql.exasol.cursor.get_column_names(result_set) | This function extracts the column names from a result set. |
luasql.exasol.cursor.get_column_types(result_set) | Extracts the column types from a result set. |
Methods
luasql.exasol.cursor:create(connection_properties, websocket, session_id, result_set) | Create a new instance of the Cursor class. |
luasql.exasol.cursor:_get_result_table_index_provider(modestring) | Gets a result table index provider for the given fetch mode. |
luasql.exasol.cursor:_fill_row(table, modestring) | Fills the given table with the values of the current row. |
luasql.exasol.cursor:fetch(table, modestring) | Retrieves the next row of results. |
luasql.exasol.cursor:getcolnames() | Gets the list of column names. |
luasql.exasol.cursor:getcoltypes() | Gets the list of column types. |
luasql.exasol.cursor:close() | Closes this cursor. |
Local Functions
Methods- luasql.exasol.cursor.col_index_provider(col_index) line 24
-
This result table index provider returns the column index.
This is used for fetch mode "n" (numeric indices in the result table).
To avoid creating a new function for each row we create this only once and re-use it.
Parameters:
- col_index number the column index
Returns:
-
number
the column index
- luasql.exasol.cursor.create_col_name_provider(column_names) line 33
-
This function creates a result table index provider that returns the column name.
This is used for fetch mode "a" (alphanumeric indices in the result table).
To avoid creating a new function for each row we create this only once in the constructor and re-use it.
Parameters:
- column_names table a list of column names
Returns:
-
function
result table index provider that maps the column index to column names
- luasql.exasol.cursor.get_column_names(result_set) line 43
-
This function extracts the column names from a result set.
Parameters:
- result_set table the result set
Returns:
-
table
a list of column names
Raises:
an error if the number of columns is not equal to the number reported by the result set - luasql.exasol.cursor.get_column_types(result_set) line 59
-
Extracts the column types from a result set.
Parameters:
- result_set table the result set
Returns:
-
table
a list of column types
Methods
- luasql.exasol.cursor:create(connection_properties, websocket, session_id, result_set) line 75
-
Create a new instance of the Cursor class.
Parameters:
- connection_properties luasql.exasol.ConnectionProperties connection properties
- websocket luasql.exasol.ExasolWebsocket the websocket connection to the database
- session_id string the session ID of the current database connection
- result_set table the result set returned by the database
Returns:
-
luasql.exasol.Cursor
a new Cursor instance
Raises:
an error in case the result set is invalid, e.g. the number of columns or rows is inconsistent - luasql.exasol.cursor:_get_result_table_index_provider(modestring) line 99
-
Gets a result table index provider for the given fetch mode.
Parameters:
- modestring
"a" or "n"
the fetch mode:
"a"
for alphanumeric indices,"n"
for numeric indices
Returns:
-
function
a function that maps column indices to a table index
in the result table
- modestring
"a" or "n"
the fetch mode:
- luasql.exasol.cursor:_fill_row(table, modestring) line 111
-
Fills the given table with the values of the current row.
Parameters:
- table table the table to fill
- modestring
"a" or "n"
determines which indices are used when filling the table:
"a"
for alphanumeric indices,"n"
for numeric indices
- luasql.exasol.cursor:fetch(table, modestring) line 147
-
Retrieves the next row of results.
If fetch is called without parameters, the results will be returned directly to the caller.
If fetch is called with a table, the results will be copied into the table and the changed table will be returned.
In this case, an optional modestring parameter can be used. It is a string indicating how the resulting table
should be constructed. The mode string can contain:
"n"
: the resulting table will have numerical indices (default)"a"
: the resulting table will have alphanumerical indices
The numerical indices are the positions of the result columns in the
SELECT
statement; the alphanumerical indices are the names of the fields.The optional table parameter is a table that should be used to store the next row. This allows the use of a single table for many fetches, which can improve the overall performance.
A call to fetch after the last row has already being returned, will close the corresponding cursor. The result values are converted to Lua types, i.e.
nil
, number and string.Null values from the database are converted
luasql.exasol.NULL
. You can test for it withvalue == luasql.exasol.NULL
.Parameters:
- table
table or nil
the table to which the result will be copied or
nil
to return a new table - modestring nil, "a" or "n" the mode as described above
Returns:
-
table or nil
row data as described above or
nil
if there are no more rows - luasql.exasol.cursor:getcolnames() line 168
-
Gets the list of column names.
Returns:
-
table
the list of column names
- luasql.exasol.cursor:getcoltypes() line 175
-
Gets the list of column types.
Returns:
-
table
the list of column types
- luasql.exasol.cursor:close() line 182
-
Closes this cursor.
Returns:
-
boolean
true
in case of success andfalse
when the cursor is already closed