Main Page | Class List | Class Members | Related Pages

SqlResult Class Reference

Helper class for the statement handle hstmt. More...

List of all members.

Public Member Functions

public OdbcEnvironment environment ()
 The parent connections environment.
public OdbcConnection connection ()
 The parent connection.
public HSTMT handle ()
 The underlying hstmt for operations not provided by this class.
public void prepare (char[] query)
 Prepares a SQL statement for later execution.
public void setInput (int num, long param, int paramType=SQL_BIGINT)
 Sets an input parameter for a prepared statement.
public void setInput (int num, int param, int paramType=SQL_INTEGER)
 Sets an input parameter for a prepared statement.
public void setInput (int num, short param, int paramType=SQL_SMALLINT)
 Sets an input parameter for a prepared statement.
public void setInput (int num, double param, int paramType=SQL_DOUBLE)
 Sets an input parameter for a prepared statement.
public void setInput (int num, float param, int paramType=SQL_REAL)
 Sets an input parameter for a prepared statement.
public void setInput (int num, char[] param, int paramType=SQL_VARCHAR, int bufLen=0)
 Sets an input parameter for a prepared statement.
public void setInputw (int num, wchar[] param, int paramType=SQL_WVARCHAR, int bufLen=0)
 Sets an input parameter for a prepared statement.
public void execute ()
 Executes a prepared statement for this result.
public void execDirect (char[] sql)
 Executes a query for this result.
public uint columnCount ()
 Column count - 0 for not row source type results.
public char[][] columns ()
 Array of column names, sorted by column index.
public ColumnSpec * columnSpec (char[] column)
 Column attributes specification.
public ColumnSpec * columnSpec (uint col)
 Column attributes specification.
public void setBinding (uint col, int dType)
 Sets the binding for a column.
public void setBinding (char[] column, int dType)
 Sets the binding for a column identified by column name.
public void setBinding (int dType)
 Sets the binding for all columns.
public void setTargetC (uint col, SQLINTEGER targetType)
 Sets the target c type for a column.
public bit fetch ()
 Fetches the next row into the buffer.
public bit isNull (uint col)
 Returns true if the column contains a NULL value.
public bit isNull (char[] column)
 Returns true if the column contains a NULL value.
public alias value_char (D_CHAR, char).val string
 char[] string(int col); char[] string(char[] column);
public alias value_char (D_WCHAR, wchar).val wstring
 wchar[] wstring(int col); wchar[] wstring(char[] column);
public alias value (D_LONG, long).val vlong
 long vlong(int col); long vlong(char[] column);
public alias value (D_INT, int).val vint
 int vint(int col); int vint(char[] column);
public alias value (D_SHORT, short).val vshort
 short vshort(int col); short vshort(char[] column);
public alias value (D_DOUBLE, double).val vdouble
 double vdouble(int col); double vdouble(char[] column);
public alias value (D_FLOAT, float).val vfloat
 float vfloat(int col); float vfloat(char[] column);
public char * stringz (int col)
 Returns a null terminated c string from the buffer.
public char * stringz (char[] column)
 Returns a null terminated c string from the buffer.
public void rawBuffer (in int col, out SQLPOINTER TargetValuePtr, out SQLINTEGER *StrLen_or_IndPtr)
 Returns a pointer to the buffer bound to a column.
public alias values_char (D_CHAR, char).cvals strings
 char[][int] strings() - Returns an indexed associative array from the current row.
public alias values_char (D_CHAR, char).fvals stringsN
 char[][char[]] stringsN() - Returns a named associative array from the current row.
public alias values_char (D_WCHAR, wchar).cvals wstrings
 wchar[][int] wstrings(); wchar[][char[]] wstringsN()
public alias values (D_LONG, long).cvals vlongs
 long[int] vlongs(); long[char[]] vlongsN()
public alias values (D_INT, int).cvals vints
 int[int] vints(); int[char[]] vintsN()
public alias values (D_SHORT, short).cvals vshorts
 short[int] vshorts(), short[char[]] vshortsN()
public alias values (D_DOUBLE, double).cvals vdoubles
 double[int] vdoubles(); double[char[]] vdoublesN()
public alias values (D_DOUBLE, float).cvals vfloats
 float[int] vfloats(), float[char[]] vfloatsN()
