1 <?php rcs_id('$Id: SQL.php,v 1.11 2004-11-27 14:39:05 rurban Exp $');
3 require_once('lib/WikiDB.php');
4 //require_once('lib/WikiDB/backend/PearDB.php');
5 //require_once('DB.php'); // Always favor use our local pear copy
10 class WikiDB_SQL extends WikiDB
12 function WikiDB_SQL ($dbparams) {
13 $backend_type = 'PearDB';
14 if (is_array($dbparams['dsn']))
15 $backend_type = $dbparams['dsn']['phptype'];
16 elseif (preg_match('/^(\w+):/', $dbparams['dsn'], $m))
17 $backend_type = $m[1];
18 include_once ("lib/WikiDB/backend/PearDB_".$backend_type.".php");
19 $backend_class = "WikiDB_backend_PearDB_".$backend_type;
20 $backend = & new $backend_class($dbparams);
21 //$this->_iwpcache = array();
23 $this->WikiDB($backend, $dbparams);
26 function view_dsn ($dsn = false) {
28 $dsninfo = DB::parseDSN($GLOBALS['DBParams']['dsn']);
30 $dsninfo = DB::parseDSN($dsn);
31 return sprintf("%s://%s:<not displayed>@%s/%s",
41 * Determine whether page exists (in non-default form).
42 * @see WikiDB::isWikiPage for the slow generic version
44 function isWikiPage ($pagename) {
45 $pagename = (string) $pagename;
46 if ($pagename === '') return false;
47 //if (empty($this->_iwpcache)) { $this->_iwpcache = array(); }
48 if (empty($this->_cache->id_cache[$pagename])) {
49 $this->_cache->_id_cache[$pagename] = $this->_backend->is_wiki_page($pagename);
51 return $this->_cache->_id_cache[$pagename];
54 // adds surrounding quotes
55 function quote ($s) { return $this->_backend->_dbh->quoteSmart($s); }
56 // no surrounding quotes because we know it's a string
57 function qstr ($s) { return $this->_backend->_dbh->escapeSimple($s); }
61 if (!$request->_dbi) return false;
62 return is_resource($this->_backend->connection());
65 // SQL result: for simple select or create/update queries
66 // returns the database specific resource type
67 function genericSqlQuery($sql) {
68 $result = $this->_backend->_dbh->query($sql);
69 if (DB::isError($result)) {
70 $msg = $result->getMessage();
71 trigger_error("SQL Error: ".DB::errorMessage($result), E_USER_WARNING);
78 // SQL iter: for simple select or create/update queries
79 // returns the generic iterator object (count,next)
80 function genericSqlIter($sql, $field_list = NULL) {
81 $result = $this->genericSqlQuery($sql);
82 return new WikiDB_backend_PearDB_generic_iter($this->_backend, $result);
93 // c-hanging-comment-ender-p: nil
94 // indent-tabs-mode: nil