コード例 #1
0
 function getConnection()
 {
     if (!$this->connection) {
         $this->connection = $this->openDB();
         // Nahraj databázi
         if (filesize(self::$databasePath) === 0) {
             //$this->beginTransaction();
             $res = $this->connection->query(file_get_contents(dirname(__FILE__) . '/setupDB.sql'));
             if (!$res) {
                 throw new \Nette\InvalidStateException("Can't create SQLite3 database: " . $this->getConnection()->lastErrorMsg());
             }
             //$this->endTransaction();
         }
     }
     return $this->connection;
 }
コード例 #2
0
 public function checkAndRepairTable($tableName = null)
 {
     $ok = true;
     if (!SapphireTest::using_temp_db() && !self::$checked_and_repaired) {
         $this->alterationMessage("Checking database integrity", "repaired");
         // Check for any tables with failed integrity
         if ($messages = $this->query('PRAGMA integrity_check')) {
             foreach ($messages as $message) {
                 if ($message['integrity_check'] != 'ok') {
                     Debug::show($message['integrity_check']);
                     $ok = false;
                 }
             }
         }
         // If enabled vacuum (clean and rebuild) the database
         if (self::$vacuum) {
             $this->query('VACUUM', E_USER_NOTICE);
             $message = $this->database->getConnector()->getLastError();
             if (preg_match('/authoriz/', $message)) {
                 $this->alterationMessage("VACUUM | {$message}", "error");
             } else {
                 $this->alterationMessage("VACUUMing", "repaired");
             }
         }
         self::$checked_and_repaired = true;
     }
     return $ok;
 }
 /**
  * If a write query is detected, hand it off to the configured write database
  * 
  * @param string $sql
  * @param int $errorLevel
  * @return \MySQLQuery
  */
 public function query($sql, $errorLevel = E_USER_ERROR)
 {
     if (in_array(strtolower(substr($sql, 0, strpos($sql, ' '))), $this->writeQueries) || $this->writePerformed) {
         $alternateReturn = $this->writeDb()->query($sql, $errorLevel);
         $this->writePerformed = true;
         return $alternateReturn;
     }
     if (stripos($sql, 'content')) {
         $o = 1;
     }
     return parent::query($sql, $errorLevel);
 }
コード例 #4
0
ファイル: SqliteExample.php プロジェクト: E89son/LieisonCMS
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
include '/Conf/Include.php';
$sqlite = new SQLite3Database();
$sqlite->connect();
$sqlite->insert("user", array("user_name" => "user" . rand(0, 100), "password" => "125445li", "state" => 1));
print_r($sqlite->get_rows("select * from user", true));
コード例 #5
0
<?php

global $project;
$project = 'mysite';
include_once dirname(__FILE__) . '/local.conf.php';
if (!defined('SS_LOG_FILE')) {
    define('SS_LOG_FILE', '/var/log/silverstripe/' . basename(dirname(dirname(__FILE__))) . '.log');
}
SS_Log::add_writer(new SS_LogFileWriter(SS_LOG_FILE), SS_Log::NOTICE, '<=');
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.com/themes/
SSViewer::set_theme('simple');
// enable nested URLs for this site (e.g. page/sub-page/)
SiteTree::enable_nested_urls();
MySQLDatabase::set_connection_charset('utf8');
// necessary for now
SQLite3Database::$vacuum = false;
// Sets up relevant cache settings to prevent permission errors
SS_Cache::add_backend('default', 'File', array('cache_dir' => TEMP_FOLDER . DIRECTORY_SEPARATOR . 'cache', 'hashed_directory_umask' => 2775, 'cache_file_umask' => 0660));
require_once 'Zend/Cache.php';
require_once 'Zend/Date.php';
$coreCache = Zend_Cache::factory('Core', 'File', array(), array('hashed_directory_umask' => 2775, 'cache_file_umask' => 0660, 'cache_dir' => TEMP_FOLDER));
Zend_Date::setOptions(array('cache' => $coreCache));
コード例 #6
0
 /**
  * Repairs and reindexes the table.  This might take a long time on a very large table.
  * @var string $tableName The name of the table.
  * @return boolean Return true if the table has integrity after the method is complete.
  */
 public function checkAndRepairTable($tableName = null)
 {
     $ok = true;
     if (!SapphireTest::using_temp_db() && !self::$checked_and_repaired) {
         $this->alterationMessage("Checking database integrity", "repaired");
         if ($msgs = $this->query('PRAGMA integrity_check')) {
             foreach ($msgs as $msg) {
                 if ($msg['integrity_check'] != 'ok') {
                     Debug::show($msg['integrity_check']);
                     $ok = false;
                 }
             }
         }
         if (self::$vacuum) {
             $this->query('VACUUM', E_USER_NOTICE);
             if ($this instanceof SQLitePDODatabase) {
                 $msg = $this->dbConn->errorInfo();
                 $msg = isset($msg[2]) ? $msg[2] : 'no errors';
             } else {
                 $msg = $this->dbConn->lastErrorMsg();
             }
             if (preg_match('/authoriz/', $msg)) {
                 $this->alterationMessage('VACUUM | ' . $msg, "error");
             } else {
                 $this->alterationMessage("VACUUMing", "repaired");
             }
         }
         self::$checked_and_repaired = true;
     }
     return $ok;
 }