loadFromFile() public static method

Import SQL dump from file - extremely fast.
public static loadFromFile ( Connection $connection, $file ) : integer
$connection Connection
return integer count of commands
Esempio n. 1
0
 public function __construct()
 {
     $connection = new \Nette\Database\Connection('mysql:host=127.0.0.1;dbname=test', 'root', '');
     \Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/sql/db.sql');
     $structure = new \Nette\Database\Structure($connection, new \Nette\Caching\Storages\FileStorage(__DIR__ . '/../../temp/'));
     $conventions = new \Nette\Database\Conventions\DiscoveredConventions($structure);
     $this->database = new \Nette\Database\Context($connection, $structure, $conventions, new \Nette\Caching\Storages\FileStorage(__DIR__ . '/../../temp/'));
     $this->cache = new Nette\Caching\Storages\FileStorage(__DIR__ . '/../../temp');
 }
Esempio n. 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $connection = $this->database->getConnection();
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_USERS_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_ROLES_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_RESOURCES_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_USER_ROLE_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_USER_REQUEST_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_ROLES_DATA_TABLE));
     Nette\Database\Helpers::loadFromFile($connection, $this->getFile(static::FILE_IDENTITY_HASH_TABLE));
 }
Esempio n. 3
0
 /** @internal */
 private function __testbench_ndb_setupDatabase(Connection $db, $container)
 {
     $this->__testbench_ndb_databaseName = 'db_tests_' . getmypid();
     $this->__testbench_ndb_dropDatabase($db);
     $this->__testbench_ndb_createDatabase($db);
     if (isset($container->parameters['testbench']['sqls'])) {
         foreach ($container->parameters['testbench']['sqls'] as $file) {
             \Nette\Database\Helpers::loadFromFile($db, $file);
         }
     }
     register_shutdown_function(function () use($db) {
         $this->__testbench_ndb_dropDatabase($db);
     });
 }
 /** @internal */
 public function __testbench_database_setup($connection, \Nette\DI\Container $container, $persistent = FALSE)
 {
     $config = $container->parameters['testbench'];
     $this->__testbench_databaseName = $config['dbprefix'] . getenv(\Tester\Environment::THREAD);
     $this->__testbench_database_drop($connection, $container);
     $this->__testbench_database_create($connection, $container);
     foreach ($config['sqls'] as $file) {
         \Nette\Database\Helpers::loadFromFile($connection, $file);
     }
     if ($persistent === FALSE) {
         register_shutdown_function(function () use($connection, $container) {
             $this->__testbench_database_drop($connection, $container);
         });
     }
 }
Esempio n. 5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $connection = $this->database->getConnection();
     $driverName = $connection->getPdo()->getAttribute(\PDO::ATTR_DRIVER_NAME);
     Nette\Database\Helpers::loadFromFile($connection, $this->getFileName($driverName . '.' . static::FILE_LABELS_TABLE));
 }
Esempio n. 6
0
require_once __DIR__ . "/libs/Curl.php";
require_once __DIR__ . "/libs/CurlResponse.php";
require_once __DIR__ . "/libs/Parser.php";
use Nette\Diagnostics\Debugger;
set_time_limit(0);
Debugger::enable(Debugger::DEVELOPMENT, __DIR__);
Debugger::timer();
/************************************ SQLite *************************************/
/*if (file_exists(__DIR__."/db.sqlite")) {
	copy(__DIR__."/db.sqlite", __DIR__."/backup/".date("Y-m-d_H-i-s-").substr(microtime(TRUE)-time(), 2, 4).".sqlite");
}
$connection = new \Nette\Database\Connection('sqlite:' . __DIR__ . '/db.sqlite');
\Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/db.structure.sqlite.sql');
/************************************ MySQL *************************************/
$connection = new \Nette\Database\Connection('mysql:host=localhost;dbname=njlogparser', 'nette', 'nette');
\Nette\Database\Helpers::loadFromFile($connection, __DIR__ . '/db.structure.mysql.sql');
if (!defined('STDIN')) {
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head>' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Nette Jabber Log Parser</title></head><body><code><pre>';
}
$parser = new Parser($connection);
$parser->originalDataDir = __DIR__ . "/data";
//$parser->debug = TRUE;
$factory = new \Nette\Http\RequestFactory();
$factory->setEncoding('UTF-8');
$req = $factory->createHttpRequest();
if (($date = $req->getQuery('date', NULL)) || ($date = isset($argv[1]) ? $argv[1] : NULL)) {
    $parser->parseDate($date, TRUE);
} else {
    $parser->parse(10);
}
echo "\n\n";
Esempio n. 7
0
<?php

/**
 * Test: Nette\Database test boostap.
 *
 * @author     Jakub Vrana
 * @author     Jan Skrasek
 * @package    Nette\Caching
 * @subpackage UnitTests
 */
use Nette\Database;
require __DIR__ . '/../bootstrap.php';
try {
    $connection = new Database\Connection('mysql:host=localhost', 'root');
    Database\Helpers::loadFromFile($connection, __DIR__ . '/nette_test.sql');
} catch (PDOException $e) {
    TestHelpers::skip('Requires corretly configured mysql connection and "nette_test" database.');
}
 function importFile($filename)
 {
     \Nette\Database\Helpers::loadFromFile($this->connection, $filename);
 }