Exemple #1
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 ) );
      }
   }

}
Exemple #2
0
/*#
   @method write ConfParser
   @brief Write the INI file.
   @optparam stream An optional output stream on which to write the configuration file.
   @raise IoError on write error.

   Writes the content of a modified or entirely generated configuration file on the
   given stream, that must be a valid Falcon stream opened for output. If a stream
   is not given, then the file name provided to the ConfParser constructor is
   opened for writing. In case the name has not been given in the constructor, the
   method raises an error.

*/
FALCON_FUNC  ConfParser_write( ::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 )
   {
      bRes = cfile->save();
   }
   else {
      bool bValid = false;
      if ( i_stream->isObject() )
      {
         CoreObject *streamObj = i_stream->asObject();
         if ( streamObj->derivedFrom( "Stream" ) )
         {
            Stream *base = (Stream *) streamObj->getUserData();
            bRes = cfile->save( base );
            bValid = true;
         }
      }

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

   if ( ! bRes )
   {
      // is this a file error?
      if ( cfile->fsError() )
      {
         throw new IoError( ErrorParam( e_file_output, __LINE__ ).
            sysError( cfile->fsError() ).
            extra( cfile->errorMessage() ) );
      }
      else
      {
         // no -- it's a configuration file.d
         self->setProperty( "error", cfile->errorMessage() );
         self->setProperty( "errorLine", (int64) cfile->errorLine() );
         throw new ParseError( ErrorParam( FALCP_ERR_STORE, __LINE__ ).
            desc( FAL_STR(cp_msg_errstore)  ).extra( cfile->errorMessage() ) );
      }
   }
}
Exemple #3
0
/*#
   @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 );
}
Exemple #4
0
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);
}
Exemple #5
0
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 );
   }
}
Exemple #6
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 );
}
Exemple #7
0
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 );
}
Exemple #8
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 );
}
Exemple #9
0
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();
   }
}
Exemple #10
0
void DBIError_init( VMachine *vm )
{
   CoreObject *einst = vm->self().asObject();
   if( einst->getUserData() == 0 )
      einst->setUserData( new DBIError );

   ::Falcon::core::Error_init( vm );
}
Exemple #11
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) );
}
Exemple #12
0
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() ) );
}
Exemple #13
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) );
}
Exemple #14
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 );
   }
}
Exemple #15
0
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);
}
Exemple #16
0
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() );
}
Exemple #17
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 );
}
Exemple #18
0
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 );
}
Exemple #19
0
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 ) );
   }
}
Exemple #20
0
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 );
   }
}
Exemple #21
0
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
}
Exemple #22
0
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 );
}
Exemple #23
0
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;
}
Exemple #24
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() );
   }
}
Exemple #25
0
/*#
   @method add ConfParser
   @brief Adds a key/value pairs to the INI file.
   @param key The key to which add the given value.
   @param value The value, or value array, to be added.
   @optparam section If provided, the section where to add the entry

   This function adds a key/value pair to the main section, or if section parameter
   is given and not @b nil, to the specified section.

   If the key is already present, a multiple value is set.
*/
FALCON_FUNC  ConfParser_add( ::Falcon::VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   ConfigFile *cfile = (ConfigFile *) self->getUserData();
   Item *i_key = vm->param(0);
   Item *i_value = vm->param(1);
   Item *i_section = vm->param(2); // actually, if valorized, key and value are param 1 and 2.

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

   String *value;
   bool delValue;
   if( i_value->isString() )
   {
      delValue = false;
      value = i_value->asString();
   }
   else {
      value = new String;
      delValue = true;
      vm->itemToString( *value, i_value );
   }

   if( i_section == 0 || i_section->isNil() )
      cfile->addValue( *i_key->asString(), *value );
   else
      cfile->addValue( *i_section->asString(), *i_key->asString(), *value );

   if ( delValue )
      delete value;
}
Exemple #26
0
void Statement_execute( VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   DBIStatement *dbt = static_cast<DBIStatement *>( self->getUserData() );
   
   DBIRecordset* res;

   if( vm->paramCount() != 0 )
   {
      ItemArray params( vm->paramCount() );
      for( int32 i = 0; i < vm->paramCount(); i++)
      {
         params.append( *vm->param(i) );
      }
      res = dbt->execute( &params );
   }
   else {
      res = dbt->execute();
   }

   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();
   }
}
Exemple #27
0
void Recordset_getRowCount( VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   DBIRecordset *dbr = static_cast<DBIRecordset *>( self->getUserData() );
   vm->retval( dbr->getRowCount() );
}
Exemple #28
0
void Statement_close( VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   DBIStatement *dbt = static_cast<DBIStatement *>( self->getUserData() );
   dbt->close();
}
Exemple #29
0
void Recordset_close( VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   DBIRecordset *dbr = static_cast<DBIRecordset *>( self->getUserData() );
   dbr->close();
}
Exemple #30
0
void Handle_close( VMachine *vm )
{
   CoreObject *self = vm->self().asObject();
   DBIHandle *dbh = static_cast<DBIHandle *>( self->getUserData() );
   dbh->close();
}