예제 #1
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Handle_aquery( VMachine *vm )
{
   Item* i_sql = vm->param(0);
   Item* i_params = vm->param(1);
   if ( i_sql == 0 || ! i_sql->isString()
      || i_params == 0 || ! i_params->isArray() )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                                        .extra( "S,A" ) );
   }

   CoreObject *self = vm->self().asObject();
   DBIHandle *dbt = static_cast<DBIHandle *>( self->getUserData() );

   DBIRecordset* res = 0;
   res = dbt->query( *i_sql->asString(), &i_params->asArray()->items() );

   if( res != 0 )
   {
      Item* rset_item = vm->findWKI( "%Recordset" );
      fassert( rset_item != 0 );
      fassert( rset_item->isClass() );

      CoreObject* rset = rset_item->asClass()->createInstance();
      rset->setUserData( res );
      vm->retval( rset );
   }
}
예제 #2
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Handle_expand( VMachine *vm )
{
   Item* i_sql = vm->param(0);

   if ( i_sql == 0 || ! i_sql->isString() )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                                        .extra( "S, ..." ) );
   }

   CoreObject *self = vm->self().asObject();
   DBIHandle *dbt = static_cast<DBIHandle *>( self->getUserData() );


   DBIRecordset* res = 0;
   int32 pCount = vm->paramCount();
   CoreString* target = new CoreString;
   
   ItemArray params( pCount - 1 );      
   for( int32 i = 1; i < vm->paramCount(); i++)
   {
      params.append( *vm->param(i) );
   }
      
   // May throw
   dbt->sqlExpand( *i_sql->asString(), *target, params );
   vm->retval( target );
}
예제 #3
0
/*#
   @method getOne ConfParser
   @brief Retreives the value associated with a key.
   @param key The key of which the value is to be read.
   @optparam section If provided, the section where the key is found.
   @return The value (or values) of associated to the key, or nil if not found.

   This method is equivalent to the @a ConfParser.get method, except for the fact that if more
   than one value has been given for the determined key in the configuration file,
   only the last one among them is returned.
*/
FALCON_FUNC  ConfParser_getOne( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();
   Item *i_key = vm->param(0);
   Item *i_section = vm->param(1);

   if ( i_key == 0 || ! i_key->isString() ||
        ( i_section != 0 && ! i_section->isString() && ! i_section->isNil() )
      )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ ) );
   }

   String value;

   if ( i_section != 0 && ! i_section->isNil() )
   {
      if ( ! cfile->getValue( *i_section->asString(), *i_key->asString(), value ) )
      {
         vm->retnil();
         return;
      }
   }
   else {
      if ( ! cfile->getValue( *i_key->asString(), value ) )
      {
         vm->retnil();
         return;
      }
   }

   vm->retval( value );
}
예제 #4
0
/*#
   @method format Format
   @brief Performs desired formatting on a target item.
   @param item The item to be formatted
   @optparam dest A string where to store the formatted data.
   @return A formatted string
   @raise ParamError if a format specifier has not been set yet.
   @raise TypeError if the format specifier can't be applied the item because of
         incompatible type.

   Formats the variable as per the given format descriptor. If the class has been
   instantiated without format, and the parse() method has not been called yet,
   a ParamError is raised. If the type of the variable is incompatible with the
   format descriptor, the method returns nil; a particular format specifier allows
   to throw a TypeError in this case.

   On success, the method returns a string containing a valid formatted representation
   of the variable.

   It is possible to provide a pre-allocated string where to store the formatted
   result to improve performace and spare memory.
*/
FALCON_FUNC  Format_format ( ::Falcon::VMachine *vm )
{
   CoreObject *einst = vm->self().asObject();
   Format *fmt = dyncast<Format*>( einst->getFalconData() );

   Item *param = vm->param( 0 );
   Item *dest = vm->param( 1 );
   if( param == 0 || ( dest != 0 && ! dest->isString() ) )
   {
      throw new ParamError( ErrorParam( e_inv_params ).extra( "X,[S]" ) );
   }
   else
   {
      CoreString *tgt;

      if( dest != 0 )
      {
         tgt = dest->asCoreString();
      }
      else {
         tgt = new CoreString;
      }

      if( ! fmt->format( vm, *param, *tgt ) )
         vm->retnil();
      else
         vm->retval( tgt );
   }
}
예제 #5
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Statement_aexec( VMachine *vm )
{
   Item* i_params = vm->param(0);
   if( i_params == 0 || ! i_params->isArray() )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                                               .extra( "A" ) );
   }

   CoreObject *self = vm->self().asObject();
   DBIStatement *dbt = static_cast<DBIStatement *>( self->getUserData() );

   DBIRecordset* res;
   res = dbt->execute( &i_params->asArray()->items() );

   if( res != 0 )
   {
      Item* rset_item = vm->findWKI( "%Recordset" );
      fassert( rset_item != 0 );
      fassert( rset_item->isClass() );

      CoreObject* rset = rset_item->asClass()->createInstance();
      rset->setUserData( res );

      vm->retval( rset );
   }
   else
   {
      vm->retnil();
   }
}
예제 #6
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
/*#
   @method lselect Handle
   @brief Returns a "select" query configured to access a sub-recordset.
   @param sql The query (excluded the "select" command).
   @optparam begin The first row to be returned (0 based).
   @optparam count The number of rows to be returned.
   @return A fully configured sql command that can be fed into @a Handle.query

   This method should create a "select" query adding the commands and/or the
    parameters needed by the engine to limit the resultset to a specified part
    part of the dataset.

    The query parameter must be a complete query EXCEPT for the "select" command,
    which is added by the engine. It must NOT terminate with a ";", which, in case
    of need is added by the engine.

    For example, to limit the following query to rows 5-14 (row 5 is the 6th row):
    @code
       SELECT field1, field2 FROM mytable WHERE key = ?;
    @endcode

    write this Falcon code:
    @code
       // dbh is a DBI handle
       rset = dbh.query(
                   dbh.lselect( "field1, field2 FROM mytable WHERE key = ?", 5, 10 ),
                   "Key value" )
    @endcode

    The @b count parameter can be 0 or @b nil to indicate "from @b begin to the end".
    It's not possible to return the n-last elements; to do that, reverse the
    query ordering logic.

    @note If the engine doesn't support limited recordsets, the limit parameters are
    ignored.
*/
void Handle_lselect( VMachine *vm )
{
   Item* i_sql = vm->param(0);
   Item* i_nBegin = vm->param(1);
   Item* i_nCount = vm->param(2);

   if( i_sql == 0 || ! i_sql->isString()
      || ( i_nBegin != 0 && ! (i_nBegin->isOrdinal() || i_nBegin->isNil() ) )
      || ( i_nCount != 0 && ! i_nCount->isOrdinal() )
         )
   {
      throw new ParamError(ErrorParam( e_inv_params, __LINE__ )
           .extra( "S,[N],[N]") );
   }

   CoreObject *self = vm->self().asObject();
   DBIHandle *dbh = static_cast<DBIHandle *>( self->getUserData() );

   CoreString* result = new CoreString;
   dbh->selectLimited( *i_sql->asString(),
         i_nBegin == 0 ? 0 : i_nBegin->forceInteger(),
         i_nCount == 0 ? 0 : i_nCount->forceInteger(), *result );

   vm->retval( result );
}
예제 #7
0
/*#
   @method getCategoryKeys ConfParser
   @brief Get the keys filed under a given category.
   @param category The category of which the key list is required
   @optparam section If provided, the section where the category is defined.
   @return All the keys listed in the given category.

   This method returns a list of all the keys belonging to a certain category.

   See the "Categorized keys" section in @a ConfParser.
*/
FALCON_FUNC  ConfParser_getCategoryKeys( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();
   Item *i_keyMask = vm->param( 0 );
   Item *i_section = vm->param( 1 );

   if ( i_keyMask == 0 || ! i_keyMask->isString() ||
        ( i_section != 0 && ! i_section->isString() && ! i_section->isNil() )
      )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ ) );
      return;
   }

   String key;
   CoreArray *ret = new CoreArray;
   bool next;

   if ( i_section != 0 && ! i_section->isNil() ) {
      next = cfile->getFirstKey( *i_section->asString(), *i_keyMask->asString(), key );
   }
   else {
      next = cfile->getFirstKey( *i_keyMask->asString(), key );
   }

   while ( next )
   {
      ret->append( new CoreString( String( key, i_keyMask->asString()->length() + 1 ) ) );
      next = cfile->getNextKey( key );
   }

   vm->retval( ret );
}
예제 #8
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Handle_result( VMachine *vm )
{
   Item* i_sql = vm->param(0);

   if ( i_sql == 0 || ! i_sql->isString() )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                                        .extra( "S, ..." ) );
   }

   CoreObject *self = vm->self().asObject();
   DBIHandle *dbt = static_cast<DBIHandle *>( self->getUserData() );

   int32 pCount = vm->paramCount();
   Item result;
   if( pCount > 1 )
   {
      ItemArray params( pCount - 1 );
      for( int32 i = 1; i < vm->paramCount(); i++)
      {
         params.append( *vm->param(i) );
      }

      // Query may throw.
      dbt->result( *i_sql->asString(), result, &params );
   }
   else
   {
	  dbt->result( *i_sql->asString(), result );
   }

   vm->retval(result);
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void CoreObjectManager::DeleteObjectByHandle(CoreObjectHandle handle)
{
	CoreObject* pObject = GetObjectByHandle(handle);
	if(pObject != NULL)
	{
		pObject->DeleteObject();
	}
}
예제 #10
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void DBIError_init( VMachine *vm )
{
   CoreObject *einst = vm->self().asObject();
   if( einst->getUserData() == 0 )
      einst->setUserData( new DBIError );

   ::Falcon::core::Error_init( vm );
}
예제 #11
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
static void internal_stmt_open( VMachine* vm, DBIStatement* trans )
{
   Item *trclass = vm->findWKI( "%Statement" );
   fassert( trclass != 0 && trclass->isClass() );

   CoreObject *oth = trclass->asClass()->createInstance();
   oth->setUserData( trans );
   vm->retval( oth );
}
예제 #12
0
FALCON_FUNC Dictionary_last( VMachine *vm )
{
   Item *itclass = vm->findWKI( "Iterator" );
   fassert( itclass != 0 );

   CoreObject *iterator = itclass->asClass()->createInstance();
   // we need to set the FalconData flag
   iterator->setUserData( new Iterator( &vm->self().asDict()->items(), true  ) );
   vm->retval( iterator );
}
예제 #13
0
/*#
   @method getDictionary ConfParser
   @brief Retreives keys and values given under a certain category.
   @optparam section If given, the section from which to extract the dictionary.
   @return A dictionary containing a pair of key-values in the given section.

   This method retrieves all the pairs of key and values in the main section, or if
   a non-nil section parameter is provided, from the given section. If the
   requested section cannot be found, or if it doesn't contain any entry, an empty
   dictionary is returned. If a key has multiple values, its element is set to an
   array containing all the values.
*/
FALCON_FUNC  ConfParser_getDictionary( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();
   Item *i_section = vm->param( 0 );

   if ( i_section != 0 && ! i_section->isString() )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ ) );
   }

   String key;
   LinearDict *ret = new LinearDict();
   LinearDict *current = ret;
   bool next;

   if ( i_section != 0 ) {
      next = cfile->getFirstKey( *i_section->asString(), "", key );
   }
   else {
      next = cfile->getFirstKey( "", key );
   }

   while( next )
   {
      String value;

      // seeking a value won't alter key iterators.
      if( i_section != 0 )
         cfile->getValue( *i_section->asString(), key, value );
      else
         cfile->getValue( key, value );

      // we have at least one value. but do we have more?
      String value1;
      if ( cfile->getNextValue( value1 ) )
      {
         CoreArray *array = new CoreArray( 5 );
         array->append( new CoreString( value ) );
         array->append( new CoreString( value1 ) );

         while( cfile->getNextValue( value1 ) )
            array->append( new CoreString( value1 ) );

         current->put( new CoreString( key ), array );
      }
      else {
         current->put( new CoreString( key ), new CoreString( value ) );
      }

      next = cfile->getNextKey( key );
   }

   vm->retval( new CoreDict(ret) );
}
예제 #14
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Recordset_discard( VMachine *vm )
{
   Item *i_count = vm->param( 0 );
   if ( i_count == 0 || ! i_count->isOrdinal() ) {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                                        .extra( "N" ) );
   }

   CoreObject *self = vm->self().asObject();
   DBIRecordset *dbr = static_cast<DBIRecordset *>( self->getUserData() );
   vm->regA().setBoolean( dbr->discard( i_count->forceInteger() ) );
}
예제 #15
0
FALCON_FUNC  ConfParser_removeSection( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();
   Item *i_section = vm->param(0);

   if ( i_section == 0 ||  ! i_section->isString() )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).extra( "S" ) );
   }

   vm->retval( (int64) ( cfile->removeSection( *i_section->asString() ) ? 1: 0) );
}
예제 #16
0
/*#
   @method GetCursor SDL
   @brief Gets currently active cursor.
   @return an instance of @a SDLCursor class or nil.

   This method returns the currently active cursor. It can be used to
   store this away and set it later.
*/
FALCON_FUNC sdl_GetCursor( ::Falcon::VMachine *vm )
{
   ::SDL_Cursor *cursor = ::SDL_GetCursor();
   if ( cursor == 0 )
      vm->retnil();
   else {
      Item *cls = vm->findWKI( "SDLCursor" );
      fassert( cls != 0 );
      CoreObject *obj = cls->asClass()->createInstance();
      obj->setUserData( new SDLCursorCarrier( cursor, false ) );
      vm->retval( obj );
   }
}
예제 #17
0
/*#
   @method get ConfParser
   @brief Retreives the value associated with a key.
   @param key The key of which the value is to be read.
   @optparam section If provided, the section where the key is found.
   @return The value (or values) of associated to the key, or nil if not found.

   The method retrieves the value associated with a given key. If section parameter
   is not provided, or if it's nil, the key is searched in the main section, else
   it is searched in the given section.

   If the section does not exist, or if the key is not present in the given
   section, the method returns nil. If the key exist but has no value associated
   with it, an empty string is returned. If there is only one instance of the key,
   a single string containing the value is returned. If multiple entries for the
   given key are found, all the values are returned as strings in an array.
   The caller should verify the if the returned value is a string or an array using
   typeOf() function. Alternatively, it is possible to use @a ConfParser.getOne to be sure to
   retrieve only strings.

   Categorized keys can be retrieved with this method by providing their full name.
*/
FALCON_FUNC  ConfParser_get( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();
   Item *i_key = vm->param(0);
   Item *i_section = vm->param(1);

   if ( i_key == 0 || ! i_key->isString() ||
        ( i_section != 0 && ! i_section->isString() && ! i_section->isNil() )
      )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ ) );
   }

   String value;

   if ( i_section != 0 && ! i_section->isNil() )
   {
      if ( ! cfile->getValue( *i_section->asString(), *i_key->asString(), value ) )
      {
         vm->retnil();
         return;
      }
   }
   else {
      if ( ! cfile->getValue( *i_key->asString(), value ) )
      {
         vm->retnil();
         return;
      }
   }

   // we have at least one value. but do we have more?
   String value1;
   if ( cfile->getNextValue( value1 ) )
   {
      CoreArray *array = new CoreArray( 5 );
      array->append( new CoreString( value ) );
      array->append( new CoreString( value1 ) );

      while( cfile->getNextValue( value1 ) )
         array->append( new CoreString( value1 ) );

      vm->retval( array );
   }
   else {
      vm->retval( value );
   }
}
예제 #18
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Handle_options( VMachine *vm )
{
   Item* i_options = vm->param(0);

   if( i_options == 0 || ! i_options->isString() )
   {
      throw new ParamError(ErrorParam( e_inv_params, __LINE__ )
           .extra( "S") );
   }

   CoreObject *self = vm->self().asObject();
   DBIHandle *dbh = static_cast<DBIHandle *>( self->getUserData() );

   dbh->options( *i_options->asString() );
}
예제 #19
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Handle_prepare( VMachine *vm )
{
   Item* i_sql = vm->param(0);

   if ( i_sql == 0 || ! i_sql->isString() )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                                        .extra( "S, ..." ) );
   }

   CoreObject *self = vm->self().asObject();
   DBIHandle *dbt = static_cast<DBIHandle *>( self->getUserData() );
   DBIStatement* stmt = dbt->prepare( *i_sql->asString() );
   internal_stmt_open(vm, stmt);
}
예제 #20
0
/*#
   @method getSections ConfParser
   @brief Enumerates the sections that are declared in the file managed by this object.
   @return All the values of associated to the key, or nil if not found.

   If the object doesn't declare any section, the method returns an empty array.
*/
FALCON_FUNC  ConfParser_getSections( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();

   String section;
   CoreArray *ret = new CoreArray;

   if( cfile->getFirstSection( section ) )
   {
      ret->append( new CoreString( section ) );
      while( cfile->getNextSection( section ) )
         ret->append( new CoreString( section ) );
   }

   vm->retval( ret );
}
예제 #21
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Recordset_getColumnNames( VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   DBIRecordset *dbr = static_cast<DBIRecordset *>( self->getUserData() );

   int count = dbr->getColumnCount();
   CoreArray* ret = new CoreArray( count );

   for( int i = 0; i < count; ++i )
   {
      CoreString* str = new CoreString;
      dbr->getColumnName( i, *str );
      str->bufferize();
      ret->append( str );
   }

   vm->retval( ret );
}
예제 #22
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Handle_getLastID( VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   DBIHandle *dbh = static_cast<DBIHandle *>( self->getUserData() );

   if ( vm->paramCount() == 0 )
      vm->retval( dbh->getLastInsertedId() );
   else {
      Item *sequenceNameI = vm->param( 0 );
      if ( sequenceNameI == 0 || ! sequenceNameI->isString() ) {
         throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                                           .extra( "S" ) );
         return;
      }
      String sequenceName = *sequenceNameI->asString();
      vm->retval( dbh->getLastInsertedId( sequenceName ) );
   }
}
예제 #23
0
Command* CommandEngine::newCommand(CoreObject* owner, QString command){
    command = command.trimmed();
    if (commands.contains(command)){
        Command* c = commands.value(command);
        if (c == 0) return 0;
        CoreObject* actualOwner = c->owner();
        core()->error(QString("[%1] the command [%2] has already been registered by [%3].")
                      .arg(owner->alias())
                      .arg(command)
                      .arg(actualOwner->alias()), "CE");
        return 0;
    }
    Command* c = new Command(this);
    c->setCommand(command);
    c->setOwner(owner);
    commands.insert(command, c);
    return c;
}
예제 #24
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Handle_query( VMachine *vm )
{
   Item* i_sql = vm->param(0);

   if ( i_sql == 0 || ! i_sql->isString() )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
                                        .extra( "S, ..." ) );
   }

   CoreObject *self = vm->self().asObject();
   DBIHandle *dbt = static_cast<DBIHandle *>( self->getUserData() );
   

   DBIRecordset* res = 0;
   int32 pCount = vm->paramCount();
   if( pCount > 1 )
   {
      ItemArray params( pCount - 1 );      
      for( int32 i = 1; i < vm->paramCount(); i++)
      {
         params.append( *vm->param(i) );
      }
      
      // Query may throw.
      res = dbt->query( *i_sql->asString(), &params );
   }
   else 
   {
      res = dbt->query( *i_sql->asString() );
   }

   if( res != 0 )
   {
      Item* rset_item = vm->findWKI( "%Recordset" );
      fassert( rset_item != 0 );
      fassert( rset_item->isClass() );

      CoreObject* rset = rset_item->asClass()->createInstance();
      rset->setUserData( res );

      vm->retval( rset );
   }
}
예제 #25
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Recordset_next( VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   DBIRecordset *dbr = static_cast<DBIRecordset *>( self->getUserData() );

   DBIRecordset *res = dbr->getNext();
   if( res != 0 )
   {
      Item* rset_item = vm->findWKI( "%Recordset" );
      fassert( rset_item != 0 );
      fassert( rset_item->isClass() );

      CoreObject* rset = rset_item->asClass()->createInstance();
      rset->setUserData( res );

      vm->retval( rset );
   }
   // else return nothing
}
예제 #26
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
void Recordset_fetch( VMachine *vm )
{
   Item *i_data = vm->param( 0 );
   Item *i_count = vm->param( 1 );

   // prepare the array in case of need.
   if( i_data == 0 )
   {
      vm->addLocals(1);
      i_data = vm->local(0);
      *i_data = new CoreArray();
      // if i_data is zero, then i_count is also zero, so we don't have to worry
      // about the VM stack being moved.
   }
/*
   if ( ! ( i_data->isArray() || i_data->isDict() || i_data->isOfClass("Table") )
         || (i_count != 0 && ! i_count->isOrdinal())
         )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
           .extra( "[A|D|Table],[N]" ) );
   }
*/

   if ( ! ( i_data->isArray() || i_data->isDict() )
         || (i_count != 0 && ! i_count->isOrdinal())
         )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
           .extra( "[A|D],[N]" ) );
   }

   CoreObject *self = vm->self().asObject();
   DBIRecordset *dbr = static_cast<DBIRecordset *>( self->getUserData() );

   if( ! dbr->fetchRow() )
   {
      vm->retnil();
      return;
   }

   internal_record_fetch( vm, dbr, *i_data );
}
예제 #27
0
FALCON_FUNC  ConfParser_read( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();
   Item *i_stream = vm->param(0);

   bool bRes;

   if( i_stream == 0 )
   {
      vm->idle();
      bRes = cfile->load();
      vm->unidle();
   }
   else {
      bool bValid = false;
      if ( i_stream->isObject() )
      {
         CoreObject *streamObj = i_stream->asObject();
         if ( streamObj->derivedFrom( "Stream" ) )
         {
            Stream *base = (Stream *) streamObj->getUserData();
            bRes = cfile->load( base );
            bValid = true;
         }
      }

      if ( ! bValid )
      {
         throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).extra( "Stream" ) );
         return;
      }
   }

   if ( ! bRes )
   {
      // is this an I/O or a parsing error?
      if ( cfile->fsError() != 0 )
      {
         throw new IoError( ErrorParam( e_loaderror, __LINE__ ).
            sysError( cfile->fsError() ).
            extra( cfile->errorMessage() ) );
      }
      else {
         String msg = cfile->errorMessage() + " at ";
         msg.writeNumber( (int64) cfile->errorLine() );
         self->setProperty( "error", cfile->errorMessage() );
         self->setProperty( "errorLine", (int64) cfile->errorLine() );
         throw new ParseError( ErrorParam( FALCP_ERR_INVFORMAT, __LINE__ )
            .desc( FAL_STR(cp_msg_invformat) )
            .extra( msg ) );
      }
   }

}
예제 #28
0
파일: dbi_ext.cpp 프로젝트: Klaim/falcon
static bool Recordset_do_next( VMachine* vm )
{
   if( vm->regA().isOob() && vm->regA().isInteger() && vm->regA().asInteger() == 0 )
   {
      return false;
   }

   CoreObject *self = vm->self().asObject();
   DBIRecordset *dbr = static_cast<DBIRecordset *>( self->getUserData() );

   if( ! dbr->fetchRow() )
   {
      return false;
   }

   // copy, as we may disrupt the stack
   Item i_callable = *vm->param(0);

   if( vm->paramCount() == 1 )
   {
      int count = dbr->getColumnCount();
      for ( int i = 0; i < count; i++ )
      {
         Item value;
         dbr->getColumnValue( i, value );
         vm->pushParam( value );
      }

      vm->callFrame( i_callable, count );
   }
   else
   {
      internal_record_fetch( vm, dbr, *vm->param(1) );
      vm->pushParam( vm->regA() );
      vm->regA().setNil();
      vm->callFrame( i_callable, 1 );
   }

   return true;
}
예제 #29
0
/*#
   @method parse Format
   @brief Initializes the Format instance with an optional value.
   @param fmtspec Format specifier
   @raise ParseError if the format specifier is not correct.

   Sets or changes the format specifier for this Format instance.
   If the format string is not correct, a ParseError is raised.
*/
FALCON_FUNC  Format_parse ( ::Falcon::VMachine *vm )
{

   CoreObject *einst = vm->self().asObject();
   Format *fmt = (Format *) einst->getFalconData();

   Item *param = vm->param( 0 );
   if ( param != 0 )
   {
      if( ! param->isString() )
      {
         throw new ParamError( ErrorParam( e_inv_params ).extra( "[S]" ) );
      }
      else  {
         fmt->parse( *param->asString() );
         if( ! fmt->isValid() )
         {
            throw new ParseError( ErrorParam( e_param_fmt_code ) );
         }
      }
   }
}
예제 #30
0
/*#
   @method remove ConfParser
   @brief Remove a key from the configuration file..
   @param key The key to be removed.
   @optparam section If provided, the section where to remove the entry.
   @return True if the key is removed, false if the given key is not found.

   Remove all the instances of a given key from the main section,
   or if @b section parameter is given and not nil, from the specified section.

   The method returns true if the section (when provided) and keys were found,
   and false if nothing has actually been deleted.

*/
FALCON_FUNC  ConfParser_remove( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();
   Item *i_key = vm->param(0);
   Item *i_section = vm->param(1); // optional

   if ( i_key == 0 || ! i_key->isString() ||
         ( i_section != 0 && ! i_section->isString() && ! i_section->isNil() )
      )
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).extra( "S, S" ) );
   }

   if ( i_section == 0 || i_section->isNil() )
   {
      cfile->removeValue( *i_key->asString() );
   }
   else
   {
      cfile->removeValue( *i_section->asString(), *i_key->asString() );
   }
}