Пример #1
0
 public function test_fetch_all()
 {
     $numRowsInDB = Model\Generic::query('select count(*) as count from scoop.test')->first()->count;
     $numRowsFetched = 0;
     $limit = 1000;
     $offset = 0;
     while ($tests = Test::fetch_all($limit, $offset)) {
         $numRowsFetched += $tests->get_num_rows();
         $offset += $limit;
     }
     $this->assertEquals($numRowsInDB, $numRowsFetched, "fetch_all should fetch all rows");
 }
Пример #2
0
 public function test_is_loaded_from_db()
 {
     $generic = new Generic();
     $this->assertFalse($generic->get_loaded_from_database(), "created models should not be marked loaded from the database");
     $this->assertTrue(\DB\Scoop\Test::fetch_one()->get_loaded_from_database(), "fetched models should be marked as loaded from the database");
 }
Пример #3
0
 /**
  * Flushes the buffer to the db
  *
  * @throws \Exception
  */
 public function flush()
 {
     if ($this->size === 0) {
         return false;
     }
     //  remove trailing commas from built sql values
     $this->insertValuesSql = rtrim($this->insertValuesSql, ',');
     // build insert statement
     $sql = "INSERT " . ($this->insertIgnore ? 'IGNORE ' : '') . "INTO\n              {$this->table}(\n                {$this->columnNames}\n              )\n              VALUES\n              {$this->insertValuesSql}\n            ";
     // do the insert
     Generic::query($sql, $this->queryParams);
     // update models with their autoincrement ids
     $insertId = Generic::$connection->get_insert_id();
     if ($insertId) {
         foreach ($this->models as &$model) {
             $model->__set($model::AUTO_INCREMENT_COLUMN, $insertId++);
             $model->set_loaded_from_database(true);
         }
     }
     $this->reset();
     $this->events->trigger('flush', $this);
     return true;
 }
Пример #4
0
 public function test_get_statement_from_sql()
 {
     $this->expectException(Exception::class);
     \Scoop\Database\Model\Generic::query("SELECT\n                *\n            FROM\n              `something`.`that_doesnt_exist`");
 }