/**
  * TestRenameTable method
  *
  * @return void
  */
 public function testRenameTable()
 {
     $this->loadFixtures('User', 'Post');
     $Migration = new TestPrecheckCakeMigration(array('up' => array('rename_table' => array('posts' => 'renamed_posts')), 'down' => array('rename_table' => array('renamed_posts' => 'posts')), 'precheck' => 'Migrations.PrecheckCondition'));
     $Migration->initDb();
     $this->assertTrue($Migration->Precheck->beforeAction($Migration, 'rename_table', array('old_name' => $this->db->fullTableName('posts', false, false), 'new_name' => $this->db->fullTableName('renamed_posts', false, false))));
     $sources = $this->db->listSources();
     $this->assertTrue(in_array($this->db->fullTableName('posts', false, false), $sources));
     $this->assertFalse(in_array($this->db->fullTableName('renamed_posts', false, false), $sources));
     $this->assertTrue($Migration->run('up'));
     $sources = $this->db->listSources();
     $this->assertFalse(in_array($this->db->fullTableName('posts', false, false), $sources));
     $this->assertTrue(in_array($this->db->fullTableName('renamed_posts', false, false), $sources));
     $this->assertFalse($Migration->Precheck->beforeAction($Migration, 'rename_table', array('old_name' => $this->db->fullTableName('posts', false, false), 'new_name' => $this->db->fullTableName('renamed_posts', false, false))));
     $this->assertTrue($Migration->Precheck->beforeAction($Migration, 'rename_table', array('old_name' => $this->db->fullTableName('renamed_posts', false, false), 'new_name' => $this->db->fullTableName('posts', false, false))));
     try {
         $Migration->run('up');
     } catch (MigrationException $e) {
         $this->fail('Exception triggered: ' . $e->getMessage());
     }
     $this->assertTrue($Migration->run('down'));
     $this->assertFalse($Migration->Precheck->beforeAction($Migration, 'rename_table', array('old_name' => $this->db->fullTableName('renamed_posts', false, false), 'new_name' => $this->db->fullTableName('posts', false, false))));
     $this->assertTrue($Migration->Precheck->beforeAction($Migration, 'rename_table', array('old_name' => $this->db->fullTableName('posts', false, false), 'new_name' => $this->db->fullTableName('renamed_posts', false, false))));
     $sources = $this->db->listSources();
     $this->assertTrue(in_array($this->db->fullTableName('posts', false, false), $sources));
     $this->assertFalse(in_array($this->db->fullTableName('renamed_posts', false, false), $sources));
 }
Example #2
0
 /**
  * Tests that SELECT queries from DboSqlite::listSources() are not cached
  *
  * @return void
  */
 public function testTableListCacheDisabling()
 {
     $this->assertFalse(in_array('foo_test', $this->Dbo->listSources()));
     $this->Dbo->query('CREATE TABLE foo_test (test VARCHAR(255))');
     $this->assertTrue(in_array('foo_test', $this->Dbo->listSources()));
     $this->Dbo->cacheSources = false;
     $this->Dbo->query('DROP TABLE foo_test');
     $this->assertFalse(in_array('foo_test', $this->Dbo->listSources()));
 }
Example #3
0
 /**
  * Check the database status before installation.
  *
  * @return bool
  */
 public function checkStatus()
 {
     if (!$this->db->isConnected()) {
         $this->out(sprintf('<error>Database connection for %s failed!</error>', FORUM_DATABASE));
         return false;
     }
     // Check the required tables
     $tables = $this->db->listSources();
     $checkFor = array($this->install['table'], 'aros', 'acos', 'aros_acos');
     $this->out(sprintf('The following tables are required: %s', implode(', ', $checkFor)));
     $this->out('<info>Checking tables...</info>');
     foreach ($checkFor as $table) {
         if (!in_array($table, $tables)) {
             $this->out(sprintf('<error>No %s table was found in %s</error>', $table, FORUM_DATABASE));
             return false;
         }
     }
     $this->out('<info>Installation status good, proceeding...</info>');
     return true;
 }
