Beispiel #1
0
/*# @method getFields URI
   @brief Returns fields contained in the query element into a dictionary.
   @return The fields as a dictionary of nil if the query part contains no element.
   @raise ParamError if the string is not a valid URI/URL encoded string.
*/
FALCON_FUNC  URI_getFields ( ::Falcon::VMachine *vm )
{
   UriObject *self = dyncast<UriObject*>( vm->self().asObject() );
   URI &uri = self->uri();

   if ( uri.query().size() == 0 )
   {
      vm->retnil();
      return;
   }

   if( uri.fieldCount() == 0 )
   {
      // we have a query but no fields; this means we still have to parse it.
      if ( ! uri.parseQuery( true ) )
      {
         // todo: better signalation
         throw new ParamError( ErrorParam( e_inv_params, __LINE__ ).
            origin( e_orig_runtime ).extra( vm->moduleString( rtl_invalid_uri ) ) );
         return;
      }

      // really nothing to parse?
      if ( uri.fieldCount() == 0 )
      {
         vm->retnil();
         return;
      }
   }

   // ok, build our dictionary
   uint32 count = uri.fieldCount();
   CoreDict *dict = new CoreDict( new LinearDict( count ) );
   CoreString *key = new CoreString;
   CoreString *value = new CoreString;
   uri.firstField( *key, *value );
   count--;
   dict->put( key, value );
   while( count > 0 )
   {
      key = new CoreString;
      value = new CoreString;
      uri.nextField( *key, *value );
      count --;
      dict->put( key, value );
   }

   vm->retval( dict );
}
Beispiel #2
0
/*#
   @function set Dictionary
   @brief Stores a value in a dictionary
   @param key The key to be found.
   @param value The key to be set.
   @return True if the value was overwritten, false if it has been inserted anew.
   
   @note This method bypassess setIndex__ override in blessed (POOP) dictionaries.

   @see oob
*/
FALCON_FUNC  mth_dictSet( ::Falcon::VMachine *vm )
{
   Item *i_dict, *i_key, *i_value;
   
   if( vm->self().isMethodic() )
   {
      i_dict = &vm->self();
      i_key = vm->param(0);
      i_value = vm->param(1);
   }
   else {
      i_dict = vm->param(0);
      i_key = vm->param(1);
      i_value = vm->param(2);
   }
   
   if( i_dict == 0  || ! i_dict->isDict() || i_key == 0 || i_value == 0 ) 
   {
      throw new ParamError( ErrorParam( e_inv_params, __LINE__ )
            .origin( e_orig_runtime )
            .extra( vm->self().isMethodic() ? "X,X" : "D,X,X" ) );
   }

   CoreDict *dict = i_dict->asDict();
   Item *value = dict->find( *i_key );
   if ( value == 0 )
   {
      vm->regA().setBoolean( false );
      dict->put( *i_key, *i_value );
   }
   else {
      vm->regA().setBoolean( true );
      *value = *i_value;
   }
}
Beispiel #3
0
static void internal_record_fetch( VMachine* vm, DBIRecordset* dbr, Item& target )
{
   int count = dbr->getColumnCount();

   if( target.isArray() )
   {
      CoreArray* aret = target.asArray();
      aret->resize( count );
      for ( int i = 0; i < count; i++ )
      {
         dbr->getColumnValue( i, aret->items()[i] );
      }
      vm->retval( aret );
   }
   else if( target.isDict() )
   {
      CoreDict* dret = target.asDict();
      for ( int i = 0; i < count; i++ )
      {
         String fieldName;
         dbr->getColumnName( i, fieldName );
         Item* value = dret->find( Item(&fieldName) );
         if( value == 0 )
         {
            Item v;
            dbr->getColumnValue( i, v );
            CoreString* key = new CoreString(fieldName);
            key->bufferize();
            dret->put( key, v );
         }
         else
         {
            dbr->getColumnValue( i, *value );
         }
      }
      vm->retval( dret );
   }
   /*
   else
   {
      CoreTable* tbl = dyncast<CoreTable*>(target.asObject()->getFalconData());
      ItemArray iaCols( count );

      if( tbl->order() == CoreTable::noitem )
      {
         String* fieldName = new String[count];
         for( int i = 0; i < count; ++ i )
         {
            dbr->getColumnName( i, fieldName[i] );
            iaCols.append( fieldName );
         }

         if( ! tbl->setHeader( iaCols ) )
         {
            delete[] fieldName;
            throw new DBIError( ErrorParam( FALCON_DBI_ERROR_FETCH, __LINE__ )
                  .extra("Incompatible table columns" ) );
         }

         delete[] fieldName;
      }
      else
      {
         if( tbl->order() != (unsigned) count )
         {
            throw new DBIError( ErrorParam( FALCON_DBI_ERROR_FETCH, __LINE__ )
                              .extra("Incompatible table columns" ) );
         }
      }

      // put in the values
      do {
         CoreArray* row = new CoreArray();
         row->resize( count );

         for( int i = 0; i < count; ++ i )
         {
            dbr->getColumnValue( i, row->at( i ) );
         }
         tbl->insertRow( row );
      }
      while( dbr->fetchRow() );

      vm->retval( target );
   }
   */
}