class SQLRCursor
Public Class Methods
Creates a cursor to run queries and fetch result sets using connection “connection”
static VALUE sqlrcur_new(VALUE self, VALUE connection) { sqlrconnection *sqlrcon; Data_Get_Struct(connection,sqlrconnection,sqlrcon); sqlrcursor *sqlrcur=new sqlrcursor(sqlrcon,true); sqlrcursordata *curdata=new sqlrcursordata; curdata->cur=sqlrcur; curdata->con=connection; return Data_Wrap_Struct(self,sqlrcur_mark,sqlrcur_free,(void *)curdata); }
Public Instance Methods
Returns the number of rows that were updated, inserted or deleted by the query. Not all databases support this call. Don’t use it for applications which are designed to be portable across databases. -1 is returned by databases which don’t support this option.
static VALUE sqlrcur_affectedRows(VALUE self) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u64r,sqlrcurdata->cur,affectedRows); return INT2NUM(result); }
Sets query caching off.
static VALUE sqlrcur_cacheOff(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,cacheOff); return Qnil; }
Sets query caching on. Future queries will be cached to the file “filename”.
A default time-to-live of 10 minutes is also set.
Note that once cacheToFile() is called, the result sets of all future queries will be cached to that file until another call to cacheToFile() changes which file to cache to or a call to cacheOff() turns off caching.
static VALUE sqlrcur_cacheToFile(VALUE self, VALUE filename) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,cacheToFile,filename); return Qnil; }
Clears all bind variables.
static VALUE sqlrcur_clearBinds(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,clearBinds); return Qnil; }
Closes the current result set, if one is open. Data that has been fetched already is still available but no more data may be fetched. Server side resources for the result set are freed as well.
static VALUE sqlrcur_closeResultSet(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,closeResultSet); return Qnil; }
Returns the number of columns in the current result set.
static VALUE sqlrcur_colCount(VALUE self) { sqlrcursordata *sqlrcurdata; uint32_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u32r,sqlrcurdata->cur,colCount); return INT2NUM(result); }
Parses the previously prepared query, counts the number of bind variables defined in it and returns that number.
static VALUE sqlrcur_countBindVariables(VALUE self) { sqlrcursordata *sqlrcurdata; uint16_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u16r,sqlrcurdata->cur,countBindVariables); return INT2NUM(result); }
Defines a binary lob output bind variable
static VALUE sqlrcur_defineOutputBindBlob(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,defineOutputBindBlob,variable); return Qnil; }
Defines a character lob output bind variable
static VALUE sqlrcur_defineOutputBindClob(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,defineOutputBindClob,variable); return Qnil; }
Defines a cursor output bind variable
static VALUE sqlrcur_defineOutputBindCursor(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,defineOutputBindCursor,variable); return Qnil; }
Defines an decimal output bind variable.
static VALUE sqlrcur_defineOutputBindDouble(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,defineOutputBindDouble,variable); return Qnil; }
Defines an integer output bind variable.
static VALUE sqlrcur_defineOutputBindInteger(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,defineOutputBindInteger,variable); return Qnil; }
Defines a string output bind variable. “length” bytes will be reserved to store the value.
static VALUE sqlrcur_defineOutputBindString(VALUE self, VALUE variable, VALUE bufferlength) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR2(sqlrcurdata->cur,defineOutputBindString,variable,bufferlength); return Qnil; }
Tells the server not to send any column info (names, types, sizes). If you don’t need that info, you should call this function to improve performance.
static VALUE sqlrcur_dontGetColumnInfo(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,dontGetColumnInfo); return Qnil; }
Returns 0 if part of the result set is still pending on the server and 1 if not. This function can only return 0 if setResultSetBufferSize() has been called with a parameter other than 0.
static VALUE sqlrcur_endOfResultSet(VALUE self) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,br,sqlrcurdata->cur,endOfResultSet); return INT2NUM(result); }
If a query failed and generated an error, the error message is available here. If the query succeeded then this function returns a nil.
static VALUE sqlrcur_errorMessage(VALUE self) { sqlrcursordata *sqlrcurdata; const char *result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,ccpr,sqlrcurdata->cur,curErrorMessage); if (result) { return rb_str_new2(result); } else { return Qnil; } }
If a query failed and generated an error, the error number is available here. If there is no error then this method returns 0.
static VALUE sqlrcur_errorNumber(VALUE self) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u64r,sqlrcurdata->cur,curErrorNumber); return INT2NUM(result); }
Execute the query that was previously prepared and bound.
static VALUE sqlrcur_executeQuery(VALUE self) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,br,sqlrcurdata->cur,executeQuery); return INT2NUM(result); }
Fetch from a cursor that was returned as an output bind variable.
static VALUE sqlrcur_fetchFromBindCursor(VALUE self) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,br,sqlrcurdata->cur,fetchFromBindCursor); return INT2NUM(result); }
Returns the index of the first buffered row. This is useful when buffering only part of the result set at a time.
static VALUE sqlrcur_firstRowIndex(VALUE self) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u64r,sqlrcurdata->cur,firstRowIndex); return INT2NUM(result); }
Returns the name of the file containing the most recently cached result set.
static VALUE sqlrcur_getCacheFileName(VALUE self) { sqlrcursordata *sqlrcurdata; const char *result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,ccpr,sqlrcurdata->cur,getCacheFileName); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Tells the server to send column info.
static VALUE sqlrcur_getColumnInfo(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,getColumnInfo); return Qnil; }
Returns 1 if the specified column auto-increments and 0 otherwise. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnIsAutoIncrement(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,br,sqlrcurdata->cur,getColumnIsAutoIncrementStr,col); } else { RCUR1(result,br,sqlrcurdata->cur,getColumnIsAutoIncrementInt,col); } return INT2NUM(result); }
Returns 1 if the specified column contains binary data and 0 otherwise. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnIsBinary(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,br,sqlrcurdata->cur,getColumnIsBinaryStr,col); } else { RCUR1(result,br,sqlrcurdata->cur,getColumnIsBinaryInt,col); } return INT2NUM(result); }
Returns 1 if the specified column can contain nulls and 0 otherwise. “col” may be specified as the colum name or number.
static VALUE sqlrcur_getColumnIsNullable(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,br,sqlrcurdata->cur,getColumnIsNullableStr,col); } else { RCUR1(result,br,sqlrcurdata->cur,getColumnIsNullableInt,col); } return INT2NUM(result); }
Returns 1 if the specified column is part of a composite key and 0 otherwise. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnIsPartOfKey(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,br,sqlrcurdata->cur,getColumnIsPartOfKeyStr,col); } else { RCUR1(result,br,sqlrcurdata->cur,getColumnIsPartOfKeyInt,col); } return INT2NUM(result); }
Returns 1 if the specified column is a primary key and 0 otherwise. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnIsPrimaryKey(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,br,sqlrcurdata->cur,getColumnIsPrimaryKeyStr,col); } else { RCUR1(result,br,sqlrcurdata->cur,getColumnIsPrimaryKeyInt,col); } return INT2NUM(result); }
Returns 1 if the specified column is unique and 0 otherwise. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnIsUnique(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,br,sqlrcurdata->cur,getColumnIsUniqueStr,col); } else { RCUR1(result,br,sqlrcurdata->cur,getColumnIsUniqueInt,col); } return INT2NUM(result); }
Returns 1 if the specified column is an unsigned number and 0 otherwise. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnIsUnsigned(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,br,sqlrcurdata->cur,getColumnIsUnsignedStr,col); } else { RCUR1(result,br,sqlrcurdata->cur,getColumnIsUnsignedInt,col); } return INT2NUM(result); }
Returns 1 if the specified column was created with the zero-fill flag and 0 otherwise. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnIsZeroFilled(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,br,sqlrcurdata->cur,getColumnIsZeroFilledStr,col); } else { RCUR1(result,br,sqlrcurdata->cur,getColumnIsZeroFilledInt,col); } return INT2NUM(result); }
Returns the length of the specified column. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnLength(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; uint32_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,u32r,sqlrcurdata->cur,getColumnLengthStr,col); } else { RCUR1(result,u32r,sqlrcurdata->cur,getColumnLengthInt,col); } return INT2NUM(result); }
Sends a query that returns a list of columns in the table specified by the “table” parameter matching “wild”. If wild is empty or nil then a list of all columns will be returned.
static VALUE sqlrcur_getColumnList(VALUE self, VALUE table, VALUE wild) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR2(result,br,sqlrcurdata->cur,getColumnList,table,wild); return INT2NUM(result); }
Returns the name of the specified column.
static VALUE sqlrcur_getColumnName(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; const char *result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,ccpr,sqlrcurdata->cur,getColumnName,col); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Returns an array of the column names of the current result set.
static VALUE sqlrcur_getColumnNames(VALUE self) { sqlrcursordata *sqlrcurdata; sqlrcursor *sqlrcur; const char * const *result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); sqlrcur=sqlrcurdata->cur; RCUR(result,ccpcpr,sqlrcur,getColumnNames); if (!result) { return Qnil; } VALUE nameary=rb_ary_new2(sqlrcur->colCount()); for (uint32_t i=0; i<sqlrcur->colCount(); i++) { if (result[i]) { rb_ary_store(nameary,i,rb_str_new2(result[i])); } else { rb_ary_store(nameary,i,Qnil); } } return nameary; }
Returns the precision of the specified column. Precision is the total number of digits in a number. eg: 123.45 has a precision of 5. For non-numeric types, it’s the number of characters in the string. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnPrecision(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; uint32_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,u32r,sqlrcurdata->cur,getColumnPrecisionStr,col); } else { RCUR1(result,u32r,sqlrcurdata->cur,getColumnPrecisionInt,col); } return INT2NUM(result); }
Returns the scale of the specified column. Scale is the total number of digits to the right of the decimal point in a number. eg: 123.45 has a scale of 2. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnScale(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; uint32_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,u64r,sqlrcurdata->cur,getColumnScaleStr,col); } else { RCUR1(result,u64r,sqlrcurdata->cur,getColumnScaleInt,col); } return INT2NUM(result); }
Returns the type of the specified column. “col” may be specified as the column name or number.
static VALUE sqlrcur_getColumnType(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); const char *result; if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,ccpr,sqlrcurdata->cur,getColumnTypeStr,col); } else { RCUR1(result,ccpr,sqlrcurdata->cur,getColumnTypeInt,col); } if (result) { return rb_str_new2(result); } else { return Qnil; } }
Sends a query that returns a list of databases/schemas matching “wild”. If wild is empty or nil then a list of all databases/schemas will be returned.
static VALUE sqlrcur_getDatabaseList(VALUE self, VALUE wild) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,br,sqlrcurdata->cur,getDatabaseList,wild); return INT2NUM(result); }
Returns the specified field as a string. “col” may be specified as the column name or number.
static VALUE sqlrcur_getField(VALUE self, VALUE row, VALUE col) { sqlrcursordata *sqlrcurdata; const char *result; uint64_t length; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR2(result,ccpr,sqlrcurdata->cur,getFieldStr,row,col); RCUR2(length,u64r,sqlrcurdata->cur,getFieldLengthStr,row,col); } else { RCUR2(result,ccpr,sqlrcurdata->cur,getFieldInt,row,col); RCUR2(length,u64r,sqlrcurdata->cur,getFieldLengthInt,row,col); } if (result) { return rb_str_new(result,length); } else { return Qnil; } }
Returns the specified field as an decimal. “col” may be specified as the column name or number.
static VALUE sqlrcur_getFieldAsDouble(VALUE self, VALUE row, VALUE col) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); double result; if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR2(result,dr,sqlrcurdata->cur,getFieldAsDoubleStr,row,col); } else { RCUR2(result,dr,sqlrcurdata->cur,getFieldAsDoubleInt,row,col); } return rb_float_new(result); }
Returns the specified field as an integer. “col” may be specified as the column name or number.
static VALUE sqlrcur_getFieldAsInteger(VALUE self, VALUE row, VALUE col) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); int64_t result; if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR2(result,i64r,sqlrcurdata->cur,getFieldAsIntegerStr,row,col); } else { RCUR2(result,i64r,sqlrcurdata->cur,getFieldAsIntegerInt,row,col); } return INT2NUM(result); }
Returns the length of the specified row and column. “col” may be specified as the column name or number.
static VALUE sqlrcur_getFieldLength(VALUE self, VALUE row, VALUE col) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR2(result,u64r,sqlrcurdata->cur,getFieldLengthStr,row,col); } else { RCUR2(result,u64r,sqlrcurdata->cur,getFieldLengthInt,row,col); } return INT2NUM(result); }
Returns the length of the longest field in the specified column. “col” may be specified as the column name or number.
static VALUE sqlrcur_getLongest(VALUE self, VALUE col) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(col,rb_cString)==Qtrue) { RCUR1(result,u64r,sqlrcurdata->cur,getLongestStr,col); } else { RCUR1(result,u64r,sqlrcurdata->cur,getLongestInt,col); } return INT2NUM(result); }
Tells the connection to return NULL fields and output bind variables as empty strings. This is the default.
static VALUE sqlrcur_getNullsAsEmptyStrings(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,getNullsAsEmptyStrings); return Qnil; }
Tells the connection to return NULL fields and output bind variables as nil’s.
static VALUE sqlrcur_getNullsAsNils(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,getNullsAsNulls); return Qnil; }
Get the value stored in a previously defined binary lob output bind variable.
static VALUE sqlrcur_getOutputBindBlob(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; const char *result; uint64_t length; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,ccpr,sqlrcurdata->cur,getOutputBindBlob,variable); RCUR1(length,u64r,sqlrcurdata->cur,getOutputBindLength,variable); if (result) { return rb_str_new(result,length); } else { return Qnil; } }
Get the value stored in a previously defined character lob output bind variable.
static VALUE sqlrcur_getOutputBindClob(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; const char *result; long length; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,ccpr,sqlrcurdata->cur,getOutputBindClob,variable); RCUR1(length,u64r,sqlrcurdata->cur,getOutputBindLength,variable); if (result) { return rb_str_new(result,length); } else { return Qnil; } }
Get the cursor associated with a previously defined output bind variable.
static VALUE sqlrcur_getOutputBindCursor(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); sqlrcursor *result; RCUR1(result,scr,sqlrcurdata->cur,getOutputBindCursor,variable); sqlrcursordata *resultdata=new sqlrcursordata; resultdata->con=sqlrcurdata->con; resultdata->cur=result; return Data_Wrap_Struct(csqlrcursor,sqlrcur_mark,sqlrcur_free, (void *)resultdata); }
Get the value stored in a previously defined decimal output bind variable.
static VALUE sqlrcur_getOutputBindDouble(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; double result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,dr,sqlrcurdata->cur,getOutputBindDouble,variable); return rb_float_new(result); }
Get the value stored in a previously defined integer output bind variable.
static VALUE sqlrcur_getOutputBindInteger(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; int64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,i64r,sqlrcurdata->cur,getOutputBindInteger,variable); return INT2NUM(result); }
Get the length of the value stored in a previously defined output bind variable.
static VALUE sqlrcur_getOutputBindLength(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,u64r,sqlrcurdata->cur,getOutputBindLength,variable); return INT2NUM(result); }
Get the value stored in a previously defined string output bind variable.
static VALUE sqlrcur_getOutputBindString(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; const char *result; uint64_t length; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,ccpr,sqlrcurdata->cur,getOutputBindString,variable); RCUR1(length,u64r,sqlrcurdata->cur,getOutputBindLength,variable); if (result) { return rb_str_new(result,length); } else { return Qnil; } }
Returns the number of result set rows that will be buffered at a time or 0 for the entire result set.
static VALUE sqlrcur_getResultSetBufferSize(VALUE self) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u64r,sqlrcurdata->cur,getResultSetBufferSize); return INT2NUM(result); }
Returns the internal ID of this result set. This parameter may be passed to another statement for use in the resumeResultSet() function. Note: The value this function returns is only valid after a call to suspendResultSet().
static VALUE sqlrcur_getResultSetId(VALUE self) { sqlrcursordata *sqlrcurdata; uint16_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u16r,sqlrcurdata->cur,getResultSetId); return INT2NUM(result); }
Returns an array of the values of the fields in the specified row.
static VALUE sqlrcur_getRow(VALUE self, VALUE row) { sqlrcursordata *sqlrcurdata; sqlrcursor *sqlrcur; const char * const *result; uint32_t *length; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); sqlrcur=sqlrcurdata->cur; VALUE fieldary=rb_ary_new2(sqlrcur->colCount()); RCUR1(result,ccpcpr,sqlrcur,getRow,row); RCUR1(length,u32pr,sqlrcur,getRowLengths,row); for (uint32_t i=0; i<sqlrcur->colCount(); i++) { if (result[i]) { rb_ary_store(fieldary,i,rb_str_new(result[i], length[i])); } else { rb_ary_store(fieldary,i,Qnil); } } return fieldary; }
Returns a hash of the values of the fields in the specified row.
static VALUE sqlrcur_getRowHash(VALUE self, VALUE row) { sqlrcursordata *sqlrcurdata; sqlrcursor *sqlrcur; const char * const *result; uint32_t *length; const char *name; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); sqlrcur=sqlrcurdata->cur; RCUR1(result,ccpcpr,sqlrcur,getRow,row); RCUR1(length,u32pr,sqlrcur,getRowLengths,row); VALUE fieldhash=rb_hash_new(); for (uint32_t i=0; i<sqlrcur->colCount(); i++) { RCUR1(name,ccpr,sqlrcur,getColumnName,INT2NUM(i)); if (result[i]) { rb_hash_aset(fieldhash, rb_str_new2(name), rb_str_new(result[i],length[i])); } else { rb_hash_aset(fieldhash, rb_str_new2(name), Qnil); } } return fieldhash; }
Returns an array of the lengths of the fields in the specified row.
static VALUE sqlrcur_getRowLengths(VALUE self, VALUE row) { sqlrcursordata *sqlrcurdata; sqlrcursor *sqlrcur; uint32_t *result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); sqlrcur=sqlrcurdata->cur; RCUR1(result,u32pr,sqlrcur,getRowLengths,row); if (!result) { return Qnil; } VALUE lengthary=rb_ary_new2(sqlrcur->colCount()); for (uint32_t i=0; i<sqlrcur->colCount(); i++) { rb_ary_store(lengthary,i,INT2NUM(result[i])); } return lengthary; }
Returns a hash of the lengths of the fields in the specified row.
static VALUE sqlrcur_getRowLengthsHash(VALUE self, VALUE row) { sqlrcursordata *sqlrcurdata; sqlrcursor *sqlrcur; uint32_t *result; const char *name; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); sqlrcur=sqlrcurdata->cur; RCUR1(result,u32pr,sqlrcur,getRowLengths,row); VALUE lengthhash=rb_hash_new(); for (uint32_t i=0; i<sqlrcur->colCount(); i++) { RCUR1(name,ccpr,sqlrcur,getColumnName,INT2NUM(i)); rb_hash_aset(lengthhash, rb_str_new2(name), INT2NUM(result[i])); } return lengthhash; }
Sends a query that returns a list of tables matching “wild”. If wild is empty or nil then a list of all tables will be returned.
static VALUE sqlrcur_getTableList(VALUE self, VALUE wild) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,br,sqlrcurdata->cur,getTableList,wild); return INT2NUM(result); }
Defines am input bind variable. The value may be a string, integer or decimal. If it is a decimal then the precision and scale may be specified. If you don’t have the precision and scale then set them both to 0. However in that case you may get unexpected rounding behavior if the server is faking binds.
static VALUE sqlrcur_inputBind(int argc, VALUE *argv, VALUE self) { sqlrcursordata *sqlrcurdata; VALUE variable; VALUE value; VALUE precision; VALUE scale; bool success=true; rb_scan_args(argc,argv,"22",&variable,&value,&precision,&scale); Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(value,rb_cString)==Qtrue) { if ((rb_obj_is_instance_of(precision,rb_cBignum)==Qtrue || rb_obj_is_instance_of(precision,rb_cFixnum)==Qtrue || rb_obj_is_instance_of(precision,rb_cInteger)==Qtrue || rb_obj_is_instance_of(precision,rb_cNumeric)==Qtrue) && NUM2INT(precision)>0) { // in this case, the precision parameter is actually // the string length CUR3(sqlrcurdata->cur,inputBindStrLen,variable,value,precision); } else { CUR2(sqlrcurdata->cur,inputBindStr,variable,value); } } else if (rb_obj_is_instance_of(value,rb_cBignum)==Qtrue || rb_obj_is_instance_of(value,rb_cFixnum)==Qtrue || rb_obj_is_instance_of(value,rb_cInteger)==Qtrue || rb_obj_is_instance_of(value,rb_cNumeric)==Qtrue) { CUR2(sqlrcurdata->cur,inputBindInt,variable,value); } else if (rb_obj_is_instance_of(value,rb_cFloat)==Qtrue) { CUR4(sqlrcurdata->cur,inputBindDbl,variable,value,precision,scale); } else if (rb_obj_is_instance_of(value,rb_cNilClass)==Qtrue) { CUR1(sqlrcurdata->cur,inputBindNull,variable); } else { success=false; } return INT2NUM(success); }
Defines a binary lob input bind variable.
static VALUE sqlrcur_inputBindBlob(VALUE self, VALUE variable, VALUE value, VALUE size) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); bool success=true; if (value==Qnil) { CUR2(sqlrcurdata->cur,inputBindBlobNull,variable,size); } else if (rb_obj_is_instance_of(value,rb_cString)==Qtrue) { CUR3(sqlrcurdata->cur,inputBindBlob,variable,value,size); } else { success=false; } return INT2NUM(success); }
Defines a character lob input bind variable.
static VALUE sqlrcur_inputBindClob(VALUE self, VALUE variable, VALUE value, VALUE size) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); bool success=true; if (value==Qnil) { CUR2(sqlrcurdata->cur,inputBindClobNull,variable,size); } else if (rb_obj_is_instance_of(value,rb_cString)==Qtrue) { CUR3(sqlrcurdata->cur,inputBindClob,variable,value,size); } else { success=false; } return INT2NUM(success); }
Defines an array of input bind variables. The values may be strings, integers or decimals. If they are decimals then the precisions and scales may also be specified.
static VALUE sqlrcur_inputBinds(int argc, VALUE *argv, VALUE self) { sqlrcursordata *sqlrcurdata; VALUE variables; VALUE values; VALUE precisions; VALUE scales; int argcount=rb_scan_args(argc,argv,"22", &variables,&values,&precisions,&scales); Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (variables==Qnil || values==Qnil) { return Qnil; } VALUE variable; VALUE value; VALUE precision=0; VALUE scale=0; bool success=true; for (;;) { variable=rb_ary_shift(variables); if (variable==Qnil) { break; } value=rb_ary_shift(values); if (argcount==4) { precision=rb_ary_shift(precisions); scale=rb_ary_shift(scales); } if (rb_obj_is_instance_of(value,rb_cString)==Qtrue) { CUR2(sqlrcurdata->cur,inputBindStr,variable,value); } else if (rb_obj_is_instance_of(value,rb_cBignum)==Qtrue || rb_obj_is_instance_of(value,rb_cFixnum)==Qtrue || rb_obj_is_instance_of(value,rb_cInteger)==Qtrue || rb_obj_is_instance_of(value,rb_cNumeric)==Qtrue) { CUR2(sqlrcurdata->cur,inputBindInt,variable,value); } else if (rb_obj_is_instance_of(value,rb_cFloat)==Qtrue) { CUR4(sqlrcurdata->cur,inputBindDbl,variable, value,precision,scale); } else if (rb_obj_is_instance_of(value,rb_cNilClass)==Qtrue) { CUR1(sqlrcurdata->cur,inputBindNull,variable); } else { success=false; } } return INT2NUM(success); }
Columns names are converted to lower case.
static VALUE sqlrcur_lowerCaseColumnNames(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,lowerCaseColumnNames); return Qnil; }
Columns names are returned in the same case as they are defined in the database. This is the default.
static VALUE sqlrcur_mixedCaseColumnNames(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,mixedCaseColumnNames); return Qnil; }
Opens a cached result set. Returns 1 on success and 0 on failure.
static VALUE sqlrcur_openCachedResultSet(VALUE self, VALUE filename) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,br,sqlrcurdata->cur,openCachedResultSet,filename); return INT2NUM(result); }
Prepare to execute the contents of “path”/“filename”.
static VALUE sqlrcur_prepareFileQuery(VALUE self, VALUE path, VALUE filename) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR2(result,br,sqlrcurdata->cur,prepareFileQuery,path,filename); return INT2NUM(result); }
Prepare to execute “query”.
static VALUE sqlrcur_prepareQuery(VALUE self, VALUE query) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,prepareQuery,query); return Qnil; }
Prepare to execute “query” with length “length”. This function must be used if the query contains binary data.
static VALUE sqlrcur_prepareQueryWithLength(VALUE self, VALUE query, VALUE length) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR2(sqlrcurdata->cur,prepareQueryWithLength,query,length); return Qnil; }
Resumes a result set previously left open using suspendSession() and continues caching the result set to “filename”. Returns 1 on success and 0 on failure.
static VALUE sqlrcur_resumeCachedResultSet(VALUE self, VALUE id, VALUE filename) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR2(result,br,sqlrcurdata->cur,resumeCachedResultSet,id,filename); return INT2NUM(result); }
Resumes a result set previously left open using suspendSession(). Returns 1 on success and 0 on failure.
static VALUE sqlrcur_resumeResultSet(VALUE self, VALUE id) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,br,sqlrcurdata->cur,resumeResultSet,id); return INT2NUM(result); }
Returns the number of rows in the current result set.
static VALUE sqlrcur_rowCount(VALUE self) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u32r,sqlrcurdata->cur,rowCount); return INT2NUM(result); }
Sends the query in file “path”/“filename” and gets a result set.
static VALUE sqlrcur_sendFileQuery(VALUE self, VALUE path, VALUE filename) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR2(result,br,sqlrcurdata->cur,sendFileQuery,path,filename); return INT2NUM(result); }
Sends “query” directly and gets a result set.
static VALUE sqlrcur_sendQuery(VALUE self, VALUE query) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,br,sqlrcurdata->cur,sendQuery,query); return INT2NUM(result); }
Sends “query” with length “length” directly and gets a result set. This function must be used if the query contains binary data.
static VALUE sqlrcur_sendQueryWithLength(VALUE self, VALUE query, VALUE length) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR2(result,br,sqlrcurdata->cur,sendQueryWithLength,query,length); return INT2NUM(result); }
Sets the time-to-live for cached result sets. The sqlr-cachemanger will remove each cached result set “ttl” seconds after it’s created, provided it’s scanning the directory containing the cache files.
static VALUE sqlrcur_setCacheTtl(VALUE self, VALUE ttl) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,setCacheTtl,ttl); return Qnil; }
Sets the number of rows of the result set to buffer at a time. 0 (the default) means buffer the entire result set.
static VALUE sqlrcur_setResultSetBufferSize(VALUE self, VALUE rows) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR1(sqlrcurdata->cur,setResultSetBufferSize,rows); return Qnil; }
Defines a substitution variable. The value may be a string, integer or decimal. If it is a decimal then the precision and scale may be specified.
static VALUE sqlrcur_substitution(int argc, VALUE *argv, VALUE self) { sqlrcursordata *sqlrcurdata; VALUE variable; VALUE value; VALUE precision; VALUE scale; bool result=true; rb_scan_args(argc,argv,"22",&variable,&value,&precision,&scale); Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (rb_obj_is_instance_of(value,rb_cString)==Qtrue) { CUR2(sqlrcurdata->cur,substitutionStr,variable,value); } else if (rb_obj_is_instance_of(value,rb_cBignum)==Qtrue || rb_obj_is_instance_of(value,rb_cFixnum)==Qtrue || rb_obj_is_instance_of(value,rb_cInteger)==Qtrue || rb_obj_is_instance_of(value,rb_cNumeric)==Qtrue) { CUR2(sqlrcurdata->cur,substitutionInt,variable,value); } else if (rb_obj_is_instance_of(value,rb_cFloat)==Qtrue) { CUR4(sqlrcurdata->cur,substitutionDbl,variable,value,precision,scale); } else if (rb_obj_is_instance_of(value,rb_cNilClass)==Qtrue) { CUR1(sqlrcurdata->cur,substitutionNull,variable); } else { result=false; } return INT2NUM(result); }
Defines an array of substitution variables. The values may be strings, integers or decimals. If they are decimals then the precisions and scales may also be specified.
static VALUE sqlrcur_substitutions(int argc, VALUE *argv, VALUE self) { sqlrcursordata *sqlrcurdata; VALUE variables; VALUE values; VALUE precisions; VALUE scales; int argcount=rb_scan_args(argc,argv,"22", &variables,&values,&precisions,&scales); Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); if (variables==Qnil || values==Qnil) { return Qnil; } VALUE variable; VALUE value; VALUE precision=0; VALUE scale=0; bool success=true; for (;;) { variable=rb_ary_shift(variables); if (variable==Qnil) { break; } value=rb_ary_shift(values); if (argcount==4) { precision=rb_ary_shift(precisions); scale=rb_ary_shift(scales); } if (rb_obj_is_instance_of(value,rb_cString)==Qtrue) { CUR2(sqlrcurdata->cur,substitutionStr,variable,value); } else if (rb_obj_is_instance_of(value,rb_cBignum)==Qtrue || rb_obj_is_instance_of(value,rb_cFixnum)==Qtrue || rb_obj_is_instance_of(value,rb_cInteger)==Qtrue || rb_obj_is_instance_of(value,rb_cNumeric)==Qtrue) { CUR2(sqlrcurdata->cur,substitutionInt,variable,value); } else if (rb_obj_is_instance_of(value,rb_cFloat)==Qtrue) { CUR4(sqlrcurdata->cur,substitutionDbl,variable, value,precision,scale); } else if (rb_obj_is_instance_of(value,rb_cNilClass)==Qtrue) { CUR1(sqlrcurdata->cur,substitutionNull,variable); } else { success=false; } } return INT2NUM(success); }
Tells the server to leave this result set open when the connection calls suspendSession() so that another connection can connect to it using resumeResultSet() after it calls resumeSession().
static VALUE sqlrcur_suspendResultSet(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,suspendResultSet); return Qnil; }
Returns the total number of rows that will be returned in the result set. Not all databases support this call. Don’t use it for applications which are designed to be portable across databases. -1 is returned by databases which don’t support this option.
static VALUE sqlrcur_totalRows(VALUE self) { sqlrcursordata *sqlrcurdata; uint64_t result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR(result,u64r,sqlrcurdata->cur,totalRows); return INT2NUM(result); }
Columns names are converted to upper case.
static VALUE sqlrcur_upperCaseColumnNames(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,upperCaseColumnNames); return Qnil; }
Returns true if “variable” was a valid bind variable of the query.
static VALUE sqlrcur_validBind(VALUE self, VALUE variable) { sqlrcursordata *sqlrcurdata; bool result; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); RCUR1(result,br,sqlrcurdata->cur,validBind,variable); return INT2NUM(result); }
If you are binding to any variables that might not actually be in your query, call this to ensure that the database won’t try to bind them unless they really are in the query. There is a performance penalty for calling this function
static VALUE sqlrcur_validateBinds(VALUE self) { sqlrcursordata *sqlrcurdata; Data_Get_Struct(self,sqlrcursordata,sqlrcurdata); CUR(sqlrcurdata->cur,validateBinds); return Qnil; }