Example #4
0
 /**
  * Returns an array of all the tables in the database.
  * Should call parent::listSources twice in the method:
  * once to see if the list is cached, and once to cache
  * the list if not.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $result = db2_tables($this->connection);
     $tables = array();
     while (db2_fetch_row($result)) {
         $tables[] = strtolower(db2_result($result, 'TABLE_NAME'));
     }
     parent::listSources($tables);
     return $tables;
 }
Example #5
0
 /**
  * テーブルの全てのリストを取得する
  * 
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $folder = new Folder($this->config['database']);
     $result = $folder->read(true, true);
     if (empty($result[1])) {
         return array();
     } else {
         $tables = array();
         foreach ($result[1] as $csv) {
             if (preg_match('/^' . $this->config['prefix'] . '[a-z0-9]/', $csv)) {
                 $tables[] = str_replace('.csv', '', $csv);
             }
         }
         parent::listSources($tables);
         return $tables;
     }
 }
Example #6
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $stmt = oci_parse($this->connection, "select * from tab");
     $res = oci_execute($stmt, OCI_DEFAULT);
     if (!$res) {
         return array();
     } else {
         $tables = array();
         while (oci_fetch($stmt)) {
             $tables[] = strtolower(oci_result($stmt, "TNAME"));
         }
         parent::listSources($tables);
         return $tables;
     }
 }
Example #7
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $result = $this->fetchAll('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES', false);
     if (!$result || empty($result)) {
         return array();
     } else {
         $tables = array();
         foreach ($result as $table) {
             $tables[] = $table[0]['TABLE_NAME'];
         }
         parent::listSources($tables);
         return $tables;
     }
 }
Example #8
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $result = $this->_execute("select name from sysobjects where type='U'");
     if (!$result) {
         return array();
     } else {
         $tables = array();
         while ($line = sybase_fetch_array($result)) {
             $tables[] = $line[0];
         }
         parent::listSources($tables);
         return $tables;
     }
 }
Example #9
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 public function listSources()
 {
     $cache = parent::listSources();
     if ($cache !== null) {
         return $cache;
     }
     $result = $this->_execute("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'");
     if (!$result) {
         $result->closeCursor();
         return array();
     } else {
         $tables = array();
         while ($line = $result->fetch()) {
             $tables[] = $line[0];
         }
         $result->closeCursor();
         parent::listSources($tables);
         return $tables;
     }
 }
Example #10
0
 /**
  * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
  *
  * @param mixed $data
  * @return array Array of table names in the database
  */
 public function listSources($data = null)
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $schema = $this->config['schema'];
     $sql = "SELECT table_name as name FROM INFORMATION_SCHEMA.tables WHERE table_schema = ?";
     $result = $this->_execute($sql, array($schema));
     if (!$result) {
         return array();
     } else {
         $tables = array();
         foreach ($result as $item) {
             $tables[] = $item->name;
         }
         $result->closeCursor();
         parent::listSources($tables);
         return $tables;
     }
 }
Example #11
0
 /**
  * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
  *
  * @return array Array of tablenames in the database
  * @access public
  */
 function listSources()
 {
     //echo "runs listSources\n";
     $db = $this->config['database'];
     $this->config['database'] = basename($this->config['database']);
     $cache = parent::listSources();
     if ($cache != null) {
         // >>> ADD 2010/03/19 egashira
         // 接続をフルパスに戻す
         $this->config['database'] = $db;
         // <<<
         return $cache;
     }
     //echo "listsources:beforeresult ";
     // >>> CUSTOMIZE MODIFY 2010/12/26 ryuring
     //$result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", false);
     // ---
     $result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' AND name<>'sqlite_sequence' ORDER BY name;", false);
     // <<<
     //echo "listsources:result ";
     //pr($result);
     if (!$result || empty($result)) {
         // >>> ADD 2010/03/19 egashira
         // 接続をフルパスに戻す
         $this->config['database'] = $db;
         // <<<
         return array();
     } else {
         $tables = array();
         foreach ($result as $table) {
             $tables[] = $table[0]['name'];
         }
         parent::listSources($tables);
         $this->config['database'] = $db;
         return $tables;
     }
     $this->config['database'] = $db;
     return array();
 }
Example #12
0
 /**
  * Returns an array of tables in the database. If there are no tables, an error is
  * raised and the application exits.
  *
  * @return array tablenames in the database
  * @access public
  */
 function listSources($data = null)
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $ownerClause = '';
     $sql = "SELECT owner, view_name AS name FROM all_views {$ownerClause} UNION SELECT owner, table_name AS name FROM all_tables {$ownerClause} ORDER BY 1, 2";
     if (!$this->execute($sql)) {
         return false;
     }
     $sources = array();
     if (!empty($this->config['prefix'])) {
         while ($r = $this->fetchRow()) {
             $sources[] = strtolower($r[0]['owner'] . '.' . $r[0]['name']);
         }
     } else {
         while ($r = $this->fetchRow()) {
             $sources[] = strtolower($r[0]['name']);
         }
     }
     parent::listSources($sources);
     return $sources;
 }
