Example #1
0
 /**
  * Drop a database table
  * Destructive and dangerous - drops entire table and all data
  * Will throw errors if user does not have proper permissions
  */
 public function dropDatabase($database)
 {
     $sql = "DROP DATABASE " . $database;
     // Add query to log
     \Spot\Log::addQuery($this, $sql);
     return $this->connection()->exec($sql);
 }
Example #2
0
 /**
  * Debug Spot queries by dumping query log
  */
 public function debugQueryLog()
 {
     if ($this->kernel->config('app.debug')) {
         // Executed queries
         echo "<hr />";
         echo "<h1>Executed Queries (" . \Spot\Log::queryCount() . ")</h1>";
         echo "<pre>";
         print_r(\Spot\Log::queries());
         echo "</pre>";
     }
 }
Example #3
0
 public function testQueryCountIsNotCachedForDifferentQueryResult()
 {
     $mapper = test_spot_mapper();
     $posts = $mapper->all('\\Spot\\Entity\\Post');
     $this->assertEquals(10, $posts->count());
     // Count # of queries
     $count1 = \Spot\Log::queryCount();
     // Change query so count will NOT be cached
     $this->assertEquals(3, $posts->where(array('status' => array(3, 4, 5)))->count());
     // Count again to ensure it is NOT cached since there are query changes
     $count2 = \Spot\Log::queryCount();
     $this->assertNotEquals($count1, $count2);
 }
Example #4
0
 /**
  * Truncate a database table
  * Should delete all rows and reset serial/auto_increment keys to 0
  */
 public function truncateDatasource($datasource)
 {
     $sql = "DELETE FROM " . $datasource;
     // Add query to log
     \Spot\Log::addQuery($this, $sql);
     try {
         return $this->connection()->exec($sql);
     } catch (\PDOException $e) {
         // Table does not exist
         if ($e->getCode() == "42S02") {
             throw new \Spot\Exception_Datasource_Missing("Table or datasource '" . $datasource . "' does not exist");
         }
         // Re-throw exception
         throw $e;
     }
 }
Example #5
0
 public function testQueryHasOneWith()
 {
     $mapper = test_spot_mapper();
     $count1 = \Spot\Log::queryCount();
     $posts = $mapper->all('Entity_Post')->with(array('author'))->execute();
     $count2 = \Spot\Log::queryCount();
     // @todo: Theoretically, 'HasOne' calls could be added as JOIN
     $this->assertEquals($count1 + 2, $count2);
     foreach ($posts as $post) {
         $this->assertEquals($post->author_id, $post->author->id);
         $this->assertInstanceOf('\\Spot\\Relation\\HasOne', $post->author);
     }
     $count3 = \Spot\Log::queryCount();
     $this->assertEquals($count1 + 2, $count3);
 }