/** * setDb * * @param DatabaseDriver $db * * @return void */ public static function setDefaultDbo(DatabaseDriver $db = null) { self::$db = $db; if ($db) { $driver = $db->getName(); self::$instances[$driver] = $db; } }
/** * Destruct. */ public function __destruct() { if (!self::$dbo) { return; } self::$dbo->setQuery('DROP DATABASE IF EXISTS ' . self::$dbo->quoteName(static::$dbname))->execute(); self::$dbo = null; }
/** * 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(); }
/** * getFilterFields * * @return array */ public function getSelectFields() { $fields = array(); $i = 0; foreach ($this->tables as $alias => $table) { $columns = $this->db->getTable($table['name'])->getColumns(); foreach ($columns as $column) { $prefix = $table['prefix']; if ($i === 0) { $prefix = $prefix === null ? false : true; } else { $prefix = $prefix === null ? true : false; } if ($prefix === true) { $fields[] = $this->db->quoteName("{$alias}.{$column} AS {$alias}_{$column}"); } else { $fields[] = $this->db->quoteName("{$alias}.{$column} AS {$column}"); } } $i++; } return $fields; }
/** * freeResult * * @return $this */ public function freeResult() { $this->db->freeResult(); return $this; }
/** * Get the current query object or a new Query object. * * @param boolean $new False to return the current query object, True to return a new Query object. * * @return Query The current query object or a new object extending the Query class. * * @since 2.0 * @throws \RuntimeException */ public function getQuery($new = false) { if ($new) { // Derive the class name from the driver. $class = '\\Windwalker\\Query\\' . ucfirst($this->options['driver']) . '\\' . ucfirst($this->options['driver']) . 'Query'; // Make sure we have a query class for this driver. if (class_exists($class)) { $this->connect(); return new $class($this->getConnection()); } return parent::getQuery($new); } else { return $this->query; } }
/** * Quick quote name. * * @param string $value * * @return mixed */ public function qn($value) { return $this->db->quoteName($value); }
/** * Method to get the auto-incremented value from the last INSERT statement. * * @return string The value of the auto-increment field from the last inserted row. * * @since 2.0 */ public function insertId() { return $this->db->getReader()->insertId(); }