Exemplo n.º 1
0
 /**
  * Destruct.
  */
 public function __destruct()
 {
     if (!self::$dbo) {
         return;
     }
     self::$dbo->setQuery('DROP DATABASE IF EXISTS ' . self::$dbo->quoteName(static::$dbname))->execute();
     self::$dbo = null;
 }
Exemplo n.º 2
0
 /**
  * gc
  *
  * @param string $past
  *
  * @return  bool
  */
 public function gc($past)
 {
     $query = $this->db->getQuery(true);
     $query->delete($this->db->quoteName($this->options['table']))->where($this->db->quoteName($this->options['time_col']) . ' < ' . $this->db->quote((int) $past));
     // Remove expired sessions from the database.
     $this->db->setQuery($query);
     return (bool) $this->db->execute();
 }
Exemplo n.º 3
0
 /**
  * Validate that the primary key has been set.
  *
  * @return  boolean  True if the primary key(s) have been set.
  *
  * @since   2.0
  */
 public function hasPrimaryKey()
 {
     if ($this->autoIncrement) {
         $empty = true;
         foreach ($this->keys as $key) {
             $empty = $empty && !$this->{$key};
         }
     } else {
         $query = $this->db->getQuery(true);
         $query->select('COUNT(*)')->from($this->table);
         $this->appendPrimaryKeys($query);
         $this->db->setQuery($query);
         $count = $this->db->loadResult();
         if ($count == 1) {
             $empty = false;
         } else {
             $empty = true;
         }
     }
     return !$empty;
 }
Exemplo n.º 4
0
 /**
  * Batch update some data.
  *
  * @param string $table      Table name.
  * @param array  $data       Data you want to update.
  * @param mixed  $conditions Where conditions, you can use array or Compare object.
  *                           Example:
  *                           - `array('id' => 5)` => id = 5
  *                           - `new GteCompare('id', 20)` => 'id >= 20'
  *                           - `new Compare('id', '%Flower%', 'LIKE')` => 'id LIKE "%Flower%"'
  *
  * @return  boolean True if update success.
  */
 public function updateBatch($table, $data, $conditions = array())
 {
     $query = $this->db->getQuery(true);
     // Build conditions
     $query = QueryHelper::buildWheres($query, $conditions);
     // Build update values.
     $fields = array_keys($this->db->getTable($table)->getColumns());
     $hasField = false;
     foreach ((array) $data as $field => $value) {
         if (!in_array($field, $fields)) {
             continue;
         }
         $query->set($query->format('%n = %q', $field, $value));
         $hasField = true;
     }
     if (!$hasField) {
         return false;
     }
     $query->update($table);
     return $this->db->setQuery($query)->execute();
 }
Exemplo n.º 5
0
 /**
  * setQuery
  *
  * @param Query $query
  *
  * @return  $this
  */
 public function setQuery($query)
 {
     $this->db->setQuery($query);
     return $this;
 }
Exemplo n.º 6
0
 /**
  * Sets the SQL statement string for later execution.
  *
  * @param   mixed    $query          The SQL statement to set either as a JDatabaseQuery object or a string.
  * @param   array    $driverOptions  The optional PDO driver options
  *
  * @return  PdoDriver  This object to support method chaining.
  *
  * @since   2.0
  */
 public function setQuery($query, $driverOptions = array())
 {
     $this->connect()->freeResult();
     $this->driverOptions = $driverOptions;
     // Store reference to the DatabaseQuery instance:
     parent::setQuery($query);
     return $this;
 }