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) {
14 if (is_array($dbparams['dsn']))
15 $backend = $dbparams['dsn']['phptype'];
16 elseif (preg_match('/^(\w+):/', $dbparams['dsn'], $m))
18 if ($backend == 'postgres7') { // ADODB cross-compatiblity hack (for unit testing)
20 if (is_string($dbparams['dsn']))
21 $dbparams['dsn'] = $backend . ':' . substr($dbparams['dsn'], 10);
23 include_once ("lib/WikiDB/backend/PearDB_".$backend.".php");
24 $backend_class = "WikiDB_backend_PearDB_".$backend;
25 $backend = new $backend_class($dbparams);
26 if (DB::isError($backend->_dbh)) return;
27 $this->WikiDB($backend, $dbparams);
30 function view_dsn ($dsn = false) {
32 $dsninfo = DB::parseDSN($GLOBALS['DBParams']['dsn']);
34 $dsninfo = DB::parseDSN($dsn);
35 return sprintf("%s://%s:<not displayed>@%s/%s",
45 * Determine whether page exists (in non-default form).
46 * @see WikiDB::isWikiPage for the slow generic version
48 function isWikiPage ($pagename) {
49 $pagename = (string) $pagename;
50 if ($pagename === '') return false;
51 //if (empty($this->_iwpcache)) { $this->_iwpcache = array(); }
52 if (empty($this->_cache->id_cache[$pagename])) {
53 $this->_cache->_id_cache[$pagename] = $this->_backend->is_wiki_page($pagename);
55 return $this->_cache->_id_cache[$pagename];
58 // adds surrounding quotes
59 function quote ($s) { return $this->_backend->_dbh->quoteSmart($s); }
60 // no surrounding quotes because we know it's a string
61 function qstr ($s) { return $this->_backend->_dbh->escapeSimple($s); }
65 if (!$request->_dbi) return false;
66 return is_resource($this->_backend->connection());
69 // SQL result: for simple select or create/update queries
70 // returns the database specific resource type
71 function genericSqlQuery($sql, $args=false) {
73 $result = $this->_backend->_dbh->query($sql, $args);
75 $result = $this->_backend->_dbh->query($sql);
76 if (DB::isError($result)) {
77 $msg = $result->getMessage();
78 trigger_error("SQL Error: ".DB::errorMessage($result), E_USER_WARNING);
85 // SQL iter: for simple select or create/update queries
86 // returns the generic iterator object (count,next)
87 function genericSqlIter($sql, $field_list = NULL) {
88 $result = $this->genericSqlQuery($sql);
89 return new WikiDB_backend_PearDB_generic_iter($this->_backend, $result);
98 // c-hanging-comment-ender-p: nil
99 // indent-tabs-mode: nil