Restores a database from a MySQL dump result, executing the contained SQL queries.
@param String $dump The MySQL dump output
512974
public function restore(&$dump) {
        $this->_adjustDumpToEnvironment($dump);
        //$dump         = $this->_lowerCaseTableAndViewNames($dump);
        $this->_removeDefinerCalls($dump);
        $dbConfig       = $this->getDbConfigParams();
        $restoreFile    = $this->getRestoreFilePath();
        $restoreDir     = $this->getBackupDir();

        $executeFile    = new Garp_Shell_Command_CreateDatabase($dbConfig);
        $this->shellExec($executeFile);

        if (!$this->_validateDump($dump)) {
            throw new Exception("The fetched database seems invalid.");
        }

        $createRestoreDir = new Garp_Shell_Command_CreateDir($restoreDir);
        $this->shellExec($createRestoreDir);

        if ($this->store($restoreFile, $dump)) {
            $executeFile = new Garp_Shell_Command_ExecuteDatabaseDumpFile($dbConfig, $restoreFile);
            $this->shellExec($executeFile);

            $removeFile = new Garp_Shell_Command_RemoveFile($restoreFile);
            $this->shellExec($removeFile);
        }
    }
1128972
public function backup($databases)
    {
        foreach ($databases as $database)
        {
            echo "\n".'dumping '.$database.' database'."\n";

            try {
                system($this->command($database));
            } catch (\Exception $e) {
                $this->event->fire('MonasheeBackupError', $e->getMessage());
                throw new \Exception('mysqldump error');
            }

            echo 'done.'."\n\n";
        }

        $this->event->fire('MonasheeBackupInfo', 'All databases done dumping.');

        return true;
    }
975364
public function dump()
	{
		$pdo = $this->pdo();

		$sql = '';

		foreach ($this->list_tables() as $table)
		{
			$query = $pdo->query("SELECT * FROM `{$table}`");

			while ($row = $query->fetch(\PDO::FETCH_NUM)) 
			{
				$values = array();

				foreach ($row as $column) 
				{
					$values[] = is_null($column) ? 'NULL' : $pdo->quote($column);
				}

				$sql .= "INSERT INTO `{$table}` VALUES (".join(',', $values). ");\n";
			}
		}

		return $sql;
	}
1212412
protected function query ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysql_query($sql, $this->conn)))
		{
			$this->sql_errcheck($sql);
		}
		if (is_resource($res))
		{
			mysql_free_result($res);
		}
	}
761022
protected function query ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		try
		{
			$this->lastaffectedrows = $this->conn->exec($sql);
			if ($this->lastaffectedrows === FALSE) {
				$this->sql_errcheck($sql);
			}
		}
		catch (PDOException $e) 
		{
			$this->sql_errcheck($sql);
		}
	}
1360626
public function restoreDatabase(): void
    {
        $currentDirectory = getcwd();
        $installer = $this->getInstallerService();
        $this->findDirectoryToRunScripts();
        $installer->setOutput(new NullOutput());
        $installer->importSchema();
        $installer->importData();
        chdir($currentDirectory);
    }
273371
public function restoreTable($table, $restoreColumns = false)
    {
        $dumpChecksum = $this->getDumpChecksum();
        $checksum = $this->getTableChecksum($table);
        if ($checksum[$table] === $dumpChecksum[$table]) {
            return;
        }

        $file = $this->getDumpFolderPath() .'/'. $table ."_dump.sql";

        if (file_exists($file)) {
            $database = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster();
            $database->execute("TRUNCATE TABLE `$table`");

            $query = "LOAD DATA INFILE '$file' INTO TABLE `$table`";
            $database->execute($query);
        }
    }
22342
public function execute( $query, $debug = 1 )
	{
		if( !$this->dbc )
			throw new RuntimeException( 'Database not conntected' );

		$result = FALSE;
		if( $query )
		{
			if( $debug > 0 )
			{
				$bits = $this->getBits( $debug, 5 );
				if( $bits[0] )
				{
					$this->countQueries++;
					$start = $this->getMicroTime();
				}
				if( $bits[1] )
					echo $query;
				if( $bits[2] )
					remark( $query );
				if( $bits[3] )
					die();
			}
			if( preg_match( '/^INSERT/i', ltrim( $query ) ) )
			{
				if( mysql_query( $query, $this->dbc ) )
				{
					$this->insertId = (int) mysql_insert_Id( $this->dbc );
					$result	= $this->insertId;
				}
			}
			else if( preg_match( '/^(SELECT|SHOW)/i', ltrim( $query ) ) )
			{
				$result = new DB_Result();
				if( $q = mysql_query( $query, $this->dbc ) )
				{
					while( $d = mysql_fetch_array( $q ) )
					{
						$row = new DB_Row();
						foreach( $d as $key => $value )
							$row->$key = $value;
						$result->rows[] = $row;
					}
				}
			}
			else
			{
				$result = mysql_query( $query, $this->dbc );
			}
			if( mysql_errno() )
				$this->handleError( mysql_errno(), mysql_error(), $query );
			if( $debug > 0 )
			{
				if( $bits[0] )
					$this->countTime += $this->getTimeDifference( $start );
				if( $bits[4] )
					die();
			}
			return $result;
		}
	}
