Menu

paging and tokens?

Help
2010-01-17
2013-04-29
  • Nobody/Anonymous

    hi there - i don't see anywhere in this library where the token is returned on either select or query…. so that you can then use the token for the next request (for paging through a dataset). am i just missing it?

     
  • Dan Myers

    Dan Myers - 2010-01-19

    I don't think you're missing it.  Glancing at the code, it looks like I forgot to include the "NextToken" response in the result.

    I actually need to update the library to use the newer 2009-04-15 API spec; it's using the older 2007-11-07 spec right now.

    I'll update it this week and post the new code this weekend.

     
  • Nobody/Anonymous

    Hi, just wondering what the status of this is.  I've modified your class to make this work, but it would be nice to have an official release (with the newer API spec too)

     
  • Dan Myers

    Dan Myers - 2010-02-09

    Yeah, sorry about the delay. The other dev has made all the updates, including updating to the new API spec and some other things, he's just making a few more changes before it's ready.

     
  • Nobody/Anonymous

    Here's our change to the select method to get token:

        public static function select($domain, $select, $nexttoken = null, $includeNextToken = null) {
            $rest = new SimpleDBRequest($domain, 'Select', 'GET', self::$__accessKey);
            if($select != '')
            {
                $rest->setParameter('SelectExpression', $select);
            }
            if($nexttoken !== null)
            {
                $rest->setParameter('NextToken', $nexttoken);
            }
            $rest = $rest->getResponse();
            if ($rest->error === false && $rest->code !== 200)
                $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
            if ($rest->error !== false) {
                SimpleDB::__triggerError('query', $rest->error);
                return false;
            }
            $results = array();
            //Zend_Debug::dump($rest->body->SelectResult, '$rest->body->SelectResult');die();
    
            if (!isset($rest->body->SelectResult))
            {
                return $results;
            }
            if ($includeNextToken) {
                // !! IMPORTANT !! ADD NEXT TOKEN VALUE INTO SEARCH RESULTS
                if (isset($rest->body->SelectResult->NextToken)) {
                    $results['NextToken'] = strval($rest->body->SelectResult->NextToken);
                }
            }
            foreach($rest->body->SelectResult->Item as $i)
            {
                $item = array('Name' => (string)($i->Name), 'Attributes' => array());
                foreach($i->Attribute as $a)
                {
                    if(isset($item['Attributes'][(string)($a->Name)]))
                    {
                        $temp = (array)($item['Attributes'][(string)($a->Name)]);
                        $temp[] = (string)($a->Value);
                        $item['Attributes'][(string)($a->Name)] = $temp;
                    }
                    else
                    {
                        $item['Attributes'][(string)($a->Name)] = (string)($a->Value);
                    }
                }
                $results[] = $item;
            }
            return $results;
        }
    
     
  • Anonymous

    Anonymous - 2010-02-13

    oops, i selected "Codeify" on the above snippet, but it didn't work. Trying again here:

    <pre>

    /**
    * Evaluate a select expression on a domain
    *
    * Function provided by Matthew Lanham
    *
    * @param string  $domain The domain being queried
    * @param string  $select The select expression to evaluate.
    * @param string  $nexttoken The token to start from when retrieving results
    * @return array | false
    */
    public static function select($domain, $select, $nexttoken = null, $includeNextToken = null) {
    $rest = new SimpleDBRequest($domain, 'Select', 'GET', self::$__accessKey);

    if($select != '')
    {
    $rest->setParameter('SelectExpression', $select);
    }
    if($nexttoken !== null)
    {
    $rest->setParameter('NextToken', $nexttoken);
    }

    $rest = $rest->getResponse();

    if ($rest->error === false && $rest->code !== 200)
    $rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
    if ($rest->error !== false) {
    SimpleDB::__triggerError('query', $rest->error);
    return false;
    }

    $results = array();

    //Zend_Debug::dump($rest->body->SelectResult, '$rest->body->SelectResult');die();

    if (!isset($rest->body->SelectResult))
    {
    return $results;
    }
    if ($includeNextToken) {
    // !! IMPORTANT !! ADD NEXT TOKEN VALUE INTO SEARCH RESULTS
    if (isset($rest->body->SelectResult->NextToken)) {
    $results = strval($rest->body->SelectResult->NextToken);
    }
    }
    foreach($rest->body->SelectResult->Item as $i)
    {
    $item = array('Name' => (string)($i->Name), 'Attributes' => array());
    foreach($i->Attribute as $a)
    {
    if(isset($item))
    {
    $temp = (array)($item);
    $temp = (string)($a->Value);
    $item = $temp;
    }
    else
    {
    $item = (string)($a->Value);
    }
    }
    $results = $item;
    }

    return $results;
    }
    </pre>

     
  • Nobody/Anonymous

    when is the new library gonna be released ?

     
  • Nobody/Anonymous

    btw.. did I ever mention that u guys rock….. official library provided by Amazon sucks.. this library saved my day

     
  • Dan Myers

    Dan Myers - 2010-03-02

    Thanks, I'm glad you like it :)

    A new version was uploaded today, it should have all the features you guys need.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.