• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Sqlapi0.1
 

Sqlapi0.1

on

  • 723 views

SQL API is the proprietary interface of CSQL to connect and execute DDL and DML opeartions in CSQL database.

SQL API is the proprietary interface of CSQL to connect and execute DDL and DML opeartions in CSQL database.

Statistics

Views

Total Views
723
Views on SlideShare
722
Embed Views
1

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 1

http://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Sqlapi0.1 Sqlapi0.1 Presentation Transcript

    • Jitendra Lenka Developer - Lakshya Solutions Ltd. [email_address] olutions.com CSQL - SQLAPI
    • Module Objectives
      • After completing this module you will be able to :
      • Understand various interfaces in SQLAPI.
      • Write application to access CSQL database
      • Understand different SQL statements executed in CSQL database with parameter and projection value.
      • The topics to be covered in this session are :-
      • Introduction to CSQL main memory database cache.
      • Overview of different Interfaces to client provided by CSQL.
      • Important classes and functions for writing application in SQLAPI.
      • Connection to the CSQL database and execute DDL and DML statements.
      • Handling errors returned by various functions in SQLAPI.
      • Know about non-primptive datatypes like Date, Time,TimeStamp .
      Module Coverage
      • CSQL Database, which comprises suite of products such as Main Memory Database with complete ACID properties, Cache to leading disk based databases (MySQL, Postgres, and Oracle), and Replication, which provides high availability and load balancing cluster for MMDB.
      • It is 30x faster than any leading database.
      • CSQL is mainly developed to be used as a cache for existing disk based commercial databases, which delivers application response times in microseconds by bringing frequently accessed data closer to the application.
      • CSQL is available as a open source product in(sourceforge.net) site, also available in official site(csqldb.com) as Proprietary license.
      • Download Enterprise version: http://csqldb.com/download.html
      • Open Source version: http://sourceforge.net/products/csql
      What is CSQL?
      • Referenced Manuals:
      • User Manual: Describes Concept, components and basic usages and useful for administrators.
      • Programmer Guide: It covers JDBC, ODBC and proprietary SQL interface and useful for application developers.
      • Cache Guide: Describes caching functionality of CSQL and configuration settings required to set up caching for MySQL, Postgres and Oracle DBMS.
      • Documentation Downloading : http://www.csqldb.com/pro_documentation.html
      CSQL Guides
      • ODBC C/C++ standard interface for SQL engine.
      • JDBC Java standard interface for SQL engine.
      • SQLAPI Proprietary interface for SQL engine.
      • DBAPI Proprietary interface for Storage engine
      Overview
      • Proprietary C++ Interface
      • Important classes
        • SqlFactory - create appropriate implementation for SQLAPI
        • AbsSqlConnection - It represents a database connection to sql engine.
        • AbsSqlStatement - Handle to the sql statement.
      • Header Files
        • AbsSqlStatement.h
        • SqlFactory.h
        • Info.h
      • Library
        • libcsqlsql.so
      SQLAPI
      • DbRetVal : This enum is defined in ErrorType.h file and contain all the error codes returned by all the functions.
      • Sample error codes :
      • OK = 0,
      • ErrSysFatal = -1,
      • ErrSysInit = -2,
      • ErrNoPrivilege = -3,
      • ErrSysInternal = -4,
      • ErrNoExists = -5,
      • ErrNoMemory = -6,
      • .
      • .
      • .
      • SplCase = -100
      Error Handling
      • This class is the entry point to access the database through the SQL engine.Each
      • connection has only one active transaction at any given point of time.
      • Member Functions :
      • DbRetVal connect( char *user, char *password )
        • Open connection to the sql engine.
      • DbRetVal close()
        • Closes connection to the database and releases all the resources .
      • DbRetVal beginTrans( IsolationLevel isolationLevel = READ_COMMITTED )
        • Starts a transaction
      AbsSqlConnection
      • This class is the entry point to access the database through the SQL engine.Each
      • connection has only one active transaction at any given point of time.
      • Member Functions :
      • DbRetVal commit()
        • Commits active transaction.
      • DbRetVal rollback()
        • Abrots active transaction.
      • DbRetVal isConnectionOpen()
        • Checks whether a connection is open or closed.
      AbsSqlConnection
      • This class is to create appropriate implementation of SQLAPI.
      • Member Functions :
      • static AbsSqlConnection *createConnection( SqlApiImplType implFlag )
        • Creates appropriate implementation of AbsSqlConenction based on implFlag passed .
        • Argument : implFlag { CSql = 1,CSqlAdapter = 2,CSqlGateway = 3 , ... }
        • Return Type : AbsSqlConenction
      • static AbsSqlStatement *createStatement( SqlApiImplType implFlag )
        • Creates appropriate implementation of AbsSqlStatement based on implFlag passed .
        • Argument : implFlag { CSql = 1,CSqlAdapter = 2,CSqlGateway = 3, … }
        • Return Type : AbsSqlConnection
      SqlFactory
      • EXAMPLE : Below snippet code shows how to open and close a connection.
      • #include<AbsSqlConnection.h>
      • #include<SqlFactory.h>
      • int main( ) {
      • DbRetVal rv = OK ;
      • AbsSqlConnection *con = SqlFactory :: createConnection( CSql ) ;
      • rv = con->connect( “root” , “manager” ) ;
      • if( rv != OK ) return 1;
      • printf(“Connection opened”) ;
      • rv = con -> close( );
      • if( rv !=OK ) return 2 ;
      • printf(“close the connection”) ;
      • }
      Connection
    • Data Type Primptive Non-Primptive typeInt typeByteInt typeLongLong typeDate typeShort typeTime typeFloat typeTimeStamp typeDouble typeString
      • This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from the database.
      • Member Functions :
      • void setConnection( AbsSqlConnection *con)
        • Sets connection handle to be used for subsequent operations.
      • DbRetVal prepare( char *statement )
        • Compiles the sql statement.
      • DbRetVal execute( int &rowsAffect )
        • Execute the sql statement
      AbsSqlStatement
      • This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from the database.
      • Member Functions :
      • DbRetVal bindField( int pos , void *val )
        • Binds application buffer to the specified field position of the projection list in the select query or for fields in the insert statement.
      • void *fetch( )
        • Fetches the next tuple from the result of the execution of sql select query.
      • void *fetchAndPrint( bool sql )
        • Fetches the next tuple from the result of the execution of sql select query and prints it to stdout.
      AbsSqlStatement
      • This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from the database.
      • Member Functions :
      • DbRetVal free( )
        • Frees all the resources held for the sql statement.
      • int noOfProjFields( )
        • Retrieves the total number of projection fields in the statement.
      • int noOfParamFields( )
        • Retrieves the total number of parameters in the statement.
      AbsSqlStatement
      • This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from the database.
      • Member Functions :
      • DbRetVal getProjFldInfo( int ProjPos , FieldInfo *&info )
        • Retrieves the field info for the required projection field position in statement
      • DbRetVal paramFldInfo( int ParamPos , FieldInfo *&info )
        • Retrieves the field info for the required parameter position in statement.
      • bool isSelect( )
        • Returns whether the statement prepared is select statement.
      • DbRetVal close( )
        • Closes the iterator & makes the statement ready for another execution.
      AbsSqlStatement
      • This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from the database.
      • Member Functions :
      • void set<Type>Param( int ParamPos , [ Type ] value )
        • Sets the value for the required parameter position in the statement.“ Type “ could be any type of datatype .
        • Type : i nt,Short,Long,LongLong,Byte,Float,Double,String,Date,Time.
        • Example : setShortParam ( int ParamPos , short value ) ,
        • setDateParam ( int ParamPos , date value ) , etc .
      AbsSqlStatement
      • EXAMPLE : commit or rollback a transaction.
      • // include the necessary header files
      • int main() {
      • DbRetVal rv = OK ;
      • AbsSqlConnection *con = SqlFactory :: createConnection( CSql ) ;
      • rv = con->connect( “root” , “manager” ) ;
      • AbsSqlStatement *stmt = SqlFactory :: createStatement( CSql ) ;
      • stmt -> setConnection(con) ;
      • con -> beginTrans( ) ;
      • // DML operations
      • con -> commit( ) ; // or you can specify rollback( ) here also .
      • stmt->free();
      • delete stmt ; delete con ; return 0;
      • }
      • Isolation level : To specify consistency and concurrency of Transactions
      • Values : READ COMMITTED | READ UNCOMMITTED | READ REPEATABLE
      Transaction
      • EXAMPLE : create table emp( eid int, ename char(20), doj date) ;
      • // include the necessary header files
      • int main() {
      • DbRetVal rv = OK ;
      • AbsSqlConnection *con = SqlFactory :: createConnection( CSql ) ;
      • rv = con->connect( “root” , “manager” ) ;
      • AbsSqlStatement *stmt = SqlFactory :: createStatement( CSql ) ;
      • stmt -> setConnection(con) ;
      • char statement[100] ;
      • strcpy(statement , ”create table emp(eid int, ename char(20), doj date) ; ” ) ;
      • int rows;
      • stmt->prepare(statement);
      • stmt->execute(rows);
      • stmt->free();
      • delete stmt ; delete con ; return 0;
      • }
      Table Creation
      • EXAMPLE : insert into T1 values(?,?) ;
      • // assumed that table T1 is already created with F1 integer and F2 char(20) fields.
      • // include the necessary header files
      • int main() {
      • // connect to the database and get the statement handle.
      • int rows; int id1 ; char name[20] ; // buffer
      • stmt->prepare(“insert itno T1 values( ? , ? ) ; ” ) ;
      • for( int i=0 ; i < 10 ; i++) {
      • con->beginTrans(); // transaction begins here
      • stmt->setIntParam( 1 , id1 ) ;
      • stmt->setStringParam( 2, name) ;
      • stmt->execute(rows) ;
      • con->commit() ; count++ ; id++;
      • }
      • stmt->free();
      • delete stmt ; delete con ; return 0;
      • }
      Table - Insert
      • EXAMPLE : select * from T1 ;
      • // assumed that Table T1 (F1 int, F2 char(20)) already created with some values.
      • // include the necessary header files
      • int main() {
      • // connect to the database and get the statement handle.
      • int rows; int id1 ; char name[20];
      • stmt->prepare(“select * from T1 ; ” ) ;
      • stmt->bindField( 1 , &id );
      • stmt->bindField( 2 , name );
      • con -> beginTrans( ); // transaction begins here
      • stmt->execute(rows) ;
      • while( stmt -> fetch( ) != NULL ) {
      • printf(“F1=%d F2=%s”, id1, name) ; count ++ ;
      • }
      • stmt->close(); stmt->commit();
      • stmt->free();
      • delete stmt ; delete con ; return 0;
      • }
      Table - Select
      • CREATED TABLE : T1( F1 int primary key, F2 int) ;
      • EXAMPLE : select * from T1 where F1= ? (0 to 99);
      • // include the necessary header files
      • int main() {
      • // prepare the statememnt and bind the two fields with ‘id’ and ‘id1’ variable.
      • int var1=0;
      • for( int i=0 ; i<100 ; i++) {
      • con->beginTrans(); // transaction begins here
      • var1 = i ;
      • setIntParam(1,var1) ;
      • stmt->execute(rows) ;
      • while( stmt -> fetch( ) != NULL ) {
      • printf(“F1=%d F2=%d”, id, id1) ; count ++ ;
      • }
      • stmt->close(); stmt->commit();
      • }
      • stmt->free();
      • delete stmt ; delete con ; return 0;
      • }
      Table – Select – Where - Parameter
      • CREATED TABLE : T1( F1 int , F2 char(20)) ;
      • EXAMPLE : update T1 set F1 = ? ;
      • // include the necessary header files
      • int main() {
      • stmt->prepare( “ update T1 set F1 = ?”;) ;
      • int var1 = 10;
      • for( int i=0 ; i<10 ; i++) {
      • con->beginTrans(); // transaction begins here
      • var1 ++ ;
      • stmt -> setIntParam(1,var1) ;
      • stmt->execute(rows) ;
      • stmt->commit();
      • }
      • stmt->free();
      • delete stmt ; delete con ; return 0;
      • }
      Table - Update
      • CREATED TABLE : T1( F1 int , F2 char(20)) ;
      • EXAMPLE : update T1 set F1 = ? ;
      • // include the necessary header files
      • int main() {
      • stmt->prepare( “ delete from T1 where F1 = ?”;) ; // f1=0,1,2…….9
      • int id = 0;
      • for( int i=0 ; i<10 ; i++) {
      • con->beginTrans(); // transaction begins here
      • stmt -> setIntParam(1 , id) ;
      • stmt->execute(rows) ;
      • stmt->commit();
      • id++ ;
      • }
      • stmt->free();
      • delete stmt ; delete con ; return 0;
      • }
      Table - Delete
      • Date is a non primptive data type.
      • Functions :
      • Date( int year , int month , int day )
      • int set( int year, int month, int day )
      • int get( int &year, int &month, int &day)
      • int dayOfMonth()
      • int month()
      • int year()
      • const char *monthName()
        • january, february,…
      • const char *dayOfWeekName()
      • Sunday, Monday, …
      • int parseFrom(const char *s)
      • Format : “mm/dd/yyyy”
      Date
      • CREATED TABLE : T1( F1 date) ;
      • EXAMPLE : insert into T1 values(?)
      • // include the necessary header files
      • int main() {
      • Date dtIn ;
      • dtIn . Set(2007,01,02) ;
      • stmt->prepare(“insert into T1 values(?) ; “) ;
      • con -> beginTrans() ;
      • stmt->setDateParam(1,dtIn) ;
      • stmt -> execute(rows) ;
      • con -> commit( ) ;
      • // close the connection.
      • return 0;
      • }
      Date - Insert
      • CREATED TABLE : T1( F1 date) .
      • EXAMPLE : select * from T1 ;
      • int main() {
      • // get the connection and connect to the database and get the statement handle
      • Date dtOut ;
      • stmt -> bindField( 1, dtOut ) ;
      • stmt->prepare(“ select * from T1 ; “) ;
      • con -> beginTrans() ;
      • stmt->execute(rows) ;
      • while( stmt -> fetch() !=NULL ) {
      • printf(“Year=%d Month=%d Day=%d” , dtOut.year() , dtOut.month() , dtOut. dayOfMonth() ) ;
      • }
      • stmt->close( ) ;
      • con -> commit( ) ;
      • // close the connection.
      • return 0;
      • }
      Date - Select
      • Time is a non primptive data type.
      • Functions :
      • Time( int hour , int mint , int secs, int usec=0 )
      • int set( int hour, int mint, int secs, int usec=0 )
      • int get( int &hour, int &mints, int &secs)
      • Int usec()
      • int seconds()
      • int minutes()
      • int hours()
      • int parseFrom(const char *s)
      • Format : “hh:mm:ss”
      Time
      • CREATED TABLE : T1( F1 time) ;
      • EXAMPLE : insert into T1 values(?)
      • // include the necessary header files
      • int main() {
      • Time inTime ;
      • inTime . Set(12,29,30) ;
      • stmt->prepare(“insert into T1 values(?) ; “) ;
      • con -> beginTrans() ;
      • stmt->setTimeParam(1 , inTime) ;
      • stmt -> execute(rows) ;
      • con -> commit( ) ;
      • // close the connection.
      • return 0;
      • }
      Time - Insert
      • CREATED TABLE : T1( F1 time) .
      • EXAMPLE : select * from T1 ;
      • int main() {
      • // get the connection and connect to the database and get the statement handle
      • Date outTime ;
      • stmt -> bindField( 1, outTime ) ;
      • stmt->prepare(“ select * from T1 ; “) ;
      • con -> beginTrans() ;
      • stmt->execute(rows) ;
      • while( stmt -> fetch() !=NULL ) {
      • printf(“Hour=%d Mimute=%d Second=%d” , outTime . hours() , outTime.minutes() , outTime. seconds() ) ;
      • }
      • stmt->close( ) ;
      • con -> commit( ) ;
      • // close the connection.
      • return 0;
      • }
      Time - Select
      • Below directories contain the test cases for SQLAPI.
      • $CSQL/examples/sqlapi/sqlapiexample.c
      • $CSQL/sqlapi/Connect/*.c
      • $CSQL/sqlapi/Select/*.c
      Date - Select