Working with CSQL Gateway

<< Cache from multiple Data Sources - TOC - Tools for Cache >>

CSQL Cache allows access to tables, which are stored in target database and are not cached in CSQL MMDB. ODBC and JDBC applications can connect using the gateway option to get his behavior.

Using CSQL tool

In another terminal run csql tool with -g option. This creates an isql session which acts as gateway to csql and target database.

$csql -g
CSQL>

The records could be retrieved from tables, which are not cached in CSQL and are present in target database

$csql -g
CSQL>select * from t3;

It will display

24083:3086153424:DatabaseManagerImpl.cxx:599:Table not exists t3
24083:3086153424:SelStatement.cxx:245:Unable to open the table: Table not exists
------------------------------
        f1      f2
------------------------------
        103     103

First it displays that the table is not present in CSQL, then it checks with target database whether the table is present there and if present it retrieves the records from target database.

Using ODBC Interface

ODBC DSN name should specify the mode to connect through gateway. Sample code snippet to connect to gateway is given below.

void checkrc (int rc, int line)
{
  if (rc)
  {
      printf(“Failed with rc:%d at line:%d\n”, rc, line);
      exit (1);
    }
}
int main()
{
   SQLHENV henv;
   SQLHDBC hdbc;
   SQLHSTMT hstmt;
   int rc = SQLAllocHandle (SQL_HANDLE_ENV, 
                        SQL_NULL_HANDLE, &henv);
  checkrc (rc, __LINE__);
  SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, 
                      (void *) SQL_OV_ODBC3, 0);

  rc = SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc);
  checkrc (rc, __LINE__);
  rc = SQLConnect (hdbc, (SQLCHAR *)    
"DSN=test;MODE=Gateway;SERVER=localhost;PORT=5678;", 
                 SQL_NTS,
                (SQLCHAR *) "root",
                (SQLSMALLINT) strlen ("root"),
                (SQLCHAR *) "manager",
                (SQLSMALLINT) strlen (""));

//Place statements here to 
//perform DML operations on cached 
//and non-cached tables

   SQLDisconnect(hdbc);
}

Using JDBC Interface

JDBC URL needs to be modified to “jdbc::gateway” to connect through gateway. Sample code snippet to connect to gateway is given below

import java.sql. *;
public class gwexample{
   public static void main(String[] args){
       try{
          Class.forName("csql.jdbc.JdbcSqlDriver");
          Connection con = DriverManager.getConnection("jdbc:gateway",        "root", "manager");

Statement cStmt = con.createStatement();
PreparedStatement stmt = null;

//Place statements here to 
//perform DML operations on cached 
//and non-cached tables

con.close();

     }catch(Exception e) {
      System.out.println("Exception in Test: "+e);
      e.printStackTrace();
   }
 }
}

Using SQL Interface

From SQL API, use CSqlGateway flag to create connection and statement objects using SqlFactory class.

AbsSqlConnection *con = SqlFactory::
                      createConnection(CSqlGateway);

rv = con->connect("root", "manager");

if (rv != OK) return 1;

AbsSqlStatement *stmt = SqlFactory::
                       createStatement(CSqlGateway);

stmt->setConnection(con);

/* Place statements here to */
/* Perform DML operations on cached */
/* And non-cached tables */
stmt->disconnect();

<< Cache from multiple Data Sources - TOC - Tools for Cache >>

Page last modified on October 23, 2009, at 05:01 AM