public alias getData_char (wchar, SQL_C_WCHAR).get wstringData
 wstringData(int col); wstringData(char[] column) Retrieves a wstring data value from an unbound column
public alias getData_char (char, SQL_C_CHAR).get stringData
 stringData(int col); stringData(char[] column) Retrieves a string data value from an unbound column
public alias getData (long, SQL_C_LONG).get longData
 longData(int col); longData(char[] column) Retrieves a long data value from an unbound column
public alias getData (int, SQL_C_SHORT).get intData
 intData(int col); intData(char[] column) Retrieves a int data value from an unbound column
public alias getData (short, SQL_C_SHORT).get shortData
 shortData(int col); shortData(char[] column) Retrieves a short data value from an unbound column
public void close ()
 Closes the result. The result can be reexecuted with a new sql statement.
public void free ()
 Deletes this object.

Public Attributes

public OdbcMessage lastMessage
 Diagnostics message from the last odbc call that returned SQL_SUCCESS_WITH_INFO.
public RETCODE lastRetcode
 Return code from the last API call.
public bit bindAll = true
 Read/write: Automatic column binding.


Detailed Description

Helper class for the statement handle hstmt.


Member Function Documentation

public OdbcEnvironment SqlResult.environment  ) 
 

The parent connections environment.

shortcut for result.connection().environment()

public void SqlResult.setInput int  num,
long  param,
int  paramType = SQL_BIGINT
 

Sets an input parameter for a prepared statement.

Parameter index numbers start at 0 for the leftmost parameter.

public void SqlResult.setInput int  num,
int  param,
int  paramType = SQL_INTEGER
 

Sets an input parameter for a prepared statement.

Parameter index numbers start at 0 for the leftmost parameter.

public void SqlResult.setInput int  num,
short  param,
int  paramType = SQL_SMALLINT
 

Sets an input parameter for a prepared statement.

Parameter index numbers start at 0 for the leftmost parameter.

public void SqlResult.setInput int  num,
double  param,
int  paramType = SQL_DOUBLE
 

Sets an input parameter for a prepared statement.

Parameter index numbers start at 0 for the leftmost parameter.

public void SqlResult.setInput int  num,
float  param,
int  paramType = SQL_REAL
 

Sets an input parameter for a prepared statement.

Parameter index numbers start at 0 for the leftmost parameter.

public void SqlResult.setInput int  num,
char[]  param,
int  paramType = SQL_VARCHAR,
int  bufLen = 0
 

Sets an input parameter for a prepared statement.

Parameter index numbers start at 0 for the leftmost parameter.

public void SqlResult.setInputw int  num,
wchar[]  param,
int  paramType = SQL_WVARCHAR,
int  bufLen = 0
 

Sets an input parameter for a prepared statement.

Parameter index numbers start at 0 for the leftmost parameter.

This function is called setInputw, otherwise the compiler complains about ambiguous overload with setInput(... char[] ...)

public void SqlResult.execute  ) 
 

Executes a prepared statement for this result.

Warning:
If the result was bound to a previous query, all resources related to that query will be freed For instance, a buffer retrieved with rawBuffer will be freed.

public void SqlResult.execDirect char[]  sql  ) 
 

Executes a query for this result.

Warning:
If the result was bound to a previous query, all resources related to that query will be freed For instance, a buffer retrieved with rawBuffer will be freed.

public uint SqlResult.columnCount  ) 
 

Column count - 0 for not row source type results.

Number of columns in the result. If the the query didn't produce a row source, columnCount returns 0.

Column index starts at 0 with the leftmost column.

public char [][] SqlResult.columns  ) 
 

Array of column names, sorted by column index.

An array of strings holding the column names. 0 is the leftmost column, length-1 the rightmost.

public ColumnSpec* SqlResult.columnSpec char[]  column  ) 
 

Column attributes specification.

This returns a struct holding information aboute a single column:

  • .name - name of the column (char[])
  • .type - column type (char[])
  • .csize - size of the column data (ushort)
  • .digits - (ushort)
  • .nullable - (ushort)
  • .numericType - (ushort)

public ColumnSpec* SqlResult.columnSpec uint  col  ) 
 

Column attributes specification.

public void SqlResult.setBinding uint  col,
int  dType
 

Sets the binding for a column.

