/**
  * Generate our fancypants Query Exception
  * @param $error
  * @param $sql
  * @return Exception
  */
 public function __construct($resource, $sql, Debug $debug)
 {
     $this->sql = $sql;
     $this->sqlError = pg_last_error($resource);
     // get the search path and add to exception message
     try {
         $qSearchPath = pg_query($resource, "SHOW search_path");
         $searchPath = pg_fetch_row($qSearchPath);
         $this->sqlError .= "\nSEARCH_PATH IS '{$searchPath[0]}'";
     } catch (\Exception $e) {
     }
     // build the debugging events we plan to emit
     $events = [self::QUERY_ERROR];
     // Not exactly happy to be doing this manually. Not cool postgres. Not cool.
     // http://www.postgresql.org/docs/8.4/static/errcodes-appendix.htm
     if ($haveState = preg_match('/ERROR:\\s+([A-Z0-9]{5}):/', $this->sqlError, $matches)) {
         $this->state = $matches[1];
         for ($i = 5; $i > 0; $i--) {
             $events[] = str_pad(substr($this->state, 0, $i), 5, '0');
         }
     } else {
         $this->state = 'EMPTY';
     }
     // emit out events
     foreach ($events as $eventName) {
         $debug->emit($eventName, $this->sql, $this->sqlError, $this->state);
     }
 }
Example #2
0
 /**
  * Manage a database connection
  *
  * @param PgResource $resource
  */
 public function __construct($resource, $name = null)
 {
     $this->resource = $resource;
     $this->name = (string) $name;
     $this->debug = Debug::get(__CLASS__);
 }
Example #3
0
 public function testObjectInstantiation()
 {
     $this->assertTrue(Debug::get() instanceof DebugUnitTest);
 }