Jitendra Lenka Developer - Lakshya Solutions Ltd. [email_address] olutions.com CSQL -  SQLAPI
Module Objectives <ul><li>After completing this module you will be able to : </li></ul><ul><li>Understand various interfac...
<ul><li>The topics to be covered in this session are :- </li></ul><ul><li>Introduction to CSQL main memory database cache....
<ul><li>CSQL Database,  which comprises suite of products such as Main Memory Database with complete ACID properties, Cach...
<ul><li>Referenced Manuals: </li></ul><ul><li>User Manual:  Describes Concept, components and basic usages and useful for ...
<ul><li>ODBC C/C++  standard interface for SQL engine. </li></ul><ul><li>JDBC Java standard interface for SQL engine. </li...
<ul><li>Proprietary  C++ Interface </li></ul><ul><li>Important classes </li></ul><ul><ul><li>SqlFactory  -  create appropr...
<ul><li>DbRetVal  :  This enum is defined in  ErrorType.h  file and contain all the error codes returned by all the functi...
<ul><li>This class is the entry point to access the database  through the SQL engine.Each </li></ul><ul><li>connection has...
<ul><li>This class is the entry point to access the database  through the SQL engine.Each </li></ul><ul><li>connection has...
<ul><li>This class is to create appropriate implementation of SQLAPI. </li></ul><ul><li>Member Functions : </li></ul><ul><...
<ul><li>EXAMPLE :  Below snippet code shows how to open and close a connection. </li></ul><ul><li>#include<AbsSqlConnectio...
Data Type Primptive Non-Primptive typeInt typeByteInt typeLongLong typeDate typeShort typeTime typeFloat typeTimeStamp typ...
<ul><li>This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from th...
<ul><li>This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from th...
<ul><li>This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from th...
<ul><li>This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from th...
<ul><li>This class is working as a handle to the SqlStatement. It is used to execute queries and return the values from th...
<ul><li>EXAMPLE :  commit or rollback a transaction. </li></ul><ul><li>// include the necessary header files </li></ul><ul...
<ul><li>EXAMPLE :  create table emp( eid int, ename  char(20), doj date) ; </li></ul><ul><li>// include the necessary head...
<ul><li>EXAMPLE :  insert into T1 values(?,?) ; </li></ul><ul><li>//  assumed that table T1 is already created with F1 int...
<ul><li>EXAMPLE :  select * from T1 ; </li></ul><ul><li>//  assumed  that  Table T1 (F1 int, F2  char(20)) already created...
<ul><li>CREATED TABLE  :  T1( F1 int  primary key,  F2 int) ;  </li></ul><ul><li>EXAMPLE  :  select * from T1  where F1= ?...
<ul><li>CREATED TABLE  :  T1( F1 int  ,  F2  char(20)) ;  </li></ul><ul><li>EXAMPLE  :  update T1 set F1 = ? ; </li></ul><...
<ul><li>CREATED TABLE  :  T1( F1 int  ,  F2  char(20)) ;  </li></ul><ul><li>EXAMPLE  :  update T1 set F1 = ? ; </li></ul><...
<ul><li>Date is a non primptive data type. </li></ul><ul><li>Functions : </li></ul><ul><li>Date( int  year , int  month , ...
<ul><li>CREATED TABLE  :  T1( F1  date) ;  </li></ul><ul><li>EXAMPLE  :  insert into T1 values(?) </li></ul><ul><li>// inc...
<ul><li>CREATED TABLE  :  T1( F1  date) . </li></ul><ul><li>EXAMPLE  :  select * from T1 ; </li></ul><ul><li>int  main() {...
<ul><li>Time is a non primptive data type. </li></ul><ul><li>Functions : </li></ul><ul><li>Time( int  hour , int  mint , i...
<ul><li>CREATED TABLE  :  T1( F1  time) ;  </li></ul><ul><li>EXAMPLE  :  insert into T1 values(?) </li></ul><ul><li>// inc...
<ul><li>CREATED TABLE  :  T1( F1  time) . </li></ul><ul><li>EXAMPLE  :  select * from T1 ; </li></ul><ul><li>int  main() {...
<ul><li>Below directories contain the test cases for SQLAPI. </li></ul><ul><li>$CSQL/examples/sqlapi/sqlapiexample.c </li>...
Upcoming SlideShare
Loading in...5
×

Sqlapi0.1

484

Published on

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

Published in: Technology, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
484
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Sqlapi0.1

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

    Clipping is a handy way to collect important slides you want to go back to later.

×