summaryrefslogtreecommitdiff
path: root/scripting/sm_db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scripting/sm_db.cpp')
-rw-r--r--scripting/sm_db.cpp49
1 files changed, 35 insertions, 14 deletions
diff --git a/scripting/sm_db.cpp b/scripting/sm_db.cpp
index 940d785..8ba612b 100644
--- a/scripting/sm_db.cpp
+++ b/scripting/sm_db.cpp
@@ -95,7 +95,13 @@ namespace mongo {
JSBool internal_cursor_hasNext(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
DBClientCursor *cursor = getCursor( cx, obj );
- *rval = cursor->more() ? JSVAL_TRUE : JSVAL_FALSE;
+ try {
+ *rval = cursor->more() ? JSVAL_TRUE : JSVAL_FALSE;
+ }
+ catch ( std::exception& e ){
+ JS_ReportError( cx , e.what() );
+ return JS_FALSE;
+ }
return JS_TRUE;
}
@@ -108,13 +114,23 @@ namespace mongo {
JSBool internal_cursor_next(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
DBClientCursor *cursor = getCursor( cx, obj );
- if ( ! cursor->more() ){
- JS_ReportError( cx , "cursor at the end" );
+
+ BSONObj n;
+
+ try {
+ if ( ! cursor->more() ){
+ JS_ReportError( cx , "cursor at the end" );
+ return JS_FALSE;
+ }
+
+ n = cursor->next();
+ }
+ catch ( std::exception& e ){
+ JS_ReportError( cx , e.what() );
return JS_FALSE;
}
- Convertor c(cx);
- BSONObj n = cursor->next();
+ Convertor c(cx);
*rval = c.toval( &n );
return JS_TRUE;
}
@@ -310,7 +326,7 @@ namespace mongo {
}
JSBool mongo_remove(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
- smuassert( cx , "mongo_remove needs 2 arguments" , argc == 2 );
+ smuassert( cx , "mongo_remove needs 2 or 3 arguments" , argc == 2 || argc == 3 );
smuassert( cx , "2nd param to insert has to be an object" , JSVAL_IS_OBJECT( argv[1] ) );
Convertor c( cx );
@@ -324,9 +340,12 @@ namespace mongo {
string ns = c.toString( argv[0] );
BSONObj o = c.toObject( argv[1] );
-
+ bool justOne = false;
+ if ( argc > 2 )
+ justOne = c.toBoolean( argv[2] );
+
try {
- conn->remove( ns , o );
+ conn->remove( ns , o , justOne );
return JS_TRUE;
}
catch ( ... ){
@@ -861,12 +880,14 @@ namespace mongo {
JSBool numberlong_tostring(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval){
Convertor c(cx);
stringstream ss;
- if ( c.hasProperty( obj, "top" ) ) {
- long long val = c.toNumberLongUnsafe( obj );
- ss << "NumberLong( \"" << val << "\" )";
- } else {
- ss << "NumberLong( " << c.getNumber( obj, "floatApprox" ) << " )";
- }
+ long long val = c.toNumberLongUnsafe( obj );
+ const long long limit = 2LL << 30;
+
+ if ( val <= -limit || limit <= val )
+ ss << "NumberLong(\"" << val << "\")";
+ else
+ ss << "NumberLong(" << val << ")";
+
string ret = ss.str();
return *rval = c.toval( ret.c_str() );
}