Пример #1
0
 protected function db()
 {
     if ($this->db === null) {
         $this->db = DbConnection::fromResourceName($this->settings['resource'])->getDbAdapter();
     }
     return $this->db;
 }
Пример #2
0
 /**
  * Delete table rows, optionally limited by using a filter
  *
  * @param   string  $table
  * @param   Filter  $filter
  */
 public function delete($table, Filter $filter = null)
 {
     if ($filter) {
         $filter = $this->requireFilter($table, $filter);
     }
     $this->ds->delete($this->prependTablePrefix($table), $filter);
 }
Пример #3
0
 protected function db()
 {
     if ($this->db === null) {
         $this->db = DbConnection::fromResourceName($this->settings['resource'])->getDbAdapter();
         // TODO: should be handled by resources:
         $this->db->exec("SET NAMES 'utf8'");
     }
     return $this->db;
 }
Пример #4
0
 public static function enumProperties(DbConnection $connection = null)
 {
     $properties = static::create()->listProperties();
     $props = mt('director', 'Properties');
     $vars = mt('director', 'Custom variables');
     $properties = array($props => array_combine($properties, $properties), $vars => array());
     if ($connection !== null) {
         foreach ($connection->fetchDistinctHostVars() as $var) {
             if ($var->datatype) {
                 $properties[$vars]['vars.' . $var->varname] = sprintf('%s (%s)', $var->varname, $var->caption);
             } else {
                 $properties[$vars]['vars.' . $var->varname] = $var->varname;
             }
         }
     }
     //$properties['vars.*'] = 'Other custom variable';
     ksort($properties[$vars]);
     ksort($properties[$props]);
     return $properties;
 }
 public static function loadAll(DbConnection $connection, $query = null, $keyColumn = null)
 {
     $objects = array();
     $class = get_called_class();
     $db = $connection->getDbAdapter();
     if ($query === null) {
         $dummy = new $class();
         $select = $db->select()->from($dummy->table);
     } else {
         $select = $query;
     }
     $rows = $db->fetchAll($select);
     foreach ($rows as $row) {
         $obj = new $class();
         $obj->setConnection($connection)->setDbProperties($row);
         if ($keyColumn === null) {
             $objects[] = $obj;
         } else {
             $objects[$row->{$keyColumn}] = $obj;
         }
     }
     return $objects;
 }
Пример #6
0
 /**
  * Executes sql file by using the database connection
  *
  * @param   DbConnection      $resource
  * @param   string          $filename
  *
  * @throws  RuntimeException
  */
 public function loadSql(DbConnection $resource, $filename)
 {
     if (!is_file($filename)) {
         throw new RuntimeException('Sql file not found: ' . $filename . ' (test=' . $this->getName() . ')');
     }
     $sqlData = file_get_contents($filename);
     if (!$sqlData) {
         throw new RuntimeException('Sql file is empty: ' . $filename . ' (test=' . $this->getName() . ')');
     }
     $resource->getConnection()->exec($sqlData);
 }