SequoiaDB
 All Classes Files Functions Variables Pages
Public Member Functions | Public Attributes | List of all members
SequoiaCL Class Reference

Public Member Functions

 drop ()
 
 alter (array|string $options)
 
 enableSharding (array|string $options)
 
 disableSharding ()
 
 enableCompression (array|string $options)
 
 disableCompression ()
 
 setAttributes (array|string $options)
 
 split (string $sourceGroup, string $targetGroup, integer|double $percent)
 
 split (string $sourceGroup, string $targetGroup, array|string $condition, array|string $endCondition=null)
 
 splitAsync (string $sourceGroup, string $targetGroup, integer|double $percent)
 
 splitAsync (string $sourceGroup, string $targetGroup, array|string $condition, array|string $endCondition=null)
 
 getFullName ()
 
 getCSName ()
 
 getName ()
 
 attachCL (string $subClFullName, array|string $options)
 
 detachCL (string $subClFullName)
 
 createAutoIncrement (array|string $field)
 
 dropAutoIncrement (array|string $field)
 
 insert (array|string $record, integer $flags=SDB_FLG_INSERT_RETURN_OID)
 
 bulkInsert (array|string $records, integer $flags=0)
 
 remove (array|string $condition=null, array|string $hint=null)
 
 update (array|string $rule, array|string $condition=null, array|string $hint=null, integer $flag=0)
 
 upsert (array|string $rule, array|string $condition=null, array|string $hint=null, array|string $setOnInsert=null, integer $flag=0)
 
 find (array|string $condition=null, array|string $selector=null, array|string $orderBy=null, array|string $hint=null, integer $numToSkip=0, integer $numToReturn=-1, integer $flag=0)
 
 findAndUpdate (array|string $rule, array|string $condition=null, array|string $selector=null, array|string $orderBy=null, array|string $hint=null, integer $numToSkip=0, integer $numToReturn=-1, integer $flag=0, boolean $returnNew=false)
 
 findAndRemove (array|string $condition=null, array|string $selector=null, array|string $orderBy=null, array|string $hint=null, integer $numToSkip=0, integer $numToReturn=-1, integer $flag=0)
 
 explain (array|string $condition=null, array|string $selector=null, array|string $orderBy=null, array|string $hint=null, integer $numToSkip=0, integer $numToReturn=-1, integer $flag=0, array|string $options=null)
 
 count (array|string $condition=null, array|string $hint=null)
 
 aggregate (array|string $aggrObj)
 
 createIndex (array|string $indexDef, string $indexName, array|string $options)
 
 createIndex (array|string $indexDef, string $indexName, boolean $isUnique=false, boolean $isEnforced=false, integer $sortBufferSize=64)
 
 dropIndex (string $indexName)
 
 getIndexes ()
 
 getIndexInfo (string $name)
 
 createIdIndex (array|string $args=null)
 
 dropIdIndex ()
 
 openLob (string $oid, integer $mode)
 
 removeLob (string $oid)
 
 truncateLob (string $oid, integer|SequoiaINT64 $length)
 
 listLob (array|string $condition=null, array|string $selector=null, array|string $orderBy=null, array|string $hint=null, integer $numToSkip=0, integer $numToReturn=-1)
 
 listLobPieces (array|string $condition=null, array|string $selector=null, array|string $orderBy=null, array|string $hint=null, integer $numToSkip=0, integer $numToReturn=-1)
 
 createLobID (string $time="")
 
 getCollectionName ()
 
 deleteIndex ()
 
 getIndex (string $indexName="")
 

Public Attributes

const SDB_FLG_INSERT_CONTONDUP 0x00000001
 
const SDB_FLG_INSERT_REPLACEONDUP 0x00000004
 
const SDB_FLG_INSERT_RETURN_OID 0x10000000
 
const SDB_FLG_FIND_FORCE_HINT 0x00000080
 
const SDB_FLG_FIND_PARALLED 0x00000100
 
const SDB_FLG_FIND_WITH_RETURNDATA 0x00000200
 
const SDB_FLG_QUERY_FORCE_HINT 0x00000080
 
const SDB_FLG_QUERY_PARALLED 0x00000100
 
const SDB_FLG_QUERY_WITH_RETURNDATA 0x00000200
 
const SDB_FLG_QUERY_PREPARE_MORE 0x00004000
 
const SDB_FLG_QUERY_KEEP_SHARDINGKEY_IN_UPDATE 0x00008000
 
const SDB_FLG_QUERY_FOR_UPDATE 0x00010000
 
const SDB_FLG_UPDATE_KEEP_SHARDINGKEY 0x00008000
 
const SDB_LOB_CREATEONLY 0x00000001
 
const SDB_LOB_READ 0x00000004
 
const SDB_LOB_WRITE 0x00000008
 
const SDB_LOB_SHAREREAD 0x00000040
 

Detailed Description

SequoiaCL Class. To get this Class object must be call SequoiaDB::getCL or SequoiaCS::selectCL or SequoiaCS::getCL.

Class for create an object of the collection

Member Function Documentation

SequoiaCL::aggregate ( array|string  $aggrObj)

Execute aggregate operation in specified collection.