Example #13
0
 /**
  * Returns an array of tables in the database. If there are no tables, an error is
  * raised and the application exits.
  *
  * @return array tablenames in the database
  * @access public
  */
 function listSources($data = null)
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $sql = 'SELECT view_name AS name FROM all_views' . ($this->_defaultSchema ? ' WHERE owner = \'' . $this->_defaultSchema . '\'' : '') . ' UNION SELECT table_name AS name FROM all_tables' . ($this->_defaultSchema ? ' WHERE owner = \'' . $this->_defaultSchema . '\'' : '');
     if (!$this->execute($sql)) {
         return false;
     }
     $sources = array();
     while ($r = $this->fetchRow()) {
         $sources[] = strtolower($r[0]['name']);
     }
     parent::listSources($sources);
     return $sources;
 }
Example #14
0
 public function testTruncateLongIndexKey()
 {
     $migration = new TestCakeMigration(array('up' => array('create_table' => array('migration_categories' => array('id' => array('type' => 'string', 'length ' => 36, 'null' => false, 'key' => 'primary'), 'description' => array('type' => 'string', 'null' => false, 'length' => 256, 'default' => null), 'info' => array('type' => 'string', 'length' => 256, 'null' => false, 'default' => null), 'indexes' => array('TESTING_INDEX' => array('column' => array('description', 'info'), 'unique' => 1))))), 'down' => array('drop_table' => array('migration_categories'))));
     $sources = $this->db->listSources();
     $this->assertFalse(in_array($this->db->fullTableName('migration_categories', false, false), $sources));
     try {
         $migration->run('up');
         $this->fail('No exception triggered');
     } catch (MigrationException $e) {
         $this->assertPattern('/SQL Error/', $e->getMessage());
     }
     $this->assertFalse(in_array($this->db->fullTableName('migration_categories', false, false), $sources));
 }
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $result = $this->fetchAll('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES', false);
     $syn = $this->fetchAll('select SUBSTRING(base_object_name,2,LEN(base_object_name)-2) as object,name as TABLE_NAME  from sys.synonyms', false);
     if (!$result || empty($result)) {
         return array();
     } else {
         $tables = array();
         foreach ($result as $table) {
             $tables[] = $table[0]['TABLE_NAME'];
         }
         foreach ($syn as $table) {
             //				$tables[] = $table[0]['TABLE_NAME'];
             $this->synonyms[$table[0]['TABLE_NAME']] = $table[0]['object'];
         }
         //			debug($this->synonyms);
         parent::listSources($tables);
         return $tables;
     }
 }
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $sql = "select RDB" . "\$" . "RELATION_NAME as name\n\t\t\t\tFROM RDB" . "\$" . "RELATIONS\n\t\t\t\tWhere RDB" . "\$" . "SYSTEM_FLAG =0";
     $result = @ibase_query($this->connection, $sql);
     $tables = array();
     while ($row = ibase_fetch_row($result)) {
         $tables[] = strtolower(trim($row[0]));
     }
     parent::listSources($tables);
     return $tables;
 }
Example #17
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $result = odbc_tables($this->connection);
     $tables = array();
     while (odbc_fetch_row($result)) {
         array_push($tables, odbc_result($result, 'TABLE_NAME'));
     }
     parent::listSources($tables);
     return $tables;
 }
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @param mixed $data
  * @return array Array of table names in the database
  */
 public function listSources($data = null)
 {
     $cache = parent::listSources();
     if ($cache !== null) {
         return $cache;
     }
     $result = $this->_execute("SELECT view_name name FROM user_views UNION SELECT table_name name FROM user_tables");
     if (!$result) {
         $result->closeCursor();
         return array();
     }
     $tables = array();
     while ($line = $result->fetch(PDO::FETCH_NUM)) {
         $tables[] = strtolower($line[0]);
     }
     $result->closeCursor();
     parent::listSources($tables);
     return $tables;
 }
Example #19
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @param mixed $data
  * @return array Array of table names in the database
  */
 public function listSources($data = null)
 {
     $cache = parent::listSources();
     if ($cache !== null) {
         return $cache;
     }
     $result = $this->_execute("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES");
     if (!$result) {
         $result->closeCursor();
         return array();
     }
     $tables = array();
     while ($line = $result->fetch(PDO::FETCH_NUM)) {
         $tables[] = $line[0];
     }
     $result->closeCursor();
     parent::listSources($tables);
     return $tables;
 }
