How to Start SequoiaDB

Basic Operation

Data Model

Database Management








Release Note


  • Content
  • Comments
  • History

C++ Development Foundation

This section introduce how to use C++ client-driven interfaces to run C++ application.for simple, the following examples are not full code, only play an exemplary role. You can get the full code in the directory "/sequoiadb/client/samples/CPP", for more, please refer to online C++ API

Database operations

  • Connecting Database

    "connect.cpp" shows how to connect database. The file must contain the head file "client.hpp" and use namespace "sdbclient".

    #include <stdio.h>
    #include <iostream>
    #include "client.hpp"
    using namespace std ;
    using namespace sdbclient ;
    // Display Syntax Error
    void displaySyntax ( CHAR *pCommand ) ;
    INT32 main ( INT32 argc, CHAR **argv )
       // define a sdb object
       // use to connect to database
       sdb connection ;
       INT32 rc = SDB_OK ;
       // verify syntax
       if ( 5 != argc )
          displaySyntax ( (CHAR*)argv[0] ) ; 
          exit ( 0 ) ;
       // read argument
       CHAR *pHostName = (CHAR*)argv[1] ;
       UINT16 Port = atoi(argv[2]) ;
       CHAR *pUsr = (CHAR*)argv[3] ;
       CHAR *pPasswd = (CHAR*)argv[4] ;
       // connect to database
       rc = connection.connect ( pHostName, Port, pUsr, pPasswd ) ;
       if( rc!=SDB_OK )
          cout << "Fail to connet to database, rc = " << rc << endl ;
          goto error ;
          cout << "connect success!" << endl ;
       //disconnect from database
       connection.disconnect() ;
       return 0 ;
       goto done ;
    //display syntax Error
    void displaysyntax ( CHAR *pcommand )
       cout << "syntax:" << pcommand << " < host >< name >< servicename >
          < username >< password >" << endl ;

    In Linux, you can compile and link the dynamic library "libsdbcpp.so" like this:

    $ gcc -o connect connect.cpp -I <path>/sequoiadb/client/CPP/include -lsdbcpp -L <path>/sequoiadb/client/CPP/lib
    Execution results: $ ./connect localhost 11810 "" ""
    connect success!

    This sample connects to the port "11810" of local database, usename and password are null, users can configure params according to needs. For example, when the user have created usename and password, you must use the correct usename and password to connect the database.

  • Create a collection of space and set.
    // First of all, the definition of set space, a collection of object
    sdbCollectionSpace collectionspace ;
    sdbCollection collection ;
    // Create collection space "foo"
    rc = connection.createCollectionSpace ( "foo", SDB_PAGESIZE_4K, collectionspace ) ;
    // Create the collection in the new collection space "bar"
    rc = collectionspace.createCollection ( "bar", collection ) ;

    Create a name for the "foo" collection space and a name for the "bar" collection, collection of pages of data set size space for 4K. Can choose according to the actual situation of different size of data pages. Create the collection, the collection do CURD operations.


    In crating a collection of "bar" and no additional partitions, compression and other information, please refer to C++ API

  • Inserting Data
    // Firstly, a BSON object is created bson obj;
    BSONObj obj ; obj = BSON ( "name" << "tom" << "age" << 24 ) ;
    // Then, insert it into a collection
    collection.insert ( &obj ) ;

    obj is inputed param and inserted data.

  • Query
    // Define a cursor object
    sdbCursor cursor ;
    // Search for all records and put the results in the cursor object
    collection.query ( cursor ) ;
    // Show every record in cursor
    while( !( rc=cursor.next( obj ) )
       cout << obj.toString() << endl ;

    In a query, a cursor object is used to store the result set of a query . You can get results by manipulating the cursor. This sample uses the next interface of cursor manipulation to get one record in the result set. This sample does not set querying conditions, filtering conditions and ordering, only use default index.

  • Index
    #define INDEX_NAME "index"
    // Firstly we create a bson that contains the information of the index.
    BSONObj obj ;
    obj = BSON ( "name" << 1 << "age" << -1 ) ;
    // Create a "name" as "age" for the ascending, descending index.
    collection.createIndex ( obj, INDEX_NAME, FALSE, FALSE ) ;

    Here, we create an index in the collection specified by the collection object collection . It is in ascending order on "name" and descending order on "age"

  • Update
    // Create a BSON object that contains updating rules
    BSONObj rule = BSON ( "$set" << BSON ( "age" << 19 ) ) ;
    // Print updating rule.
    cout << rule.toString() << endl ;
    // Update records.
    collection.update( rule ) ;

    Here, as no record matching conditions have specified, then this example will update all records in the collection which collection handle specified.

Cluster Operations

  • Replica group Operations

    Replica group Operations contains creating Replica groups(sdbCreateGroup), getting Replica group handles(sdbGetGroup), starting Replica group(sdbStartGroup) and stopping Replica group(sdbStopGroup). The following shows the Replica group Operations, and real application should include error detecting, etc.

    // define a Replica group Instance
    sdbReplicaGroup rg ;
    // define a null map object,it means that no more configuration information when create data nodes
    map<string,string> config ;
    // create a catalog Replica group at first
    connection.createCataReplicaGroup ( HOST_NAME, SERVICE_NAME, CATALOG_SHARD_PATH, NULL ) ;
    // create data Replica group
    connection.createRG ( REPLICA_SHARD_NAME, rg ) ;
    // create data nodes
    rg.createNode ( HOST_NAME1, SERVICE_NAME1, DATABASE_PATH1, config ) ;
    // start Replica group
    rg.start () ;
  • Data Node Operations

    Data Node Operations contains create data node(sdbReplicaGroup::createNode), get master data node(sdbReplicaGroup::getMaster), get slave data node(sdbReplicaGroup::GetSlave), start data node (sdbNode::Start) and stop data node(sdbNode::Stop), etc. The following shows the Data Node Operations, and real application should include error detecting, etc.

    // define a data node instance
    sdbNode masternode ;
    sdbNode slavenode ;
    // get master data node
    rg.getMaster( masternode ) ;
    //get slave data node
    rg.getSlave( slavenode ) ;
please login to comment.
Latest Comment
  • 2015-03-14

About Us

SequoiaDB is a financial-level distributed database vendor and is the first Chinese database listed in Gartner’s Magic Quadrant OPDBMS report. SequoiaDB has recently released version 3.0.
SequoiaDB is now penetrating the vertical sector Financial Industry quickly and had more than 50 banking clients and hundreds of enterprise customers in industries including government, telecommunication, Internet and IoT.

Tower R, No.8 North Star East Road, Chaoyang District, Beijing,China
Tower A, No.22 Qinglan Street, Panyu District, Guangzhou,China
Tsing Hua Tech Park, Nanshan District, Shenzhen,China