Valid parameters:

		 SqlResult.D_LONG
		 SqlResult.D_INT
		 SqlResult.D_SHORT

		 SqlResult.D_DOUBLE
		 SqlResult.D_FLOAT

		 SqlResult.D_WCHAR
		 SqlResult.D_CHAR

		 SqlResult.UNBOUND
	 

This function sets the binding target type for a column or for all columns, but it doesn't actually bind the columns. The columns are bound on the first call to fetch().

Every D type is mapped to a predefined target C type. Some target types can be extracted with the value functions.

D_LONG = SQL_C_SBIGINT result.vlong(col) D_INT = SQL_C_SLONG result.vint(col) D_SHORT = SQL_C_SSHORT result.vshort(col) D_DOUBLE = SQL_C_DOUBLE result.vdouble(col) D_FLOAT = SQL_C_FLOAT result.vfloat(col) D_CHAR = SQL_C_CHAR result.string(col) result.stringz(col) D_WCHAR = SQL_C_WCHAR result.wstring(col)

Default target types for column bindings are the default target types from the ODBC specs with the following exceptions:

 		SQL_BIGINT:         D_LONG (SQL_C_SBIGINT) - odbc default is SQL_C_CHAR
		SQL_TYPE_DATE:      D_CHAR (SQL_C_CHAR)
		SQL_TYPE_TIME:      D_CHAR (SQL_C_CHAR)
		SQL_TYPE_TIMESTAMP: D_CHAR (SQL_C_CHAR)
	 

SqlResult.UNBOUND causes the column not to be bound.

Note:
If bindAll is true, all columns set to UNBOUND will be set to their default types on the first fetch. After the first fetch, a column set to UNBOUND stays unbound even if bindAll is true.
If the column is already bound it will be unbound.
Warning:
Allocated buffer for the column will be freed.

public void SqlResult.setTargetC uint  col,
SQLINTEGER  targetType
 

Sets the target c type for a column.

This function can be called on any individual column to set it's target c type.

Valid arguments are the SQL_C_* constants.

public bit SqlResult.fetch  ) 
 

Fetches the next row into the buffer.

Returns true if there was a new row to fetch, false otherwise.

public alias SqlResult.value_char D_CHAR  ,
char 
 

char[] string(int col); char[] string(char[] column);

Retrieves a column value as a string.

The value functions attempt to retrieve the buffer for a column into each function's return type.

In contract:

If the c target type is incompatible, an Exception is thrown.

See d type to sql c type mapping under setBinding()

public void SqlResult.rawBuffer in int  col,
out SQLPOINTER  TargetValuePtr,
out SQLINTEGER *  StrLen_or_IndPtr
 

Returns a pointer to the buffer bound to a column.

SQLPOINTER TargetValuePtr points to the raw buffer. The buffer is not copied. SQLINTEGER* StrLen_or_IndPtr points to the string length or indication buffer

The buffer pointers remain valid after a new fetch, containing the new values.

Warning:
The buffer and the integer are malloc'd and will be free'd by the result object's destructor or after a call to setBinding for this column.

public alias SqlResult.values_char D_CHAR  ,
char 
 

char[][int] strings() - Returns an indexed associative array from the current row.

Returns an associative array of all compatible columns of the current row. The index is the column index. Missing indexes are of incompatible type.

public alias SqlResult.values_char D_CHAR  ,
char 
 

char[][char[]] stringsN() - Returns a named associative array from the current row.

Returns an associative array of all compatible columns of the current row. The index is the column name. Missing column names are of incompatible type.


Member Data Documentation

public RETCODE SqlResult.lastRetcode
 

Return code from the last API call.

If this is set to SQL_SUCCESS_WITH_INFO, the info message is available in lastMessage.

public bit SqlResult.bindAll = true
 

Read/write: Automatic column binding.

This value is used by the class internally on the first fetch call after a new query.

On the first fetch, if bindAll is true, all columns will be bound. Columns not defined by setBinding will be bound to a default target type.

If bindAll is false, only those columns defined with the setBinding functions will be bound. All other columns will remain unbound.

Changes to this value won't be in effect between subsequent fetch'es after the first fetch

Closing the result or executing a new query resets this value to true. The bindAll behaviour must be set between the query execution and the first call to fetch.

Default of bindAll is true.


Generated on Tue Sep 21 00:33:13 2004 for Simple Database Objects by doxygen 1.3.8