Ejemplo n.º 1
0
 protected final function insert($tableName, $data)
 {
     $driver = $this->db->getDriver();
     $id = $driver->insert($this->db, $tableName, $data);
     echo 'Data into table ' . $tableName . ' is inserted' . "\n";
     return $id;
 }
Ejemplo n.º 2
0
 /**
  * Создает пустое место в дереве заданной ширины
  * Место создается ВНУТРИ элемента с заданным rgt как ПОСЛЕДНИЙ его потомок
  * @param \T4\Dbal\Connection $connection
  * @param string $table
  * @param int $rgt
  * @param int $width
  */
 protected function expandTreeBeforeRgt(Connection $connection, $table, $rgt, $width)
 {
     $query = new QueryBuilder();
     $query->update()->table($table)->values(['__lft' => 'CASE WHEN __lft>=:rgt THEN __lft + (:width + 1) ELSE __lft END', '__rgt' => 'CASE WHEN __rgt>=:rgt THEN __rgt + (:width + 1) ELSE __rgt END'])->where('__lft>=:rgt OR __rgt>=:rgt')->order('__lft DESC');
     $query->params([':rgt' => $rgt, ':width' => $width]);
     $connection->execute($query);
 }
Ejemplo n.º 3
0
 public function insert(Connection $connection, $tableName, array $data)
 {
     $sql = 'INSERT INTO ' . $this->quoteName($tableName) . '';
     $sql .= ' ("' . implode('", "', array_keys($data)) . '")';
     $sql .= ' VALUES';
     $values = [];
     foreach ($data as $key => $val) {
         $values[':' . $key] = $val;
     }
     $sql .= ' (' . implode(', ', array_keys($values)) . ')';
     $connection->execute($sql, $values);
     return $connection->lastInsertId();
 }
Ejemplo n.º 4
0
 /**
  * get name of the sequence that a serial or bigserial column uses
  * @param Connection $connection
  * @param string $tableName
  *
  * @return string
  */
 protected function getSequenceName(Connection $connection, $tableName)
 {
     $PkColumns = $connection->query("SELECT a.attname, format_type(a.atttypid, a.atttypmod) AS data_type\n            FROM   pg_index i\n            JOIN   pg_attribute a ON a.attrelid = i.indrelid\n                                 AND a.attnum = ANY(i.indkey)\n            WHERE  i.indrelid = :table_name::regclass\n            AND    i.indisprimary;", [':table_name' => $tableName])->fetchAll(\PDO::FETCH_ASSOC);
     $PkColumnsCount = count($PkColumns);
     if ($PkColumnsCount != 1) {
         return null;
     }
     return $connection->query('select pg_get_serial_sequence(:table_name, :column_name)', [':table_name' => $tableName, ':column_name' => $PkColumns[0]['attname']])->fetchScalar();
 }