]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/SQL.php
simpified regex search architecture:
[SourceForge/phpwiki.git] / lib / WikiDB / SQL.php
1 <?php rcs_id('$Id: SQL.php,v 1.11 2004-11-27 14:39:05 rurban Exp $');
2
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
6
7 /**
8  *
9  */
10 class WikiDB_SQL extends WikiDB
11 {
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();
22         
23         $this->WikiDB($backend, $dbparams);
24     }
25     
26     function view_dsn ($dsn = false) {
27         if (!$dsn)
28             $dsninfo = DB::parseDSN($GLOBALS['DBParams']['dsn']);
29         else
30             $dsninfo = DB::parseDSN($dsn);
31         return sprintf("%s://%s:<not displayed>@%s/%s",
32                        $dsninfo['phptype'],
33                        $dsninfo['username'],
34                        $dsninfo['hostspec'],
35                        $dsninfo['database']
36                        );
37     }
38
39     
40     /**
41      * Determine whether page exists (in non-default form).
42      * @see WikiDB::isWikiPage for the slow generic version
43      */
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);
50         }
51         return $this->_cache->_id_cache[$pagename];
52     }
53
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); }
58
59     function isOpen () {
60         global $request;
61         if (!$request->_dbi) return false;
62         return is_resource($this->_backend->connection());
63     }
64
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);
72             return false;
73         } else {
74             return $result;
75         }
76     }
77
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);
83     }
84
85 };
86
87   
88 // For emacs users
89 // Local Variables:
90 // mode: php
91 // tab-width: 8
92 // c-basic-offset: 4
93 // c-hanging-comment-ender-p: nil
94 // indent-tabs-mode: nil
95 // End:
96
97 ?>