function __construct(Poodle_SQL $SQL) { $this->SQL = $SQL; $this->prefix = $this->SQL->TBL->prefix; $this->platform = strtolower($SQL->engine); $this->tables = $SQL->list_tables(); }
function __construct($adapter, $master_config, $prefix, $slave_config = null) { if (!self::$path) { self::$path = realpath(dirname(__FILE__)) . '/'; } if (!$adapter) { throw new Exception('Poodle SQL adapter not configured'); } $adapter_file = self::$path . 'adapter/' . strtolower($adapter) . '.php'; if (!is_readable($adapter_file)) { throw new Exception('Poodle SQL adapter not found'); } include_once $adapter_file; $adapter = 'Poodle_SQL_Adapter_' . ucfirst($adapter); $this->DBM = new $adapter($master_config); if ($slave_config) { $this->DBS = new $adapter($slave_config); } $this->TBL = new Poodle_SQL_Tables($this, $prefix, constant(get_class($this->DBM) . '::TBL_QUOTE')); $this->debug = Poodle::$DEBUG; }
function __call($method, $args) { switch ($method) { case 'list_tables': global $prefix, $user_prefix; $result = parent::__call($method, $args); $tables = array(); foreach ($result as $name) { $tables[preg_replace("#^({$prefix}|{$user_prefix})_#", '', $name)] = $name; } return $tables; case 'list_columns': $return = parent::__call($method, $args); foreach ($return as $field => $row) { $row['Type'] = strtoupper($row['type']); if (!empty($args[1])) { $row['Type'] = str_replace('SERIAL', 'SERIAL4', str_replace('BIGSERIAL', 'SERIAL8', $row['Type'])); } $return[$field]['Field'] = $field; $return[$field]['Type'] = $row['Type']; $return[$field]['Null'] = intval(!$row['notnull']); $return[$field]['Default'] = $row['default']; $return[$field]['Extra'] = $row['extra']; $return[$field]['Comment'] = $row['comment']; } return $return; case 'list_indexes': $return = parent::__call($method, $args); foreach ($return as $key => $row) { $return[$key]['name'] = $key; $return[$key]['unique'] = 'UNIQUE' == $row['type']; } return $return; case 'get_versions': case 'get_details': case 'create_table': case 'alter_table': case 'drop_table': case 'alter_field': case 'alter_index': case 'increment_serial': case 'optimize_table': if (empty($this->dfmngr)) { $class = 'Poodle_SQL_DfMngr_' . $this->engine; $this->dfmngr = new $class($this); } return call_user_func_array(array($this->dfmngr, $method), $args); # this is slow } return parent::__call($method, $args); }