SlideShare a Scribd company logo
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

More Related Content

PPT
Executing Sql Commands
PPTX
C++11 - STL Additions
PPTX
C++11 Multithreading - Futures
PPT
Executing Sql Commands
PDF
spring-tutorial
PPT
Call Back
PPTX
Java script advance-auroskills (2)
PDF
Developing for Node.JS with MySQL and NoSQL
Executing Sql Commands
C++11 - STL Additions
C++11 Multithreading - Futures
Executing Sql Commands
spring-tutorial
Call Back
Java script advance-auroskills (2)
Developing for Node.JS with MySQL and NoSQL

What's hot (20)

DOCX
Memory management in c++
PDF
How Does Kubernetes Build OpenAPI Specifications?
ODP
Java Persistence API
PDF
Planet-HTML5-Game-Engine Javascript Performance Enhancement
PPT
Hibernate
PDF
Don't Make Android Bad... Again
PDF
Kotlin Developer Starter in Android projects
PDF
#29.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
PDF
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
PPTX
PL/SQL User-Defined Functions in the Read World
PDF
ADG Poznań - Kotlin for Android developers
PPTX
Oleksandr Valetskyy - DI vs. IoC
PDF
Demystifying AJAX Callback Commands in Drupal 8
PDF
[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...
KEY
Scala for scripting
PDF
Apache Commons - Don\'t re-invent the wheel
PDF
Scala coated JVM
PDF
Java9 Beyond Modularity - Java 9 más allá de la modularidad
PDF
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
PDF
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Memory management in c++
How Does Kubernetes Build OpenAPI Specifications?
Java Persistence API
Planet-HTML5-Game-Engine Javascript Performance Enhancement
Hibernate
Don't Make Android Bad... Again
Kotlin Developer Starter in Android projects
#29.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#36.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_재직자환급교육,실업자교육,국비지원교육, 자바교육,구...
PL/SQL User-Defined Functions in the Read World
ADG Poznań - Kotlin for Android developers
Oleksandr Valetskyy - DI vs. IoC
Demystifying AJAX Callback Commands in Drupal 8
[스프링/Spring교육학원,자바교육,근로자교육,실업자교육추천학원_탑크리에듀]#6.스프링프레임워크 & 마이바티스 (Spring Framew...
Scala for scripting
Apache Commons - Don\'t re-invent the wheel
Scala coated JVM
Java9 Beyond Modularity - Java 9 más allá de la modularidad
(국비지원학원/재직자교육/실업자교육/IT실무교육_탑크리에듀)#4.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Ad

Viewers also liked (7)

PPT
PPT
Kellogg Plastics
PPT
PPT
JDBC for CSQL Database
PPT
Facts: why the Pag canal isn't a good idea (Croatia tourism)
PPS
Navigator
PDF
ettamae.photos
Kellogg Plastics
JDBC for CSQL Database
Facts: why the Pag canal isn't a good idea (Croatia tourism)
Navigator
ettamae.photos
Ad

Similar to Sqlapi0.1 (20)

DOCX
Part APurposeThis laboratory provides some experience work.docx
PDF
DConf 2016 std.database (a proposed interface & implementation)
PDF
Advanced SQL - Database Access from Programming Languages
PDF
Orasta500.c
PPT
Slides11
PPT
Dbms & prog lang
PPT
PPT
A brief introduction to PostgreSQL
PPTX
Introduction to Structured Query Language
PPT
JDBC – Java Database Connectivity
PPTX
PostgreSQL Database Slides
PPTX
Database Access With JDBC
PPT
08 Dynamic SQL and Metadata
PPT
PDF
Fdms 1st cycle exp.pdf
PPT
Java Database Connectivity (JDBC) with Spring Framework is a powerful combina...
PDF
Java 1-contd
Part APurposeThis laboratory provides some experience work.docx
DConf 2016 std.database (a proposed interface & implementation)
Advanced SQL - Database Access from Programming Languages
Orasta500.c
Slides11
Dbms & prog lang
A brief introduction to PostgreSQL
Introduction to Structured Query Language
JDBC – Java Database Connectivity
PostgreSQL Database Slides
Database Access With JDBC
08 Dynamic SQL and Metadata
Fdms 1st cycle exp.pdf
Java Database Connectivity (JDBC) with Spring Framework is a powerful combina...
Java 1-contd

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Empathic Computing: Creating Shared Understanding
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Cloud computing and distributed systems.
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
sap open course for s4hana steps from ECC to s4
NewMind AI Weekly Chronicles - August'25 Week I
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Network Security Unit 5.pdf for BCA BBA.
Empathic Computing: Creating Shared Understanding
MIND Revenue Release Quarter 2 2025 Press Release
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Big Data Technologies - Introduction.pptx
Cloud computing and distributed systems.
Per capita expenditure prediction using model stacking based on satellite ima...
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4

Sqlapi0.1

  • 1. Jitendra Lenka Developer - Lakshya Solutions Ltd. [email_address] olutions.com CSQL - SQLAPI
  • 2. 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.
  • 3. 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
  • 4. 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?
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. Data Type Primptive Non-Primptive typeInt typeByteInt typeLongLong typeDate typeShort typeTime typeFloat typeTimeStamp typeDouble typeString
  • 14. 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
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. 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
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. 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
  • 24. 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
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. 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
  • 31. 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
  • 32. Below directories contain the test cases for SQLAPI. $CSQL/examples/sqlapi/sqlapiexample.c $CSQL/sqlapi/Connect/*.c $CSQL/sqlapi/Select/*.c Date - Select