]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/ADODB.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / WikiDB / ADODB.php
1 <?php // -*-php-*-
2
3
4 require_once 'lib/WikiDB.php';
5
6 /**
7  * WikiDB layer for ADODB, which does nothing more than calling the
8  * mysql-specific ADODB backend.
9  * Support for a newer adodb library, the adodb extension library
10  * and more databases will come with PhpWiki v1.3.10
11  *
12  * @author: Lawrence Akka, Reini Urban
13  */
14 class WikiDB_ADODB extends WikiDB
15 {
16     function WikiDB_ADODB ($dbparams) {
17         $backend = 'ADODB';
18         if (is_array($dbparams['dsn']))
19             $backend = $dbparams['dsn']['phptype'];
20         elseif (preg_match('/^(\w+):/', $dbparams['dsn'], $m))
21             $backend = $m[1];
22         // Do we have a override? (currently: mysql, sqlite, oracle, mssql, oci8po, postgres7)
23         // TODO: mysqlt (innodb or bdb)
24     if ($backend == 'pgsql') { // PearDB DSN cross-compatiblity hack (for unit testing)
25         $backend = 'postgres7';
26         if (is_string($dbparams['dsn']))
27         $dbparams['dsn'] = $backend . ':' . substr($dbparams['dsn'], 6);
28     }
29         if (FindFile("lib/WikiDB/backend/ADODB_".$backend.".php",true)) {
30             $backend = 'ADODB_' . $backend;
31         } else {
32             $backend = 'ADODB';
33         }
34         include_once 'lib/WikiDB/backend/'.$backend.'.php';
35         $backend_class = "WikiDB_backend_".$backend;
36         $backend = new $backend_class($dbparams);
37     if (!$backend->_dbh->_connectionID) return false;
38         $this->WikiDB($backend, $dbparams);
39     }
40
41     /**
42      * Determine whether page exists (in non-default form).
43      * @see WikiDB::isWikiPage
44      */
45     function isWikiPage ($pagename) {
46         $pagename = (string) $pagename;
47         if ($pagename === '') return false;
48         if (!array_key_exists($pagename, $this->_cache->_id_cache)) {
49             $this->_cache->_id_cache[$pagename] = $this->_backend->is_wiki_page($pagename);
50         }
51         return $this->_cache->_id_cache[$pagename];
52     }
53
54     // add surrounding quotes '' if string
55     function quote ($in) {
56         if (is_int($in) || is_double($in)) {
57             return $in;
58         } elseif (is_bool($in)) {
59             return $in ? 1 : 0;
60         } elseif (is_null($in)) {
61             return 'NULL';
62         } else {
63             return $this->_backend->_dbh->qstr($in);
64         }
65     }
66     // ADODB handles everything as string
67     // Don't add surrounding quotes '', same as in PearDB
68     function qstr ($in) {
69         return $this->_backend->_dbh->addq($in);
70     }
71
72     function isOpen () {
73         global $request;
74         if (!$request->_dbi) return false;
75         return is_resource($this->_backend->connection());
76     }
77
78     // SQL result: for simple select or create/update queries
79     // returns the database specific resource type
80     function genericSqlQuery($sql, $args=false) {
81         if ($args)
82             $result = $this->_backend->_dbh->Execute($sql, $args);
83         else
84             $result = $this->_backend->_dbh->Execute($sql);
85         if (!$result) {
86             trigger_error("SQL Error: ".$this->_backend->_dbh->ErrorMsg(), E_USER_WARNING);
87             return false;
88         } else {
89             return $result;
90         }
91     }
92
93     // SQL iter: for simple select or create/update queries
94     // returns the generic iterator object (count,next)
95     function genericSqlIter($sql, $field_list = NULL) {
96         $result = $this->genericSqlQuery($sql);
97         return new WikiDB_backend_ADODB_generic_iter($this->_backend, $result, $field_list);
98     }
99
100 };
101
102 // Local Variables:
103 // mode: php
104 // tab-width: 8
105 // c-basic-offset: 4
106 // c-hanging-comment-ender-p: nil
107 // indent-tabs-mode: nil
108 // End: