コード例 #1
0
 public function testBindInsertAnonymous()
 {
     $query = new SDBStatement("INSERT INTO cars (brand, colour, doors) VALUES ( ?, 'black', ? )");
     $this->assertTrue($query->execute(array('Dodge', 2)));
     $id = SDBStatement::LastInsertId();
     $car = Mock\SDBCar::Find($id);
     $this->assertEquals('Dodge', $car->brand);
     $this->assertEquals('black', $car->colour);
     $this->assertEquals(2, $car->doors);
 }
コード例 #2
0
ファイル: SDBResponse.php プロジェクト: laiello/flexible-orm
 /**
  * Ensure the query is complete
  *
  * Amazon SDB only returns a limited set of data (usually around 100 results).
  * Calling this method will ensure that SDB is queried until all results are
  * returned. It will stop retrieving results when MAX_QUERIES is reached.
  *
  * Additionally returned items are appended to this response object's items
  * array.
  *
  * \note Only works with Select statements. It should not be neccasary for
  *       others, except maybe getAttributes if you have a large number of
  *       attributes or listDomains if you have a lot.
  * 
  * \note The $consistentRead parameter must have the same value as the original
  *       command, if the original query was run with consistentRead==true, 
  *       then getAll() must be called as getAll(true)
  *
  * @param boolean $consistentRead
  *      [optional] defaults to false. Tell SDB whether or not to force consistency.
  *      This must be the same as the original query (ie if the original query
  *      enforced consistent read, this must be true)
  * @param int $resultsLimit
  *      [optional] Maximum number of records to return (including the original items)
  *      Defaults to no limit (other than those imposed by MAX_QUERIES).
  * @param int $offset
  *      [optional] Number of rows to skip from beinging when used with limit.
  *      Defaults to 0 (start from beginning).
  * @param int $currentOffset
  *      The number of rows already skipped. Defaults to 0 (started from beginning).
  * @return SDBResponse
  *      The current SDBResponse item is returned for convenience
  */
 public function getAll($consistentRead = false, $resultsLimit = null, $offset = 0, $currentOffset = 0)
 {
     if (isset($this->body->SelectResult)) {
         $result = $this;
         $query = $this->getQuery();
         $count = 0;
         if ($currentOffset < $offset) {
             $this->clear();
         }
         if ($resultsLimit) {
             $limit = $resultsLimit;
             $currentOffset += count($this->_items);
             NextTokenCache::Store($query, $limit, $currentOffset, $result->nextToken());
             $query = str_replace("LIMIT {$limit}", '', $query);
         } else {
             $limit = 2400;
         }
         // Continue querying SDB until all items have been fetched or limit is reached
         while ((is_null($resultsLimit) || count($this->_items) < $resultsLimit) && $result->nextToken()) {
             $limitRemaining = is_null($resultsLimit) ? $limit : $this->_limitRemaining($limit, $offset, $currentOffset);
             $result = SDBStatement::Query("{$query} LIMIT {$limitRemaining}", $consistentRead, $result->nextToken());
             $this->_setItems($result);
             $currentOffset += count($result);
             NextTokenCache::Store("{$query} LIMIT {$limitRemaining}", $limit, $currentOffset, $result->nextToken());
             if (++$count > self::MAX_QUERIES) {
                 break;
             }
         }
     }
     return $this;
 }
コード例 #3
0
ファイル: ORMModelSDB.php プロジェクト: laiello/flexible-orm
 /**
  * Override the ORM_Model::_BuildSQLFindWith() to work with SDB
  *
  * Uses the SDBStatment::$findWith static variable, which is not a very nice
  * way to do this.
  *
  * @param string $table
  * @param array|string $findWith
  * @return string
  *      SQL Query
  */
 protected static function _BuildSQLFindWith($table, $findWith)
 {
     SDBStatement::$findWith = (array) $findWith;
     $className = static::ClassName();
     return "SELECT `{$className}`.* FROM `{$table}` AS `{$className}` ";
 }
コード例 #4
0
ファイル: TagsTest.php プロジェクト: laiello/flexible-orm
 public function setUp()
 {
     $this->sdb = SDBStatement::GetSDBConnection();
 }
コード例 #5
0
 protected function tearDown()
 {
     $sdb = \ORM\SDB\SDBStatement::GetSDBConnection();
     $sdb->delete_domain(Mock\File::TableName());
     $sdb->delete_domain(Mock\SDBCar::TableName());
 }