Example #20
0
 /**
  * Returns an array of tables in the database. If there are no tables, an error is
  * raised and the application exits.
  *
  * @return array tablenames in the database
  * @access public
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $sql = 'SELECT view_name AS name FROM all_views UNION SELECT table_name AS name FROM all_tables';
     if (!$this->execute($sql)) {
         return false;
     }
     $sources = array();
     while ($r = $this->fetchRow()) {
         $sources[] = strtolower($r[0]['name']);
     }
     return $sources;
 }
Example #21
0
 /**
  * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
  *
  * @param mixed $data Unused.
  * @return array Array of table names in the database
  */
 public function listSources($data = null)
 {
     $cache = parent::listSources();
     if ($cache) {
         return $cache;
     }
     $result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;", false);
     if (!$result || empty($result)) {
         return array();
     }
     $tables = array();
     foreach ($result as $table) {
         $tables[] = $table[0]['name'];
     }
     parent::listSources($tables);
     return $tables;
 }
 /**
  * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $schema = $this->config['schema'];
     $sql = "SELECT table_name as name FROM INFORMATION_SCHEMA.tables WHERE table_schema = '{$schema}';";
     $result = $this->fetchAll($sql, false);
     if (!$result) {
         return array();
     } else {
         $tables = array();
         foreach ($result as $item) {
             $tables[] = $item[0]['name'];
         }
         parent::listSources($tables);
         return $tables;
     }
 }
Example #23
0
 /**
 	 205:  * Returns an array of sources (tables) in the database.
 	 206:  *
 	 207:  * @param mixed $data
 	 208:  * @return array Array of table names in the database
 	 209:  */
 public function listSources($data = null)
 {
     $cache = parent::listSources();
     if ($cache) {
         return $cache;
     }
     $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']));
     if (!$result) {
         $result->closeCursor();
         return array();
     }
     $tables = array();
     while ($line = $result->fetch(PDO::FETCH_NUM)) {
         $tables[] = $line[0];
     }
     $result->closeCursor();
     parent::listSources($tables);
     return $tables;
 }
Example #24
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $result = $this->_execute('SHOW TABLES FROM ' . $this->name($this->config['database']) . ';');
     if (!$result) {
         return array();
     } else {
         $tables = array();
         while ($line = mysqli_fetch_array($result)) {
             $tables[] = $line[0];
         }
         parent::listSources($tables);
         return $tables;
     }
 }
 /**
  * Check if the provided $table exists.
  *
  * @param string $table
  * @return bool
  */
 public function tableExists($table)
 {
     return in_array($this->_db->fullTableName($table, false, false), $this->_db->listSources());
 }
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $result = $this->_execute("SELECT name FROM sysobjects WHERE type IN ('U', 'V')");
     if (!$result) {
         return array();
     } else {
         $tables = array();
         while ($line = sybase_fetch_array($result)) {
             $tables[] = $line[0];
         }
         parent::listSources($tables);
         return $tables;
     }
 }
Example #27
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     /*$result = odbc_tables($this->connection);
     		if (function_exists('odbc_fetch_row')) {
     			echo 'GOOD';
     		} else {
     			echo 'BAD';
     		}*/
     $result = odbc_tables($this->connection);
     $tables = array();
     while (odbc_fetch_row($result)) {
         array_push($tables, odbc_result($result, "TABLE_NAME"));
     }
     parent::listSources($tables);
     return $tables;
 }
Example #28
0
 /**
  * Returns an array of tables in the database. If there are no tables, an error is raised and the application exits.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $db = $this->config['database'];
     $this->config['database'] = basename($this->config['database']);
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $result = $this->fetchAll("SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;");
     if (!$result || empty($result)) {
         return array();
     } else {
         $tables = array();
         foreach ($result as $table) {
             $tables[] = $table[0]['name'];
         }
         parent::listSources($tables);
         $this->config['database'] = $db;
         return $tables;
     }
     $this->config['database'] = $db;
     return array();
 }
Example #29
0
 /**
  * Returns an array of sources (tables) in the database.
  *
  * @return array Array of tablenames in the database
  */
 function listSources()
 {
     $cache = parent::listSources();
     if ($cache != null) {
         return $cache;
     }
     $tables = array();
     $result = mysql_list_tables($this->config['database'], $this->connection);
     if ($result) {
         while ($line = mysql_fetch_array($result)) {
             $tables[] = $line[0];
         }
     }
     if (empty($tables)) {
         $result = $this->query('SHOW TABLES');
         $key1 = $key2 = null;
         if ($result) {
             foreach ($result as $item) {
                 if (empty($key1)) {
                     $key1 = key($item);
                     $key2 = key($item[$key1]);
                 }
                 $tables[] = $item[$key1][$key2];
             }
         }
     }
     parent::listSources($tables);
     return $tables;
 }