Initiates a connection to “host” 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, waiting “retrytime” seconds between each try. 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 is nether nil nor “” then an attempt will be made to connect through it before attempting to connect to “host” on “port”. If it is nil or “” then no attempt will be made to connect through the socket.
static VALUE sqlrcon_new(VALUE self, VALUE host, VALUE port, VALUE socket, VALUE user, VALUE password, VALUE retrytime, VALUE tries) { const char *socketstr; if (socket==Qnil) { socketstr=""; } else { socketstr=STR2CSTR(socket); } sqlrconnection *sqlrcon=new sqlrconnection(STR2CSTR(host), NUM2INT(port), socketstr, STR2CSTR(user), STR2CSTR(password), NUM2INT(retrytime), NUM2INT(tries), true); return Data_Wrap_Struct(self,0,sqlrcon_free,(void *)sqlrcon); }
Instructs the database to wait for the client to tell it when to commit.
static VALUE sqlrcon_autoCommitOff(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->autoCommitOff()); }
Instructs the database to perform a commit after every successful query.
static VALUE sqlrcon_autoCommitOn(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->autoCommitOn()); }
Begins a transaction. Returns true if the begin succeeded, false if it failed. If the database automatically begins a new transaction when a commit or rollback is issued then this doesn't do anything unless SQL Relay is faking transaction blocks.
static VALUE sqlrcon_begin(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->begin()); }
Returns a string representing the format of the bind variables used in the db.
static VALUE sqlrcon_bindFormat(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->bindFormat(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Returns the version of the sqlrelay client software.
static VALUE sqlrcon_clientVersion(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->clientVersion(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Issues a commit. Returns true if the commit succeeded, false if it failed.
static VALUE sqlrcon_commit(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->commit()); }
Returns the host name of the database
static VALUE sqlrcon_dbHostName(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->dbHostName(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Returns the ip address of the database
static VALUE sqlrcon_dbIpAddress(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->dbIpAddress(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Returns the version of the database
static VALUE sqlrcon_dbVersion(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->dbVersion(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Turns debugging off.
static VALUE sqlrcon_debugOff(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); sqlrcon->debugOff(); return Qnil; }
Causes verbose debugging information to be sent to standard output. Another way to do this is to start a query with “– debugn”. Yet another way is to set the environment variable SQLR_CLIENT_DEBUG to “ON”
static VALUE sqlrcon_debugOn(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); sqlrcon->debugOn(); return Qnil; }
Ends the session.
static VALUE sqlrcon_endSession(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); sqlrcon->endSession(); return Qnil; }
If an operation failed and generated an error, the error message is available here. If there is no error then this method returns nil
static VALUE sqlrcon_errorMessage(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->errorMessage(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
If an operation failed and generated an error, the error number is available here. If there is no error then this method returns 0.
static VALUE sqlrcon_errorNumber(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->errorNumber()); }
Returns the string that was set by setClientInfo().
static VALUE sqlrcon_getClientInfo(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->getClientInfo(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Returns the inet port that the connection is communicating over. This parameter may be passed to another connection for use in the sqlrcon_resumeSession() command. Note: The result this function returns is only valid after a call to suspendSession().
static VALUE sqlrcon_getConnectionPort(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->getConnectionPort()); }
Returns the unix socket that the connection is communicating over. This parameter may be passed to another connection for use in the sqlrcon_resumeSession() command. Note: The result this function returns is only valid after a call to suspendSession().
static VALUE sqlrcon_getConnectionSocket(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->getConnectionSocket(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Returns the database/schema that is currently in use.
static VALUE sqlrcon_getCurrentDatabase(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->getCurrentDatabase(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Returns 0 if debugging is off and 1 if debugging is on.
static VALUE sqlrcon_getDebug(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->getDebug()); }
Returns the value of the autoincrement column for the last insert
static VALUE sqlrcon_getLastInsertId(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->getLastInsertId()); }
Returns the type of database: oracle8, postgresql, mysql, etc.
static VALUE sqlrcon_identify(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->identify(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Returns 1 if the database is up and 0 if it's down.
static VALUE sqlrcon_ping(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->ping()); }
Resumes a session previously left open using sqlrcon_suspendSession(). Returns 1 on success and 0 on failure.
static VALUE sqlrcon_resumeSession(VALUE self, VALUE port, VALUE socket) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->resumeSession(NUM2INT(port), STR2CSTR(socket))); }
Issues a rollback. Returns true if the rollback succeeded, false if it failed.
static VALUE sqlrcon_rollback(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->rollback()); }
Sets the current database/schema to “database”
static VALUE sqlrcon_selectDatabase(VALUE self, VALUE db) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->selectDatabase(STR2CSTR(db))); }
Returns the version of the sqlrelay server software.
static VALUE sqlrcon_serverVersion(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); const char *result=sqlrcon->serverVersion(); if (result) { return rb_str_new2(result); } else { return Qnil; } }
Allows you to set a string that will be passed to the server and ultimately included in server-side logging along with queries that were run by this instance of the client.
static VALUE sqlrcon_setClientInfo(VALUE self, VALUE clientinfo) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); sqlrcon->setClientInfo(STR2CSTR(clientinfo)); return Qnil; }
Sets the server connect timeout in seconds and milliseconds. Setting either parameter to -1 disables the timeout. You can also set this timeout using the SQLR_CLIENT_CONNECT_TIMEOUT environment variable.
static VALUE sqlrcon_setConnectTimeout(VALUE self, VALUE timeoutsec, VALUE timeoutusec) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); sqlrcon->setConnectTimeout(NUM2INT(timeoutsec),NUM2INT(timeoutusec)); return Qnil; }
Allows you to specify a file to write debug to. Setting “filename” to NULL or an empty string causes debug to be written to standard output (the default).
static VALUE sqlrcon_setDebugFile(VALUE self, VALUE filename) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); sqlrcon->setDebugFile(STR2CSTR(filename)); return Qnil; }
Disconnects this connection from the current session but leaves the session open so that another connection can connect to it using sqlrcon_resumeSession().
static VALUE sqlrcon_suspendSession(VALUE self) { sqlrconnection *sqlrcon; Data_Get_Struct(self,sqlrconnection,sqlrcon); return INT2NUM(sqlrcon->suspendSession()); }