v1.10

Document

How to Start SequoiaDB

Basic Operation

Data Model

Database Management

Aggregation

Index

Replication

Cluster

Connector

Reference

Development

Release Note

FAQ

  • Content
  • Comments
  • History

SQL to SequoiaDB shell to C

The query in Sequoiadb is in the format of json(bson). The following table shows examples comparing sql statements, sequoiadb shell statements and sequoiadb C driver application statements.

SQL SequoiaDB shell C Driver
insert into students(a,b) values(1,-1) db.foo.bar.insert({a:1,b:-1}) const char *r ="{a:1,b:-1}" ;

// JsonToBso transforms a json string into a bson object

jsonToBson ( &obj, r ) ;

// Collection is the handle of collection bar

sdbInsert (collection, &obj ) ;

select a,b from students db.foo.bar.find(null,{a:"",b:""}) const char *r ="{a:"",b:""}" ;

// JsonToBso transforms a json string into bson object

jsonToBson ( & select, r ) ;

// Collection is the handle of collection bar. Cursor is the handle that returns query results.

sdbQuery ( collection, NULL, &select, NULL, NULL, 0, -1, cursor ) ;

select * from students db.foo.bar.find() // Collection is the handle of collection bar.Cursor is the handle that returns query results.

sdbQuery ( collection, NULL, NULL, NULL, NULL, 0, -1, cursor ) ;

select * from students where age=20 db.foo.bar.find({age:20}) const char *r ="{age:20}";

// JsonToBso transforms a json string into a bson object.

jsonToBson ( &condition, r ) ;

// Collection is the handle of collection bar. Cursor is the handle that returns query results.

sdbQuery ( collection, & condition, NULL, NULL, NULL, 0, -1, cursor ) ;

select * from students where age=20 order by name db.foo.bar.find({age:20}).sort({name:1}) const char *r1 ="{age:20}" ;

const char *r2 ="{name:1}" ;

// JsonToBso transforms a json string into a bson object

jsonToBson ( & condition, r1 ) ;

jsonToBson ( &orderBy, r2 ) ;

// Collection is the handle of collection bar. Cursor is the handle that returns query results.

sdbQuery ( collection, & condition, NULL, & orderBy, NULL, 0, -1, cursor ) ;

select * from students where age>20 and age<30 db.foo.bar.find({age:{$gt:20,$lt:30}}) const char *r ="{age:{$gt:20,$lt:30}}" ;

// JsonToBso transforms a json string into a bson object

jsonToBson ( &condition, r ) ;

// Collection is the handle of collection bar. Cursor is the handle that returns query results.

sdbQuery ( collection, & condition, NULL, NULL, NULL, 0, -1, cursor ) ;

create index testIndex on students(name) db.foo.bar.createIndex("testIndex",{name:1},false) const char *r ="{name:1}" ;

// jsonToBso transforms a json string into a bson object

jsonToBson ( &obj, r ) ;

// Collection is the handle of collection bar

sdbCreateIndex ( collection, &obj, "testIndex", FALSE, FALSE )

select * from students limit 20 skip 10 db.foo.bar.find().limit(20).skip(10) // Collection is the handle of collection bar. Cursor is the handle that returns query results.

sdbQuery ( collection, NULL, NULL, NULL, NULL, 10, 20, cursor ) ;

select count(*) from students where age>20 db.foo.bar.find({age:{$gt:20}}).count() const char *r ="{age:{$gt:20}}" ;

// jsonToBson transforms a json string into a bson object

jsonToBson ( &condition, r ) ;

// Collection is the handle of collection bar. Count is the total amount of results.

sdbGetCount ( collection, & condition, &count );

update students set a=a+2 where b=-1 db.foo.bar.update({$set:{a:2}},{b:-1}) const char *r1 ="{$set:{a:2}}" ;

const char *r2 =”{b:-1}” ;

// jsonToBso transforms a json string into a bson object

jsonToBson ( &rule, r1 ) ;

jsonToBson ( &condition, r2 ) ;

// Collection is the handle of collection bar.

sdbUpdate (collection, &rule, &condition, NULL ) ;

delete from students where a=1 db.foo.bar.remove({a:1}) const char *r ="{a:1}" ;

// jsonToBso transforms a json string into a bson object

jsonToBson ( &condition, r ) ;

// Collection is the handle of collection bar.

sdbDelete ( collection, & condition, NULL ) ;
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.

Beijing:
Tower R, No.8 North Star East Road, Chaoyang District, Beijing,China
Guangzhou:
Tower A, No.22 Qinglan Street, Panyu District, Guangzhou,China
Shenzhen:
Tsing Hua Tech Park, Nanshan District, Shenzhen,China
Tel:400-8038-339
E-mail:contact@sequoiadb.com