Esempio n. 1
0
   INT32 _rtnQueryOptions::getOwned()
   {
      INT32 rc = SDB_OK ;
      if ( NULL != _fullNameBuf )
      {
         SDB_OSS_FREE( _fullNameBuf ) ;
         _fullNameBuf = NULL ;
      }

      if ( NULL != _fullName )
      {
         _fullNameBuf = ossStrdup( _fullName ) ;
         if ( NULL == _fullNameBuf )
         {
            rc = SDB_OOM ;
            goto error ;
         }
      }

      _fullName = _fullNameBuf ;
      _query = _query.getOwned() ;
      _selector = _selector.getOwned() ;
      _orderBy = _orderBy.getOwned() ;
      _hint = _hint.getOwned() ;
   done:
      return rc ;
   error:
      goto done ;
   }
Esempio n. 2
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_SCOPE_EVALUATE2, "Scope::evaluate2" )
   INT32 Scope::evaluate2 ( const CHAR *code, UINT32 len, UINT32 lineno,
                            jsval *rval, CHAR **errMsg,
                            INT32 printFlag )
   {
      PD_TRACE_ENTRY ( SDB_SCOPE_EVALUATE2 );
      INT32 rc = SDB_OK ;
      jsval exception = JSVAL_VOID ;
      CHAR *cstrException = NULL ;
      SDB_ASSERT ( _context && _global, "this scope has not been initilized" ) ;
      SDB_ASSERT ( code , "Invalid arguments" ) ;

      // set error report
      sdbSetPrintError( ( printFlag & SPT_EVAL_FLAG_PRINT ) ? TRUE : FALSE ) ;
      sdbSetNeedClearErrorInfo( TRUE ) ;

      if ( ! JS_EvaluateScript ( _context, _global, code, len, NULL,
                                 lineno, rval ) )
      {
         rc = sdbGetErrno() ? sdbGetErrno() : SDB_SPT_EVAL_FAIL ;
         goto error ;
      }

      // clear return error
      if ( sdbIsNeedClearErrorInfo() &&
           !JS_IsExceptionPending( _context ) )
      {
         sdbClearErrorInfo() ;
      }

   done:
      PD_TRACE_EXITRC ( SDB_SCOPE_EVALUATE2, rc );
      return rc ;
   error:
      if ( JS_IsExceptionPending( _context ) &&
           JS_GetPendingException ( _context , &exception ) )
      {
         cstrException = convertJsvalToString ( _context , exception ) ;
         if ( cstrException )
         {
            if ( printFlag & SPT_EVAL_FLAG_PRINT )
            {
               ossPrintf ( "Uncaught exception: %s\n" , cstrException ) ;
            }

            /// what to do when oom?
            *errMsg = ossStrdup( cstrException ) ;
            SAFE_JS_FREE ( _context , cstrException ) ;
         }
         else
         {
            JS_ClearPendingException ( _context ) ;
         }
      }
      goto done ;
   }
Esempio n. 3
0
   INT32 _rtnQueryOptions::getOwned ()
   {
      INT32 rc = SDB_OK ;

      _rtnReturnOptions::getOwned() ;

      SAFE_OSS_FREE( _fullNameBuf ) ;
      if ( NULL != _fullName )
      {
         _fullNameBuf = ossStrdup( _fullName ) ;
         if ( NULL == _fullNameBuf )
         {
            rc = SDB_OOM ;
            goto error ;
         }
      }
      _fullName = _fullNameBuf ;

      SAFE_OSS_FREE( _mainCLNameBuf ) ;
      if ( NULL != _mainCLName )
      {
         _mainCLNameBuf = ossStrdup( _mainCLName ) ;
         if ( NULL == _mainCLNameBuf )
         {
            rc = SDB_OOM ;
            goto error ;
         }
      }
      _mainCLName = _mainCLNameBuf ;

      _query = _query.getOwned() ;
      _orderBy = _orderBy.getOwned() ;
      _hint = _hint.getOwned() ;

   done:
      return rc ;
   error:
      goto done ;
   }
Esempio n. 4
0
 const CHAR* _qgmPtrTable::getOwnedString( const CHAR *str )
 {
    STR_TABLE_IT it = _stringTable.find( str ) ;
    if ( it != _stringTable.end() )
    {
       ++( it->second ) ;
       return it->first ;
    }
    else
    {
       CHAR *dup = ossStrdup( str ) ;
       _stringTable[ dup ] = 1 ;
       return dup ;
    }
 }
Esempio n. 5
0
 void sdbSetErrMsg( const CHAR *err )
 {
    static CHAR* s_emptyMsg = "" ;
    __hasSetErrMsg__        = FALSE ;
    if ( NULL != __errmsg__ && s_emptyMsg != __errmsg__ )
    {
       SDB_OSS_FREE( __errmsg__ ) ;
       __errmsg__ = s_emptyMsg ;
    }
    if ( err && 0 != *err )
    {
       __errmsg__ = ossStrdup( err ) ;
       __hasSetErrMsg__ = TRUE ;
    }
 }
