For example:
load /usr/lib/sqlrelay/sqlrelay.so sqlrelay set con [sqlrcon -server "adasz" -port "9000" -user "user1" -password "password"] set cur [$con sqlrcur] catch [$cur sendQuery "select table_name from user_tables"] $con endSession for {set i 0} {$i<[$cur rowCount]} {incr i} { puts [$cur getFieldByName $i "table_name"] }
set con [sqlrcon -server "server" -port "port" -socket "socket"
-user "user" -password "password" -retrytime "0" -tries "1"]
Initiates a connection to "server" on "port" or to the unix "socket" on the local machine and authenticates with "user" and "password". Failed connections will be retried for "tries" times on interval "retrytime". If "tries" is 0 then retries will continue forever. If "retrytime" is 0 then retries will be attempted on a default interval.
If the "socket" parameter isn't "" then an attempt will be made to connect through it before attempting to connect to "server" on "port". If it is "" then no attempt will be made to connect through the socket.
$con endSession
terminates the session
$con suspendSession
Disconnects this client from the current session but leaves the session open so that another client can connect to it using resumeSession
$con getConnectionPort
Returns the inet port that the client is communicating over. This parameter may be passed to another client for use in the resumeSession command. Note: the value returned by this method is only valid after a call to suspendSession.
$con getConnectionSocket
Returns the unix socket that the client is communicating over. This parameter may be passed to another client for use in the resumeSession command. Note: the value returned by this method is only valid after a call to suspendSession.
$con resumeSession port socket
Resumes a session previously left open using suspendSession. Returns 1 on success and 0 on failure.
$con ping
Returns 1 if the database is up and 0 if it's down.
$con identify
Returns the type of database: oracle8, postgresql, mysql, etc.
$con dbVersion
Returns the version of the database
$con bindFormat
Returns a string representing the format of the bind variables used in the db.
$con autoCommit true|false
Instructs the database to wait for the client to tell it when to commit.
$con commit
Issues a commit. Returns 1 if the commit succeeded, 0 if it failed and -1 if an error occurred.
$con rollback
Issues a rollback. Returns 1 if the rollback succeeded, 0 if it failed and -1 if an error occurred.
$con debug true|false
Causes verbose debugging information to be sent to standard output. Another way to do this is to start a query with "-- debug\n".
$con getDebug
returns FALSE if debugging is off and TRUE if debugging is on
$con sqlrcur
Creates a cursor object
$con eval query
Runs query and returns the result set as a list of lists where the main list contains rows and each sub-list contains the fields of each row.
$cur setResultSetBufferSize rows
Sets the number of rows of the result set to buffer at a time. 0 (the default) means buffer the entire result set.
$cur getResultSetBufferSize
Returns the number of result set rows that will be buffered at a time or 0 for the entire result set.
$cur dontGetColumnInfo
Tells the server not to send any column info (names, types, sizes). If you don't need that info, you should call this method to improve performance.
$cur caseColumnNames upper|lower|mixed
Columns names are converted to upper or lower case or returned as they appear in the database.
$cur getColumnInfo
Tells the server to send column info.
$cur cacheToFile filename
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.
$cur setCacheTtl ttl
Sets the time-to-live for cached result sets. The sqlr-cachemanger will remove each cached result set "ttl" seconds after it's created.
$cur getCacheFileName
Returns the name of the file containing the most recently cached result set.
$cur cacheOff
Sets query caching off.
If you don't need to use substitution or bind variables in your queries, use these two methods.
$cur sendQuery query
Sends "query" and gets a return set. Returns TRUE on success and FALSE on failure.
$cur sendQueryWithLength query length
Sends "query" with length "length" and gets a result set. This method must be used if the query contains binary data.
$cur sendFileQuery path filename
Sends the query in file "path"/"filename" and gets a return set. Returns TRUE on success and FALSE on failure.
If you need to use substitution or bind variables, in your queries use the following methods. See the API documentation for more information about substitution and bind variables.
$cur prepareQuery query
Prepare to execute "query".
$cur prepareQueryWithLength query length
Prepare to execute "query" with length "length". This method must be used if the query contains binary data.
$cur prepareFileQuery path filename
Prepare to execute the contents of "path"/"filename".
$cur substitution variable value ?precision? ?scale?
Define a substitution variable.
$cur substitutions {{variable value ?precision? ?scale?} ...}
Define a set of substitution variables.
$cur clearBinds
Clear all bind variables.
$cur countBindVariables
Parses the previously prepared query, counts the number of bind variables defined in it and returns that number.
$cur inputBind variable value ?precision? ?scale?
$cur inputBindBlob variable length
$cur inputBindClob variable length
Define an input bind variable.
$cur inputBinds {{variable value ?precision? ?scale?} ...}
Defines a set of input bind variables.
$cur defineOutputBindString variable length
Define a string output bind variable. "length" bytes will be reserved to store the value.
$cur defineOutputBindInteger variable
Define an integer output bind variable.
$cur defineOutputBindDouble variable
Define a double precision floating point output bind variable.
$cur defineOutputBindBlob variable
Define a BLOB output bind variable.
$cur defineOutputBindClob variable
Define a CLOB output bind variable.
$cur defineOutputBindCursor variable
Define a cursor output bind variable.
$cur validateBinds
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.
$cur validBind variable
Returns true if "variable" was a valid bind variable of the query.
$cur executeQuery
Execute the query that was previously prepared and bound.
$cur fetchFromBindCursor
Fetch from a cursor that was returned as an output bind variable.
$cur getOutputBindString variable
Get the value stored in a previously defined output bind variable.
$cur getOutputBindBlob variable
Get the value stored in a previously defined output bind variable.
$cur getOutputBindClob variable
Get the value stored in a previously defined output bind variable.
$cur getOutputBindInteger variable
Get the value stored in a previously defined output bind variable and return it as an integer.
$cur getOutputBindDouble variable
Get the value stored in a previously defined output bind variable and return it as a double.
$cur getOutputBindLength variable
Get the length of the value stored in a previously defined output bind variable.
$cur getOutputBindCursor variable
Get the cursor associated with a previously defined output bind variable.
$cur openCachedResultSet filename
Opens a cached result set as if a query that would have generated it had been executed. Returns TRUE on success and FALSE on failure.
$cur colCount
returns the number of columns in the current return set
$cur rowCount
returns the number of rows in the current return set
$cur totalRows
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.
$cur affectedRows
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.
$cur firstRowIndex
Returns the index of the first buffered row. This is useful when buffering only part of the result set at a time.
$cur endOfResultSet
Returns 0 if part of the result set is still pending on the server and 1 if not. This method can only return 0 if $cur setResultSetBufferSize has been called with a parameter other than 0.
$cur errorMessage
If a query failed and generated an error, the error message is available here. If the query succeeded then this method returns FALSE
$cur getFieldByName row col
$cur getFieldByIndex row col
returns a string with value of the specified row and column
$cur getFieldAsIntegerByName row col
$cur getFieldAsIntegerByIndex row col
returns an integer with value of the specified row and column
$cur getFieldAsDoubleByName row col
$cur getFieldAsDoubleByIndex row col
returns a double with value of the specified row and column
$cur getFieldLengthByName row col
$cur getFieldLengthByIndex row col
returns the length of the specified row and column
$cur getRow row
returns an indexed array of the values of the specified row
$cur getRowLengths row
returns an indexed array of the lengths of the specified row
$cur getColumnNames
returns the array of the column names of the current return set
$cur getColumnName col
returns the name of the specified column
$cur getColumnTypeByName col
$cur getColumnTypeByIndex col
returns the type of the specified column
$cur getColumnLengthByName col
$cur getColumnLengthByIndex col
returns the length of the specified column.
$cur getColumnPrecisionByName col
$cur getColumnPrecisionByIndex col
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.
$cur getColumnScaleByName col
$cur getColumnScaleByIndex col
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.
$cur getColumnIsNullableByName col
$cur getColumnIsNullableByIndex col
Returns 1 if the specified column can contain nulls and 0 otherwise.
$cur getColumnIsPrimaryKeyByName col
$cur getColumnIsPrimaryKeyByIndex col
Returns 1 if the specified column is a primary key and 0 otherwise.
$cur getColumnIsUniqueByName col
$cur getColumnIsUniqueByIndex col
Returns 1 if the specified column is unique and 0 otherwise.
$cur getColumnIsPartOfKeyByName col
$cur getColumnIsPartOfKeyByIndex col
Returns 1 if the specified column is part of a composite key and 0 otherwise.
$cur getColumnIsUnsignedByName col
$cur getColumnIsUnsignedByIndex col
Returns 1 if the specified column is an unsigned number and 0 otherwise.
$cur getColumnIsZeroFilledByName col
$cur getColumnIsZeroFilledByIndex col
Returns 1 if the specified column was created with the zero-fill flag and 0 otherwise.
$cur getColumnIsBinaryByName col
$cur getColumnIsBinaryByIndex col
Returns 1 if the specified column contains binary data and 0 otherwise.
$cur getColumnIsAutoIncrementByName col
$cur getColumnIsAutoIncrementByIndex col
Returns 1 if the specified column auto-increments and 0 otherwise.
$cur getLongestByName col
$cur getLongestByIndex col
Returns the length of the longest field in the specified column.
$cur suspendResultSet
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.
$cur getResultSetId
Returns the internal ID of this result set. This parameter may be passed to another statement for use in the resumeResultSet method. Note: the value returned by this method is only valid after a call to suspendResultSet.
$cur resumeResultSet id
Resumes a result set previously left open using suspendSession. Returns 1 on success and 0 on failure.
$cur resumeCachedResultSet id filename
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.