Ejemplo n.º 1
0
 /**
  * Execute a query and fetch all results
  *
  * This function performs the same function as Database::prefetch(),
  * but returns an array of regular integer-indexed arrays. It is
  * faster for cases when the names of the columns are not known to the
  * query planner in advance of their execution (eg: 'SELECT * FROM
  * table').
  *
  * @param string $str The query string
  * @param array $params The query paramters
  * @param string $name The query name
  * @throws DatabaseException
  * @return array
  */
 public static function prefetch_int($str, $params = array(), $name = null)
 {
     $ret = array();
     $r = Database::query($str, $params, $name);
     while ($row = pg_fetch_row($r)) {
         $ret[] = $row;
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * Create a new entry in the database based on current Model data
  *
  * Runs an INSERT query against the database, based on the current
  * contents of the "dirty" array.
  *
  * @return Model
  */
 protected function _insert()
 {
     $table = $this->table();
     $cols = $this->columns();
     $names = array();
     $holds = array();
     $vals = array();
     $rets = array();
     $x = 1;
     foreach ($cols as $name => $col) {
         $qname = Database::quote_identifier($name);
         array_push($rets, $qname);
         if ($col->primary_key()) {
             continue;
         }
         $val = $col->prep_for_database($this->column($name));
         array_push($names, $qname);
         array_push($holds, '$' . $x++);
         array_push($vals, $val);
     }
     $names = join(', ', $names);
     $holds = join(', ', $holds);
     $rets = join(', ', $rets);
     $table = Database::quote_identifier($table);
     $query = "INSERT INTO {$table} ({$names}) VALUES ({$holds}) " . "RETURNING {$rets}";
     $results = Database::prefetch($query, $vals, "_insert_{$table}");
     $this->_set_all($results[0]);
     return $this;
 }