956332
public function after_execute_question() {
        global $DB;

        // For random questions, questiontext should only ever be '0' or '1'.
        // In the past there were sometimes junk values like ''. If there
        // were any in the restore, fix them up.
        //
        // Note, we cannot just do this in one DB query, because MySQL is useless.
        // The expected case is that the SELECT returns 0 rows, so loading all the
        // ids should not be a problem.
        $problemquestions = $DB->get_records_sql_menu("
                SELECT q.id, 1
                  FROM {question} q
                  JOIN {backup_ids_temp} bi ON q.id = bi.newitemid
                 WHERE q.qtype = 'random'
                   AND " . $DB->sql_compare_text('q.questiontext') . " = ?
                   AND bi.backupid = ?
                   AND bi.itemname = 'question_created'
                ", array('', $this->get_restoreid()));

        if (!$problemquestions) {
            return; // Nothing to do.
        }

        list($idtest, $params) = $DB->get_in_or_equal(array_keys($problemquestions));
        $DB->set_field_select('question', 'questiontext', '0', "id $idtest", $params);
    }
634160
protected function dumpDatabases()
    {

        foreach ($this->db->query("SHOW DATABASES") as $list) {
            $database = $list->Database;

            if (!in_array($database, $this->ignore) || preg_match("~_no_backup$~", $database)) {
                $start = microtime(true);

                $dir = $this->dump_dir . '1/';

                $filename = $dir . $database;

                $this->log("Dumping Database: " . $database);
                $command = "mysqldump -u " . $this->db_user . " -h "
                    . $this->db_host . " -p" . $this->db_pass . " "
                    . $database . ">" . $filename . ".sql";

                exec($command);

                $command = "tar -zcvf " . $filename . ".gz " . $filename . ".sql";
                exec($command);
                $ms = round((microtime(true) - $start) * 1000, 2);

                clearstatcache();
                $size = round((filesize($filename . '.gz') / 1024), 2) . 'kb';

                $this->log($list->Database . " was backed up in " . $ms . ' ms and is ' . $size . ' bytes');
                unlink($filename . '.sql');
            }
        }
    }
827376
public function exec($sql)
    {
        $this->useConfiguredDatabase();
        $success = $this->getDbConnection()->exec($sql);
        $this->checkForDatabaseError($sql, 'exec');
        return $success;
    }
641110
public function exec($sql)
    {
        if ($sql instanceof Zend_Db_Select) {
            $sql = $sql->assemble();
        }

        try {
            $affected = $this->getConnection()->exec($sql);

            if ($affected === false) {
                $errorInfo = $this->getConnection()->errorInfo();
                /**
                 * @see Zend_Db_Adapter_Exception
                 */
                // require_once 'Zend/Db/Adapter/Exception.php';
                throw new Zend_Db_Adapter_Exception($errorInfo[2]);
            }

            return $affected;
        } catch (PDOException $e) {
            /**
             * @see Zend_Db_Adapter_Exception
             */
            // require_once 'Zend/Db/Adapter/Exception.php';
            throw new Zend_Db_Adapter_Exception($e->getMessage(), $e->getCode(), $e);
        }
    }
1192294
function restore()
    {
        $Timestamps = $this->CacheFile->processFile( array( $this, 'fetchData' ) );
        if ( $Timestamps === false )
        {
            $errMsg = 'Fatal error - could not restore expiry.php file.';
            eZDebug::writeError( $errMsg, __METHOD__ );
            trigger_error( $errMsg, E_USER_ERROR );
        }

        $this->Timestamps = $Timestamps;
        $this->IsModified = false;
    }
961707
public function startDatabase($database)
    {
        assert($this->_platform instanceof SQLAnywherePlatform);
        $this->_execSql($this->_platform->getStartDatabaseSQL($database));
    }
570395
public function exec($sql)
    {
        if ($this->useDebug) {
            $debug = $this->getDebugSnapshot();
        }

        $return = parent::exec($sql);

        if ($this->useDebug) {
            $this->log($sql, null, __METHOD__, $debug);
            $this->setLastExecutedQuery($sql);
            $this->incrementQueryCount();
        }

        return $return;
    }
236272
public function exec($sql)
    {
        $this->writeToLog("Exec: " . $sql);
        $result = parent::exec($sql);
        return $result;
    }
1285073
public function init($request)
    {
        if ($file = $request->getUploadedFile('importSql')) {
            $databaseHandler = $this->getDatabaseHandler();
            $databaseHandler->import($file);
        }

        if ($request->getParameter('dumpDB')) {
            $databaseRestorer = $this->getDatabaseRestorer();
            $databaseRestorer->dumpDB($request->getParameter('dump-prefix'));
        }

        if ($request->getParameter('restoreDB')) {
            $databaseRestorer = $this->getDatabaseRestorer();
            $databaseRestorer->restoreDB($request->getParameter('dump-prefix'));
        }
    }