文档

关于 SequoiaDB

快速入门

安装

基本操作

数据模型

SQL引擎

FileSystem引擎

S3引擎

系统架构

数据库管理

连接器

驱动

参考手册

故障排除

SAC 管控中心

Web服务

版本信息

SQL to SequoiaDB shell to C++

SequoiaDB 的查询用 json(bson)对象表示,下表以例子的形式显示了 SQL 语句,SequoiaDB shell 语句和 SequoiaDB C++ 驱动程序语法之间的对照。

SQL SequoiaDB shell C++ Driver
insert into bar( a, b ) values( 1, -1 ) db.foo.bar.insert( { a: 1, b: -1 } ) sdbCollection collection ;
BSONObj obj = BSON( "a" << 1 << "b" << -1 ) ;
collection.insert( obj ) ;
select a,b from bar db.foo.bar.find( null, { a: "", b: "" } ) sdbCollection collection ;
sdbCursor cursor ;
BSONObj selected ;
BSONObj obj ;
selected = BSON( "a"<<""<<"b"<<"" ) ;
collection .query( cursor, obj, selected ) ;
select * from bar db.foo.bar.find() sdbCollection collection ;
sdbCursor cursor ;
collection.query ( cursor ) ;
select * from bar where age=20 db.foo.bar.find( { age: 20 } ) sdbCollection collection ;
sdbCursor cursor ;
BSONObj condition ;
condition = BSON( "age" << 20 ) ;
collection .query ( cursor, condition ) ;
select * from bar where age=20 order by name db.foo.bar.find( { age: 20 } ).sort( { name: 1 } ) sdbCollection collection ;
sdbCursor cursor ;
BSONObj obj ;
BSONObj condition ;
BSONObj orderBy ;
condition = BSON( "age"<<20 ) ;
orderBy = BSON( "name"<<1 ) ;
collection.query( cursor, condition, obj, orderBy, obj ) ;
select * from bar where age > 20 and age < 30 db.foo.bar.find( { age: { $gt: 20, $lt: 30 } } ) sdbCollection collection ;
sdbCursor cursor ;
BSONObj condition ;
condition = BSON( "age" << BSON( "$gt" << 20 << "$lt" << 30 ) ) ;
collection.query( cursor, condition ) ;
create index testIndex on bar( name ) db.foo.bar.createIndex( "testIndex", { name: 1 }, false ) sdbCollection collection ;
BSONObj obj ;
obj = BSON( "name"<<1 ) ;
collection.createIndex ( obj, "testIndex", FALSE, FALSE );
select * from bar limit 20 offset 10 db.foo.bar.find().limit( 20 ).skip( 10 ) sdbCollection collection ;
BSONObj obj ;
sdbCursor cursor ;
collection .query( cursor,obj, obj, obj, obj, 10, 20 ) ;
select count(*) from bar where age > 20 db.foo.bar.find( { age: { $gt: 20 } } ).count() sdbCollection collection ;
SINT64 count = 0 ;
BSONObj condition ;
condition = BSON( "age" << BSON( "$gt" << 20 ) ) ;
collection.getCount( count, condition ) ;
update bar set a=2 where b=-1 db.foo.bar.update( { $set: { a: 2 } }, { b: -1 } ) sdbCollection collection ;
BSONObj condition = BSON( "b"<<-1 ) ;
BSONObj rule = BSON( "$set" << BSON( "a" << 2 ) );
BSONObj obj ;
collection.update ( rule, condition, obj ) ;
delete from bar where a=1 db.foo.bar.remove( { a: 1 } ) sdbCollection collection ;
BSONObj condition = BSON( "a"<<1 ) ;
collection.del ( condition ) ;
回到顶部