Esempio n. 6
0
   INT32 _qgmPtrTable::getOwnField( const CHAR * begin, qgmField & field )
   {
      PD_TRACE_ENTRY( SDB__QGMPTRTABLE_GETOWNFIELD ) ;
      SDB_ASSERT( NULL != begin, "impossible" ) ;
      INT32 rc = SDB_OK ;
      UINT32 size = ossStrlen( begin ) ;
      if ( NULL == begin || 0 == size )
      {
         rc = SDB_INVALIDARG ;
         goto error ;
      }
      {
      qgmField f ;
      f._begin = begin ;
      f._size = size ;
      PTR_TABLE::const_iterator itr = _table.find( f ) ;
      if ( _table.end() == itr )
      {
         CHAR *newStr = ossStrdup( begin ) ;
         _stringTable.push_back( newStr ) ;

         field._begin = ( const CHAR*)newStr ;
         field._size = size ;
         _table.insert( field ) ;
      }
      else
      {
         field = *itr;
      }
      }
   done:
      PD_TRACE_EXITRC( SDB__QGMPTRTABLE_GETOWNFIELD, rc ) ;
      return rc ;
   error:
      goto done ;
   }
Esempio n. 7
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_SCOPE_EVALUATE, "Scope::evaluate" )
   INT32 Scope::evaluate ( const CHAR *code , UINT32 len,
                           const CHAR *filename, UINT32 lineno,
                           CHAR ** result, INT32 printFlag )
   {
      PD_TRACE_ENTRY ( SDB_SCOPE_EVALUATE );
      jsval        rval           = JSVAL_VOID ;
      jsval        exception      = JSVAL_VOID ;
      CHAR *       cstrException  = NULL ;
      CHAR *       cstr           = NULL ;
      INT32        rc             = SDB_OK ;

      SDB_ASSERT ( _context && _global, "this scope has not been initilized" ) ;
      SDB_ASSERT ( code , "Invalid arguments" ) ;

      // set error report
      sdbSetPrintError( ( printFlag & SPT_EVAL_FLAG_PRINT ) ? TRUE : FALSE ) ;
      sdbSetNeedClearErrorInfo( TRUE ) ;

      if ( ! JS_EvaluateScript ( _context , _global ,
                                 code , len > 0 ? len : ossStrlen ( code ) ,
                                 filename ? filename : "(default)" , lineno ,
                                 &rval ) )
      {
         rc = sdbGetErrno() ? sdbGetErrno() : SDB_SPT_EVAL_FAIL ; ;
         goto error ;
      }

      // clear return error
      if ( sdbIsNeedClearErrorInfo() &&
           !JS_IsExceptionPending( _context ) )
      {
         sdbClearErrorInfo() ;
      }

      if ( !result )
      {
         goto done ;
      }

      // cstr is freed in done:
      // cstr is freed by JSFree, so we have to use strdup instead of ossStrdup
      if ( JSVAL_IS_VOID ( rval ) )
      {
#if defined (_LINUX)
         cstr = strdup ( "" ) ;
#elif defined (_WINDOWS)
         cstr = _strdup ( "" ) ;
#endif
      }
      else
      {
         cstr = convertJsvalToString ( _context , rval ) ;
      }

      if ( ! cstr )
      {
         rc = SDB_SYS ;
         goto error ;
      }

      *result = ossStrdup ( cstr ) ;
      if ( !( result && result[0] != '\0') )
      {
         rc = SDB_OOM ;
         PD_LOG ( PDERROR , "memory allcation fail" ) ;
         goto error ;
      }

   done :
      SAFE_JS_FREE ( _context , cstr ) ;
      PD_TRACE_EXITRC ( SDB_SCOPE_EVALUATE, rc );
      return rc ;
   error :
      if ( JS_GetPendingException ( _context , &exception ) )
      {
         cstrException = convertJsvalToString ( _context , exception ) ;
         if ( cstrException )
         {
            if ( printFlag & SPT_EVAL_FLAG_PRINT )
            {
               ossPrintf ( "Uncaught exception: %s\n" , cstrException ) ;
            }
            SAFE_JS_FREE ( _context , cstrException ) ;
         }
         else
         {
            JS_ClearPendingException ( _context ) ;
         }
      }
      goto done ;
   }
Esempio n. 8
0
 /*
    OSS_INLINE functions :
 */
 OSS_INLINE void _dmsStorageData::_collectionNameInsert( const CHAR * pName,
                                                         UINT16 mbID )
 {
    _collectionNameMap[ ossStrdup( pName ) ] = mbID ;
 }