Parameters
$aggrObjan array or the string argument. Aggregation parameter, if the input string or an array, you can enter only one parameter, such as the string:
'{ "$project": { "field": 1 } }'
an associative array:
array( '$project' => array ( 'field' => 1 ) )
if the input array, you can enter multiple parameters, such as:
array ( '{ "$project": { "field1": 1, "field2": 2 } }', '{ "$project": { "field1": 1 } }' )
or
array ( array ( '$project' => array ( 'field1' => 1, 'field2' => 2 ) ), array ( '$project' => array ( 'field1' => 1 ) ) )
Returns
Returns a new SequoiaCursor object.
Return values
SequoiaCursorObject

Example:

$cursor = $cl -> aggregate( array ( array ( '$project' => array ( 'field1' => 1, 'field2' => 2 ) ), array ( '$project' => array ( 'field1' => 1 ) ) ) ) ;
if( empty( $cursor ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to call aggregate, error code: ".$err['errno'] ;
return ;
}
while( $record = $cursor -> next() ) {
var_dump( $record ) ;
}
SequoiaCL::alter ( array|string  $options)

Alter collection options.

Parameters
$optionsan array or the string argument. The options are as following:
ReplSize : Assign how many replica nodes need to be synchronized when a write request(insert, update, etc) is executed
ShardingKey : Assign the sharding key
ShardingType : Assign the sharding type
Partition : When the ShardingType is "hash", need to assign Partition, it's the bucket number for hash, the range is [2^3,2^20]
CompressionType : The compression type of data, could be "snappy" or "lzw"
EnsureShardingIndex : Assign to true to build sharding index
StrictDataMode : Using strict date mode in numeric operations or not
e.g. array( "RepliSize" => 0, "ShardingKey" => array( "a" => 1 ), "ShardingType" => "hash", "Partition" =>1024 )
AutoIncrement : Assign attributes of an autoincrement field or batch autoincrement fields.
e.g. array( "AutoIncrement" => array( "Field" => "a", "MaxValue" => 2000 ) )
array( "AutoIncrement" => array( array( "Field" => "a", "MaxValue" => 2000 ), array( "Field" => "a", "MaxValue" => 4000 ) ) )
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Alter collection option ReplSize

$err = $cl -> alter( array( 'ReplSize' => -1 ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to alter collection options, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::attachCL ( string  $subClFullName,
array|string  $options 
)

Attach the specified collection.

Parameters
$subClFullNamethe string argument. The name of the subcollection.
$optionsan array or the string argument. The low boudary and up boudary eg:
array( 'LowBound' => array( '<key>' => <value> ), 'UpBound' => array( '<key>' => <value> ) )
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: 2 collections have been created, one of which is a vertival partition.

$err = $veticalCL -> attachCL( 'cs.normalCL', array( 'LowBound' => array( 'id' => 0 ), 'UpBound' => array( 'id' => 100 ) ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to attach collection, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::bulkInsert ( array|string  $records,
integer  $flags = 0 
)

Insert records into current collection.

Parameters
$recordsan array or the string argument. The inserted record, cannot be empty.
$flagsan integer argument.
0 : while 0 is set, database will stop inserting
when the record hit index key duplicate error.
SDB_FLG_INSERT_CONTONDUP : if the record hit index key duplicate error,
database will skip them and go on inserting.
SDB_FLG_INSERT_RETURN_OID : return the value of "_id" field in the record.
SDB_FLG_INSERT_REPLACEONDUP : if the record hit index key duplicate error,
database will replace the existing record by
the inserting new record and then go on inserting.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Insert an array record

$err = $cl -> bulkInsert( array( 'a' => 1 ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to insert records, error code: ".$err['errno'] ;
return ;
}

Example: Insert the json string

$err = $cl -> bulkInsert( '{ "a": 2 }' ) ;
if( $err['errno'] != 0 ) {
echo "Failed to insert records, error code: ".$err['errno'] ;
return ;
}

Example: Insert multiple records

$records = array(
array( 'a' => 3 ),
array( 'a' => 4 ),
array( 'a' => 5 ),
array( 'a' => 6 ),
array( 'a' => 7 ),
'{ "a": 8 }',
'{ "a": 9 }',
'{ "a": 10 }',
'{ "a": 11 }',
'{ "a": 12 }'
) ;
$err = $cl -> bulkInsert( $records ) ;
if( $err['errno'] != 0 ) {
echo "Failed to insert records, error code: ".$err['errno'] ;
return ;
}

Example: Set $flags SDB_FLG_INSERT_CONTONDUP

$records = array(
array( 'a' => 3 ),
array( 'a' => 4 ),
array( 'a' => 5 ),
array( 'a' => 6 ),
array( 'a' => 7 ),
'{ "a": 8 }',
'{ "a": 9 }',
'{ "a": 10 }',
'{ "a": 11 }',
'{ "a": 12 }'
) ;
$err = $cl -> bulkInsert( $records, SDB_FLG_INSERT_CONTONDUP ) ;
if( $err['errno'] != 0 ) {
echo "Failed to insert records, error code: ".$err['errno'] ;
return ;
}

Example: Set $flags SDB_FLG_INSERT_RETURN_OID

$records = array(
array( 'a' => 3 ),
array( 'a' => 4 ),
array( 'a' => 5 )
) ;
$err = $cl -> bulkInsert( $records, SDB_FLG_INSERT_RETURN_OID ) ;
if( $err['errno'] != 0 ) {
echo "Failed to insert records, error code: ".$err['errno'] ;
return ;
}
var_dump( $err ) ;
Print $err is
array(2) {
["_id"]=>
array(3) {
[0]=>
object(SequoiaID)#4 (1) {
["$oid"]=>
string(24) <24 hexadecimal characters>
}
[1]=>
object(SequoiaID)#5 (1) {
["$oid"]=>
string(24) <24 hexadecimal characters>
}
[2]=>
object(SequoiaID)#6 (1) {
["$oid"]=>
string(24) <24 hexadecimal characters>
}
}
["errno"]=>
int(0)
}
SequoiaCL::count ( array|string  $condition = null,
array|string  $hint = null 
)

Get the count of records in specified collection.

Parameters
$conditionan array or the string argument. The matching rule, return the count of all records if this parameter is null.
$hintan array or the string argument. The hint, automatically match the optimal hint if null.
Returns
Returns the number of records matching the query.
Return values
integer|SequoiaINT64Records number

Example:

$recordNum = $cl -> count() ;
if( $recordNum < 0 ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to call count, error code: ".$err['errno'] ;
return ;
}
echo "Collection records number: ".$recordNum ;
SequoiaCL::createAutoIncrement ( array|string  $field)

Create autoincrement field on collection

Parameters
$fieldan array or the string argument. The arguments of field. e.g. array( 'Field' => 'a', 'MaxValue' => 2000 )
Field : The name of autoincrement field
StartValue : The start value of autoincrement field
MinValue : The minimum value of autoincrement field
MaxValue : The maxmun value of autoincrement field
Increment : The increment value of autoincrement field
CacheSize : The cache size of autoincrement field
AcquireSize : The acquire size of autoincrement field
Cycled : The cycled flag of autoincrement field
Generated : The generated mode of autoincrement field
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> createAutoIncrement( array( 'Field' => 'a', 'MaxValue' => 2000 ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to create auto increment, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::createIdIndex ( array|string  $args = null)

Create $id index in collection.

Parameters
$argsan array or the string argument. The arguments of creating id index. set it as null if no args. e.g. array( 'SortBufferSize' => 64 )
SortBufferSize : The size of sort buffer used when creating index, the unit is MB,
zero means don't use sort buffer
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> createIdIndex( array( 'SortBufferSize' => 64 ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to create id index, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::createIndex ( array|string  $indexDef,
string  $indexName,
array|string  $options 
)

Create the index in current collection.

Parameters
$indexDefan array or the string argument. The index element. e.g. array( 'name' => 1, 'age' => -1 )
$indexNamethe string argument. The index name.
$optionsan array or the string argument. The options are as below:
Unique: Whether the index elements are unique or not
Enforced: Whether the index is enforced unique. This element is meaningful when Unique is true
NotNull: Any field of index key should exist and cannot be null when NotNull is true
SortBufferSize: The size of sort buffer used when creating index. Unit is MB. Zero means don't use sort buffer
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> createIndex( array( 'name' => 1, 'age' => -1 ), "myIndex", array( 'Unique' => true, 'NotNull' => true ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to create index, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::createIndex ( array|string  $indexDef,
string  $indexName,
boolean  $isUnique = false,
boolean  $isEnforced = false,
integer  $sortBufferSize = 64 
)

Create the index in current collection.

Parameters
$indexDefan array or the string argument. The index element. e.g. array( 'name' => 1, 'age' => -1 )
$indexNamethe string argument. The index name.
$isUniquea boolean argument. Whether the index elements are unique or not,default is false.
$isEnforceda boolean argument. Whether the index is enforced unique This element is meaningful when isUnique is set to true.
$sortBufferSizean integer argument. The size of sort buffer used when creating index, the unit is MB, zero means don't use sort buffer.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> createIndex( array( 'name' => 1, 'age' => -1 ), "myIndex" ) ;
if( $err['errno'] != 0 ) {
echo "Failed to create index, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::createLobID ( string  $time = "")

Create a lob ID.

Parameters
$timethe string argument. Timestamp(format:YYYY-MM-DD-HH.mm.ss). if Timestamp is empty string, the Timestamp will be generated by server.
Returns
Returns The object id.
Return values
stringlob id

Example:

echo $cl -> createLobID() ;
SequoiaCL::deleteIndex ( )

Delete $id index in collection.

See Also
dropIndex().
Deprecated:
This function is deprecated, use the function dropIndex() instead.
SequoiaCL::detachCL ( string  $subClFullName)

Detach the specified collection.

Parameters
$subClFullNamethe string argument. The name of the subcollection.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: 2 collections have been created, one of which is a vertival partition and attach collection.

$err = $veticalCL -> detachCL( 'cs.normalCL' ) ;
if( $err['errno'] != 0 ) {
echo "Failed to detach collection, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::disableCompression ( )

Alter collection to disable compression.

Parameters
$optionsan array or the string argument. New collection options.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Alter collection to disable compression

$err = $cl -> disableCompression() ;
if( $err['errno'] != 0 ) {
echo "Failed to alter collection options, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::disableSharding ( )

Alter collection to disable sharding.

Parameters
$optionsan array or the string argument. New collection options.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Alter collection to disable sharding

$err = $cl -> disableSharding() ;
if( $err['errno'] != 0 ) {
echo "Failed to alter collection options, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::drop ( )

Drop collection.

Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Drop collection

$err = $cl -> drop() ;
if( $err['errno'] != 0 ) {
echo "Failed to drop collection, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::dropAutoIncrement ( array|string  $field)

Drop autoincrement field on collection

Parameters
$fieldan array or the string argument. The arguments of field. e.g. array( 'Field' => 'a' )
Field : The name of autoincrement field
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> dropAutoIncrement( array( 'Field' => 'a' ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to drop auto increment, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::dropIdIndex ( )

Drop $id index in collection.

Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> dropIdIndex() ;
if( $err['errno'] != 0 ) {
echo "Failed to drop id index, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::dropIndex ( string  $indexName)

Drop the index in current collection.

Parameters
$indexNamethe string argument. The index name.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> dropIndex( "myIndex" ) ;
if( $err['errno'] != 0 ) {
echo "Failed to drop index, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::enableCompression ( array|string  $options)

Alter collection to enable compression.

Parameters
$optionsan array or the string argument. New collection options.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Alter collection to enable compression

$err = $cl -> enableCompression( array( 'CompressionType' => 'lzw' ) ;
if( $err['errno'] != 0 ) {
echo "Failed to alter collection options, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::enableSharding ( array|string  $options)

Alter collection to enable sharding.

Parameters
$optionsan array or the string argument. New collection options.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Alter collection to enable sharding

$err = $cl -> enableSharding( array( 'ShardingKey' => array( 'a' => 1 ) ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to alter collection options, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::explain ( array|string  $condition = null,
array|string  $selector = null,
array|string  $orderBy = null,
array|string  $hint = null,
integer  $numToSkip = 0,
integer  $numToReturn = -1,
integer  $flag = 0,
array|string  $options = null 
)

Get access plan of query

Parameters
$conditionan array or the string argument. The matching rule, return all the record if null.
$selectoran array or the string argument. The selective rule, return the whole record if null.
$orderByan array or the string argument. The ordered rule, never sort if null.
$hintan array or the string argument. The hint, automatically match the optimal hint if null.
$numToSkipan integer argument. Skip the first numToSkip records, never skip if this parameter is 0.
$numToReturnan integer argument. Only return numToReturn records, return all if this parameter is -1.
$flagan integer argument. The query flag, default to be 0.
SDB_FLG_QUERY_FORCE_HINT(0x00000080) : Force to use specified hint to query, if database have no index assigned by the hint, fail to query
SDB_FLG_QUERY_PARALLED(0x00000100) : Enable paralled sub query
SDB_FLG_QUERY_WITH_RETURNDATA(0x00000200) : In general, query will not return data until cursor get from database,
when add this flag, return data in query response, it will be more high-performance
$optionsan array or the string argument. The rules of explain, the options are as below:
Run: Whether execute query explain or not, true for excuting query explain then get
the data and time information; false for not excuting query explain but get the
query explain information only.
e.g. array( 'run' => true )
Returns
Returns a new SequoiaCursor object.
Return values
SequoiaCursorObject

Example:

$cursor = $cl -> explain( array( 'Run' => true ) ) ;
if( empty( $cursor ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to call explain, error code: ".$err['errno'] ;
return ;
}
while( $record = $cursor -> next() ) {
var_dump( $record ) ;
}
SequoiaCL::find ( array|string  $condition = null,
array|string  $selector = null,
array|string  $orderBy = null,
array|string  $hint = null,
integer  $numToSkip = 0,
integer  $numToReturn = -1,
integer  $flag = 0 
)

Get the matching records in current collection.

Parameters
$conditionan array or the string argument. The matching rule, return all the record if null.
$selectoran array or the string argument. The selective rule, return the whole record if null.
$orderByan array or the string argument. The The ordered rule, never sort if null.
$hintan array or the string argument. The hint, automatically match the optimal hint if null.
$numToSkipan integer argument. Skip the first numToSkip records, never skip if this parameter is 0.
$numToReturnan integer argument. Only return numToReturn records, return all if this parameter is -1.
$flagan integer argument. The query flag, default to be 0.
SDB_FLG_QUERY_FORCE_HINT(0x00000080) : Force to use specified hint to query, if database have no index assigned by the hint, fail to query
SDB_FLG_QUERY_PARALLED(0x00000100) : Enable paralled sub query
SDB_FLG_QUERY_WITH_RETURNDATA(0x00000200) : In general, query will not return data until cursor get from database,
when add this flag, return data in query response, it will be more high-performance
SDB_FLG_QUERY_PREPARE_MORE(0x00004000) : Enable prepare more data when query
SDB_FLG_UPDATE_KEEP_SHARDINGKEY(0x00008000) : The sharding key in update rule is not filtered, when updating records.
SDB_FLG_QUERY_FOR_UPDATE(0x00010000 ) : When the transaction is turned on and the transaction isolation level is "RC", the transaction lock will be
released after the record is read by default. However, when setting this flag, the transaction lock will not
released until the transaction is committed or rollback. When the transaction is turned off or
the transaction isolation level is "RU", the flag does not work
Returns
Returns a new SequoiaCursor object.
Return values
SequoiaCursorObject

Example:

$cursor = $cl -> find( array( 'a' => array( '$lte' => 50 ) ) ) ;
if( empty( $cursor ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to find, error code: ".$err['errno'] ;
return ;
}
while( $record = $cursor -> next() ) {
var_dump( $record ) ;
}
SequoiaCL::findAndRemove ( array|string  $condition = null,
array|string  $selector = null,
array|string  $orderBy = null,
array|string  $hint = null,
integer  $numToSkip = 0,
integer  $numToReturn = -1,
integer  $flag = 0 
)

Get the matching documents in current collection and remove.

Parameters
$conditionan array or the string argument. The matching rule, return all the record if null.
$selectoran array or the string argument. The selective rule, return the whole record if null.
$orderByan array or the string argument. The The ordered rule, never sort if null.
$hintan array or the string argument. The hint, automatically match the optimal hint if null.
$numToSkipan integer argument. Skip the first numToSkip records, never skip if this parameter is 0.
$numToReturnan integer argument. Only return numToReturn records, return all if this parameter is -1.
$flagan integer argument. The query flag, default to be 0.
SDB_FLG_QUERY_FORCE_HINT(0x00000080) : Force to use specified hint to query, if database have no index assigned by the hint, fail to query
SDB_FLG_QUERY_PARALLED(0x00000100) : Enable paralled sub query
SDB_FLG_QUERY_WITH_RETURNDATA(0x00000200) : In general, query will not return data until cursor get from database,
when add this flag, return data in query response, it will be more high-performance
SDB_FLG_QUERY_FOR_UPDATE(0x00010000 ) : When the transaction is turned on and the transaction isolation level is "RC", the transaction lock will be
released after the record is read by default. However, when setting this flag, the transaction lock will not
released until the transaction is committed or rollback. When the transaction is turned off or
the transaction isolation level is "RU", the flag does not work
Returns
Returns a new SequoiaCursor object.
Return values
SequoiaCursorObject

Example:

$cursor = $cl -> findAndRemove( array( 'a' => array( '$gt' => 0 ) ) ) ;
if( empty( $cursor ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to call findAndRemove, error code: ".$err['errno'] ;
return ;
}
while( $record = $cursor -> next() ) {
var_dump( $record ) ;
}
SequoiaCL::findAndUpdate ( array|string  $rule,
array|string  $condition = null,
array|string  $selector = null,
array|string  $orderBy = null,
array|string  $hint = null,
integer  $numToSkip = 0,
integer  $numToReturn = -1,
integer  $flag = 0,
boolean  $returnNew = false 
)

Get the matching records in current collection and update.

Parameters
$rulean array or the string argument. The update rule, can't be null.
$conditionan array or the string argument. The matching rule, return all the record if null.
$selectoran array or the string argument. The selective rule, return the whole record if null.
$orderByan array or the string argument. The The ordered rule, never sort if null.
$hintan array or the string argument. The hint, automatically match the optimal hint if null.
$numToSkipan integer argument. Skip the first numToSkip records, never skip if this parameter is 0.
$numToReturnan integer argument. Only return numToReturn records, return all if this parameter is -1.
$flagan integer argument. The query flag, default to be 0.
SDB_FLG_QUERY_FORCE_HINT(0x00000080) : Force to use specified hint to query, if database have no index assigned by the hint, fail to query
SDB_FLG_QUERY_PARALLED(0x00000100) : Enable paralled sub query
SDB_FLG_QUERY_WITH_RETURNDATA(0x00000200) : In general, query will not return data until cursor get from database,
when add this flag, return data in query response, it will be more high-performance
SDB_FLG_QUERY_KEEP_SHARDINGKEY_IN_UPDATE(0x00008000) : The sharding key in update rule is not filtered.
SDB_FLG_QUERY_FOR_UPDATE(0x00010000 ) : When the transaction is turned on and the transaction isolation level is "RC", the transaction lock will be
released after the record is read by default. However, when setting this flag, the transaction lock will not
released until the transaction is committed or rollback. When the transaction is turned off or
the transaction isolation level is "RU", the flag does not work
$returnNewa boolean argument. When TRUE, returns the updated record rather than the original.
Returns
Returns a new SequoiaCursor object.
Return values
SequoiaCursorObject

Example:

$cursor = $cl -> findAndUpdate( array( '$set' => array( 'a' => 0 ) ), false, array( 'a' => array( '$gt' => 0 ) ) ) ;
if( empty( $cursor ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to call findAndUpdate, error code: ".$err['errno'] ;
return ;
}
while( $record = $cursor -> next() ) {
var_dump( $record ) ;
}
SequoiaCL::getCollectionName ( )

Get the specified collection name.

See Also
getName().
Deprecated:
This function is deprecated, use the function getName() instead.
SequoiaCL::getCSName ( )

Get the specified collection space name.

Returns
Returns the collection space name.
Return values
string<cs_name>

Example:

$csName = $cl -> getCSName() ;
$err = $db -> getLastErrorMsg() ;
if( $err['errno'] != 0 ) {
echo "Failed to get collection space name, error code: ".$err['errno'] ;
return ;
}
echo "Collection space name is: ".$csName ;
SequoiaCL::getFullName ( )

Get the specified collection full name.

Returns
Returns the collection full name.
Return values
string<cs_name.cl_name>

Example:

$fullName = $cl -> getFullName() ;
$err = $db -> getLastErrorMsg() ;
if( $err['errno'] != 0 ) {
echo "Failed to get collection full name, error code: ".$err['errno'] ;
return ;
}
echo "Collection full name is: ".$fullName ;
SequoiaCL::getIndex ( string  $indexName = "")

Get all of or one of the indexes in current collection.

See Also
getIndexes() and getIndexInfo().
Deprecated:
This function is deprecated, use the function getIndexes() and getIndexInfo() instead.
SequoiaCL::getIndexes ( )

Get the information of all the indexes in current collection.

Returns
Returns a new SequoiaCursor object.
Return values
SequoiaCursorObject

Example:

$cursor = $cl -> getIndexes() ;
if( empty( $cursor ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to get indexes, error code: ".$err['errno'] ;
return ;
}
while( $record = $cursor -> next() ) {
var_dump( $record ) ;
}
SequoiaCL::getIndexInfo ( string  $name)

Get the information of the specified index in current collection.

Parameters
$namethe string argument. The index name.
Returns
Returns the information of index, default return array.
Return values
arrayrecord
stringrecord

Example:

$indexInfo = $cl -> getIndexInfo( 'myIndex' ) ;
if ( empty( $indexInfo ) )
{
$err = $db -> getLastErrorMsg() ;
echo "Failed to get index, error code: ".$err['errno'] ;
return ;
}
var_dump( $indexInfo ) ;
SequoiaCL::getName ( )

Get the specified collection name.

Returns
Returns the collection name.
Return values
string<cl_name>

Example:

$clName = $cl -> getName() ;
$err = $db -> getLastErrorMsg() ;
if( $err['errno'] != 0 ) {
echo "Failed to get collection name, error code: ".$err['errno'] ;
return ;
}
echo "Collection name is: ".$clName ;
SequoiaCL::insert ( array|string  $record,
integer  $flags = SDB_FLG_INSERT_RETURN_OID 
)

Insert a record into current collection.

Parameters
$recordan array or the string argument. The inserted record, cannot be empty.
$flagsan integer argument.
0 : while 0 is set, database will stop inserting
when the record hit index key duplicate error.
SDB_FLG_INSERT_CONTONDUP : if the record hit index key duplicate error,
database will skip them and go on inserting.
SDB_FLG_INSERT_RETURN_OID : return the value of "_id" field in the record.
SDB_FLG_INSERT_REPLACEONDUP : if the record hit index key duplicate error,
database will replace the existing record by
the inserting new record.
Returns
Returns the result, default return array. When flag SDB_FLG_INSERT_RETURN_OID is set, return the value of "_id" field of the inserted record.
Return values
arrayarray( 'errno' => 0, '_id' => <24 hexadecimal characters> )
string{ "errno": 0, "_id": <24 hexadecimal characters> }

Example: Record type is php array

$err = $cl -> insert( array( 'time' => '2012-12-12' ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to insert record, error code: ".$err['errno'] ;
return ;
}
echo "Insert record id is: ".$err['_id'] ;

Example: Record type is json string

$err = $cl -> insert( '{ "time": "2012-12-12" }' ) ;
if( $err['errno'] != 0 ) {
echo "Failed to insert record, error code: ".$err['errno'] ;
return ;
}
echo "Insert record id is: ".$err['_id'] ;

Example:

$err = $cl -> insert( array( 'name' => 'jack' ), SDB_FLG_INSERT_CONTONDUP | SDB_FLG_INSERT_RETURN_OID ) ;
if( $err['errno'] != 0 ) {
echo "Failed to insert record, error code: ".$err['errno'] ;
return ;
}
echo "Insert record id is: ".$err['_id'] ;
SequoiaCL::listLob ( array|string  $condition = null,
array|string  $selector = null,
array|string  $orderBy = null,
array|string  $hint = null,
integer  $numToSkip = 0,
integer  $numToReturn = -1 
)

List all the lobs' meta data in current collection.

Parameters
$conditionan array or the string argument. The matching rule, return all the lob if not provided.
$selectoran array or the string argument. The selective rule, return the whole infomation if not provided.
$orderByan array or the string argument. The ordered rule, result set is unordered if not provided.
$hintan array or the string argument. Specified options. e.g. {"ListPieces": 1} means get the detail piece info of lobs.
$numToSkipan integer argument. Skip the first numToSkip lob, default is 0.
$numToReturnan integer argument. Only return numToReturn lob, default is -1 for returning all results.
Returns
Returns a new SequoiaCursor object.
Return values
SequoiaCursorObject

Example:

$cursor = $cl -> listLob() ;
if( empty( $cursor ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to call listLob, error code: ".$err['errno'] ;
return ;
}
while( $record = $cursor -> next() ) {
var_dump( $record ) ;
}
SequoiaCL::listLobPieces ( array|string  $condition = null,
array|string  $selector = null,
array|string  $orderBy = null,
array|string  $hint = null,
integer  $numToSkip = 0,
integer  $numToReturn = -1 
)

List all the pieces in the lob.

Parameters
$conditionan array or the string argument. The matching rule, return all the lob if not provided.
$selectoran array or the string argument. The selective rule, return the whole infomation if not provided.
$orderByan array or the string argument. The ordered rule, result set is unordered if not provided.
$hintan array or the string argument. Specified options. e.g. {"ListPieces": 1} means get the detail piece info of lobs.
$numToSkipan integer argument. Skip the first numToSkip lob, default is 0.
$numToReturnan integer argument. Only return numToReturn lob, default is -1 for returning all results.
Returns
Returns a new SequoiaCursor object.
Return values
SequoiaCursorObject

Example:

$cursor = $cl -> listLobPieces() ;
if( empty( $cursor ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to call listLobPieces, error code: ".$err['errno'] ;
return ;
}
while( $record = $cursor -> next() ) {
var_dump( $record ) ;
}
SequoiaCL::openLob ( string  $oid,
integer  $mode 
)

Create a large object or open a large object to read or write.

Parameters
$oidthe string argument. The object id.
$modean integer argument. The open mode:
Returns
Returns a new SequoiaLob object.
Return values
SequoiaLobObject

Example:

$lobObj = $cl -> openLob( "123456789012345678901234", SDB_LOB_CREATEONLY ) ;
if( empty( $lobObj ) ) {
$err = $db -> getLastErrorMsg() ;
echo "Failed to open lob, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::remove ( array|string  $condition = null,
array|string  $hint = null 
)

Delete the matching documents in current collection, never rollback if failed.

Parameters
$conditionan array or the string argument. The matching rule, delete all the documents if null.
$hintan array or the string argument. The hint, automatically match the optimal hint if null.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Remove all records

$err = $cl -> remove() ;
if( $err['errno'] != 0 ) {
echo "Failed to remove, error code: ".$err['errno'] ;
return ;
}

Example: Remove match condition records

$err = $cl -> remove( array( 'age' => array( '$lte' => 50 ) ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to remove, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::removeLob ( string  $oid)

Remove lob

Parameters
$oidthe string argument. The object id.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> removeLob( "123456789012345678901234" ) ;
if( $err['errno'] != 0 ) {
echo "Failed to remove lob, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::setAttributes ( array|string  $options)

Alter collection options.

Parameters
$optionsan array or the string argument. The options are as following:
ReplSize : Assign how many replica nodes need to be synchronized when a write request(insert, update, etc) is executed
ShardingKey : Assign the sharding key
ShardingType : Assign the sharding type
Partition : When the ShardingType is "hash", need to assign Partition, it's the bucket number for hash, the range is [2^3,2^20]
CompressionType : The compression type of data, could be "snappy" or "lzw"
EnsureShardingIndex : Assign to true to build sharding index
StrictDataMode : Using strict date mode in numeric operations or not
e.g. array( "RepliSize" => 0, "ShardingKey" => array( "a" => 1 ), "ShardingType" => "hash", "Partition" =>1024 )
AutoIncrement : Assign attributes of an autoincrement field or batch autoincrement fields.
e.g. array( "AutoIncrement" => array( "Field" => "a", "MaxValue" => 2000 ) )
array( "AutoIncrement" => array( array( "Field" => "a", "MaxValue" => 2000 ), array( "Field" => "a", "MaxValue" => 4000 ) ) )
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example: Alter collection option ReplSize

$err = $cl -> setAttributes( array( 'ReplSize' => -1 ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to alter collection options, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::split ( string  $sourceGroup,
string  $targetGroup,
integer|double  $percent 
)

Split the specified collection from source replica group to target by percent.

Parameters
$sourceGroupthe string argument. The source replica group name.
$targetGroupthe string argument. The target replica group name.
$percentan integer or a double argument. The split percent, Range:(0.0, 100.0].
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> split( 'group1', 'group2', 50 ) ;
if( $err['errno'] != 0 ) {
echo "Failed to split collection, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::split ( string  $sourceGroup,
string  $targetGroup,
array|string  $condition,
array|string  $endCondition = null 
)

Split the specified collection from source replica group to target by range.

Parameters
$sourceGroupthe string argument. The source replica group name.
$targetGroupthe string argument. The target replica group name.
$conditionan array or the string argument. The split condition.
$endConditionan array or the string argument. The split end condition.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> split( 'group1', 'group2', array( 'a' => 1 ), array( 'a' => 100 ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to split collection, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::splitAsync ( string  $sourceGroup,
string  $targetGroup,
integer|double  $percent 
)

Split the specified collection from source replica group to target by range.

Parameters
$sourceGroupthe string argument. The source replica group name.
$targetGroupthe string argument. The target replica group name.
$percentan integer or a double argument. The split percent, Range:(0.0, 100.0].
Returns
Returns the result and task id, default return array.
Return values
arrayarray( 'errno' => 0, 'taskID' => 1 )
string{ "errno": 0, "taskID": 1 }

Example:

$err = $cl -> splitAsync( 'group1', 'group2', 50 ) ;
if( $err['errno'] != 0 ) {
echo "Failed to split collection, error code: ".$err['errno'] ;
return ;
}
echo "Task id is: ".$err['taskID'] ;
SequoiaCL::splitAsync ( string  $sourceGroup,
string  $targetGroup,
array|string  $condition,
array|string  $endCondition = null 
)

Split the specified collection from source replica group to target by range.

Parameters
$sourceGroupthe string argument. The source replica group name.
$targetGroupthe string argument. The target replica group name.
$conditionan array or the string argument. The split condition.
$endConditionan array or the string argument. The split end condition.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0, 'taskID' => 1 )
string{ "errno": 0, "taskID": 1

Example:

$err = $cl -> splitAsync( 'group1', 'group2', array( 'a' => 1 ), array( 'a' => 100 ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to split collection, error code: ".$err['errno'] ;
return ;
}
echo "Task id is: ".$err['taskID'] ;
SequoiaCL::truncateLob ( string  $oid,
integer|SequoiaINT64  $length 
)

Truncate lob

Parameters
$oidthe string argument. The object id.
$lengththe integer argument. The truncate length.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> truncateLob( "123456789012345678901234", 10 ) ;
if( $err['errno'] != 0 ) {
echo "Failed to truncate lob, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::update ( array|string  $rule,
array|string  $condition = null,
array|string  $hint = null,
integer  $flag = 0 
)

Update the matching documents in current collection.

Parameters
$rulean array or the string argument. The updating rule, cannot be null.
$conditionan array or the string argument. The matching rule, update all the documents if null.
$hintan array or the string argument. The hint, automatically match the optimal hint if null.
$flagan integer argument. The query flag, default to be 0.
SDB_FLG_UPDATE_KEEP_SHARDINGKEY(0x00008000) : The sharding key in update rule is not filtered.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> update( '{ "$set": { "phone" : "" } }', array( 'age' => array( '$lt' => 10 ) ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to update, error code: ".$err['errno'] ;
return ;
}
SequoiaCL::upsert ( array|string  $rule,
array|string  $condition = null,
array|string  $hint = null,
array|string  $setOnInsert = null,
integer  $flag = 0 
)

Update the matching documents in current collection, insert if no matching.

Parameters
$rulean array or the string argument. The updating rule, cannot be null.
$conditionan array or the string argument. The matching rule, update all the documents if null.
$hintan array or the string argument. The hint, automatically match the optimal hint if null.
$setOnInsertan array or the string argument. The setOnInsert, assigns the specified values to the fileds when insert
$flagan integer argument. The query flag, default to be 0.
SDB_FLG_UPDATE_KEEP_SHARDINGKEY(0x00008000) : The sharding key in update rule is not filtered.
Returns
Returns the result, default return array.
Return values
arrayarray( 'errno' => 0 )
string{ "errno": 0 }

Example:

$err = $cl -> upsert( '{ "$set": { "b" : 1 } }', array( 'a' => array( '$gt' => 100 ) ) ) ;
if( $err['errno'] != 0 ) {
echo "Failed to upsert, error code: ".$err['errno'] ;
return ;
}

Member Data Documentation

const SequoiaCL::SDB_FLG_FIND_FORCE_HINT 0x00000080

Force to use specified hint to query, if database have no index assigned by the hint, fail to query.

const SequoiaCL::SDB_FLG_FIND_PARALLED 0x00000100

Enable paralled sub query.

const SequoiaCL::SDB_FLG_FIND_WITH_RETURNDATA 0x00000200

In general, query will not return data until cursor get from database, when add this flag, return data in query response, it will be more high-performance.

const SequoiaCL::SDB_FLG_INSERT_CONTONDUP 0x00000001

The flag represent whether insert continue(no errors were reported) when hitting index key duplicate error

const SequoiaCL::SDB_FLG_INSERT_REPLACEONDUP 0x00000004

The flag represent if the record hit index key duplicate error, database will replace the existing record by the inserting new record.

const SequoiaCL::SDB_FLG_INSERT_RETURN_OID 0x10000000

The flag represent whether insert return the "_id" field of the record for user

const SequoiaCL::SDB_FLG_QUERY_FOR_UPDATE 0x00010000

When the transaction is turned on and the transaction isolation level is "RC", the transaction lock will be released after the record is read by default. However, when setting this flag, the transaction lock will not released until the transaction is committed or rollback. When the transaction is turned off or the transaction isolation level is "RU", the flag does not work.

const SequoiaCL::SDB_FLG_QUERY_FORCE_HINT 0x00000080

Force to use specified hint to query, if database have no index assigned by the hint, fail to query

const SequoiaCL::SDB_FLG_QUERY_KEEP_SHARDINGKEY_IN_UPDATE 0x00008000

The sharding key in update rule is not filtered, when executing findAndUpdate

const SequoiaCL::SDB_FLG_QUERY_PARALLED 0x00000100

Enable paralled sub query

const SequoiaCL::SDB_FLG_QUERY_PREPARE_MORE 0x00004000

Enable prepare more data when query

const SequoiaCL::SDB_FLG_QUERY_WITH_RETURNDATA 0x00000200

In general, query will not return data until cursor get from database, when add this flag, return data in query response, it will be more high-performance

const SequoiaCL::SDB_FLG_UPDATE_KEEP_SHARDINGKEY 0x00008000

The sharding key in update rule is not filtered, when executing update or upsert. SDB_FLG_QUERY_KEEP_SHARDINGKEY_IN_UPDATE is equal to SDB_FLG_UPDATE_KEEP_SHARDINGKEY, to prevent confusion.

const SequoiaCL::SDB_LOB_CREATEONLY 0x00000001

Open a new lob only.

const SequoiaCL::SDB_LOB_READ 0x00000004

Open an existing lob to read.

const SequoiaCL::SDB_LOB_SHAREREAD 0x00000040

Open an existing lob to share read.

const SequoiaCL::SDB_LOB_WRITE 0x00000008

Open an existing lob to write.


The documentation for this class was generated from the following files: