function loadColumns($db) { $this->columns = array(); $table = $this->name; $dbType = $db->getAttribute(PDO::ATTR_DRIVER_NAME); if ('sqlite' == $dbType || 'sqlite2' == $dbType) { $query = "select sql from sqlite_master where type='table' and name='{$table}'"; $row = $db->query($query)->fetch(); $createQuery = new SqlCode($row['sql']); $this->columns = $createQuery->extractColumns(); } else { $query = "show columns from {$table}"; $result = $db->query($query); foreach ($result as $column) { $this->columns[] = new Column($column['Field'], $column['Type']); } } return $this->columns; }
static function set_db($db) { if ($db instanceof PDO) { self::$db =& $db; } else { if (empty($user)) { self::$db = new PDO($db); } else { self::$db = new PDO($db, $user, $password); } } self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); return self::$db; }
function test_select() { $result = SqlCode::select(" where id='test:001'"); $expected = array($this->sqlCode2); $this->assertEqual($expected, $result); }
define('WARAQ_ROOT', '../..'); require_once WARAQ_ROOT . '/' . 'ini.php'; require "code.php"; $dbFile = $bazdig->getparam("db")->file; $console = $bazdig->get("/console"); try { SqlCode::set_db("sqlite:" . $dbFile); } catch (Exception $e) { $error = "<b>DATABASE ERROR</b> check you have PDO_SQLITE <sub>(" . $e->getMessage() . ")</sub>"; die("<div style='background-color: yellow; border: 2px solid red; padding: 10px; margin: 10px;'>{$error}</div>"); } if ($_GET['q']) { $queries = SqlCode::search($_GET['q'], 'order by date desc'); } else { $queries = SqlCode::select('order by date desc limit 10'); } ?> <title>bazdig history</title> <link rel="stylesheet" type="text/css" href="../codepress/languages/sql.css" /> <link rel="stylesheet" type="text/css" href="../bazdig.css" /> <div id="nav"><a href="../console/" accesskey="c" title="(c)" class="button">console</a><a href="../bazdig.db" accesskey="s" title="(s)" class="button">save</a> <form id="search" method="get" action="."> <input type="text" name="q" value="<?php echo $_GET['q']; ?> "/><input type="submit" value="Search" /> <input type="hidden" name="f" value="7" /> </form> </div> <div id="history">
$db_user = $_SERVER['PHP_AUTH_USER']; $db_password = $_SERVER['PHP_AUTH_PW']; if (!$_GET['q']) { header('Location: ' . $bazdig->get('/console')->url); } try { $history_db = new PDO("sqlite:" . $bazdig->getparam('db')->file); $work_db = new BDB(array('type' => $db_type, 'name' => $db_name, 'host' => $db_host), $db_user, $db_password); SqlCode::set_db($history_db); } catch (Exception $e) { Header("WWW-Authenticate: Basic realm=\"{$db_name}@{$db_host}\""); Header("HTTP/1.0 401 Unauthorized"); $error = "<b>CONNECTION ERROR</b> check your server permissions then check that the PDO_SQLITE and PDO_MYSQL modules are installed"; die("<div style='background-color: yellow; border: 2px solid red; padding: 10px; margin: 10px;'>{$error}</div>"); } $query = new SqlCode(trim(stripslashes($_GET['q']))); ?> <html> <head> <style type="text/css"> table, tr, td, th { margin: 0px; padding: 5px; border-width: 0px; border-spacing: 0px; border-collapse: collapse; font-style: fixed; white-space: nowrap; } table tr td {border: solid 1px silver;}