|  |  | @ -46,9 +46,6 @@ class OC_DB { | 
			
		
	
		
			
				
					|  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  | 	static private $connection; //the preferred connection to use, only Doctrine
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	static private $prefix=null; | 
			
		
	
		
			
				
					|  |  |  | 	static private $type=null; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  | 	 * connects to the database | 
			
		
	
		
			
				
					|  |  |  | 	 * @return boolean|null true if connection can be established or false on error | 
			
		
	
	
		
			
				
					|  |  | @ -325,12 +322,21 @@ class OC_DB { | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  | 	 * drop a table | 
			
		
	
		
			
				
					|  |  |  | 	 * drop a table - the database prefix will be prepended | 
			
		
	
		
			
				
					|  |  |  | 	 * @param string $tableName the table to drop | 
			
		
	
		
			
				
					|  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  | 	public static function dropTable($tableName) { | 
			
		
	
		
			
				
					|  |  |  | 		$schemaManager = self::getMDB2SchemaManager(); | 
			
		
	
		
			
				
					|  |  |  | 		$schemaManager->dropTable($tableName); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$tableName = OC_Config::getValue('dbtableprefix', 'oc_' ) . trim($tableName); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		self::$connection->beginTransaction(); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$platform = self::$connection->getDatabasePlatform(); | 
			
		
	
		
			
				
					|  |  |  | 		$sql = $platform->getDropTableSQL($platform->quoteIdentifier($tableName)); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		self::$connection->query($sql); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		self::$connection->commit(); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
	
		
			
				
					|  |  | @ -342,15 +348,6 @@ class OC_DB { | 
			
		
	
		
			
				
					|  |  |  | 		$schemaManager->removeDBStructure($file); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  | 	 * replaces the ownCloud tables with a new set | 
			
		
	
		
			
				
					|  |  |  | 	 * @param string $file path to the MDB2 xml db export file | 
			
		
	
		
			
				
					|  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  | 	public static function replaceDB( $file ) { | 
			
		
	
		
			
				
					|  |  |  | 		$schemaManager = self::getMDB2SchemaManager(); | 
			
		
	
		
			
				
					|  |  |  | 		$schemaManager->replaceDB($file); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  | 	 * check if a result is an error, works with Doctrine | 
			
		
	
		
			
				
					|  |  |  | 	 * @param mixed $result | 
			
		
	
	
		
			
				
					|  |  | @ -405,4 +402,51 @@ class OC_DB { | 
			
		
	
		
			
				
					|  |  |  | 			self::$connection->disableQueryStatementCaching(); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  | 	 * Checks if a table exists in the database - the database prefix will be prepended | 
			
		
	
		
			
				
					|  |  |  | 	 * | 
			
		
	
		
			
				
					|  |  |  | 	 * @param string $table | 
			
		
	
		
			
				
					|  |  |  | 	 * @return bool | 
			
		
	
		
			
				
					|  |  |  | 	 * @throws DatabaseException | 
			
		
	
		
			
				
					|  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  | 	public static function tableExists($table) { | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$table = OC_Config::getValue('dbtableprefix', 'oc_' ) . trim($table); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		$dbType = OC_Config::getValue( 'dbtype', 'sqlite' ); | 
			
		
	
		
			
				
					|  |  |  | 		switch ($dbType) { | 
			
		
	
		
			
				
					|  |  |  | 			case 'sqlite': | 
			
		
	
		
			
				
					|  |  |  | 			case 'sqlite3': | 
			
		
	
		
			
				
					|  |  |  | 				$sql = "SELECT name FROM sqlite_master " | 
			
		
	
		
			
				
					|  |  |  | 					.  "WHERE type = 'table' AND name = ? " | 
			
		
	
		
			
				
					|  |  |  | 					.  "UNION ALL SELECT name FROM sqlite_temp_master " | 
			
		
	
		
			
				
					|  |  |  | 					.  "WHERE type = 'table' AND name = ?"; | 
			
		
	
		
			
				
					|  |  |  | 				$result = \OC_DB::executeAudited($sql, array($table, $table)); | 
			
		
	
		
			
				
					|  |  |  | 				break; | 
			
		
	
		
			
				
					|  |  |  | 			case 'mysql': | 
			
		
	
		
			
				
					|  |  |  | 				$sql = 'SHOW TABLES LIKE ?'; | 
			
		
	
		
			
				
					|  |  |  | 				$result = \OC_DB::executeAudited($sql, array($table)); | 
			
		
	
		
			
				
					|  |  |  | 				break; | 
			
		
	
		
			
				
					|  |  |  | 			case 'pgsql': | 
			
		
	
		
			
				
					|  |  |  | 				$sql = 'SELECT tablename AS table_name, schemaname AS schema_name ' | 
			
		
	
		
			
				
					|  |  |  | 					.  'FROM pg_tables WHERE schemaname NOT LIKE \'pg_%\' ' | 
			
		
	
		
			
				
					|  |  |  | 					.  'AND schemaname != \'information_schema\' ' | 
			
		
	
		
			
				
					|  |  |  | 					.  'AND tablename = ?'; | 
			
		
	
		
			
				
					|  |  |  | 				$result = \OC_DB::executeAudited($sql, array($table)); | 
			
		
	
		
			
				
					|  |  |  | 				break; | 
			
		
	
		
			
				
					|  |  |  | 			case 'oci': | 
			
		
	
		
			
				
					|  |  |  | 				$sql = 'SELECT TABLE_NAME FROM USER_TABLES WHERE TABLE_NAME = ?'; | 
			
		
	
		
			
				
					|  |  |  | 				$result = \OC_DB::executeAudited($sql, array($table)); | 
			
		
	
		
			
				
					|  |  |  | 				break; | 
			
		
	
		
			
				
					|  |  |  | 			case 'mssql': | 
			
		
	
		
			
				
					|  |  |  | 				$sql = 'SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = ?'; | 
			
		
	
		
			
				
					|  |  |  | 				$result = \OC_DB::executeAudited($sql, array($table)); | 
			
		
	
		
			
				
					|  |  |  | 				break; | 
			
		
	
		
			
				
					|  |  |  | 			default: | 
			
		
	
		
			
				
					|  |  |  | 				throw new DatabaseException("Unknown database type: $dbType"); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		return $result->fetchOne() === $table; | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | } |