]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/ADODB.php
Reformat code
[SourceForge/phpwiki.git] / lib / WikiDB / ADODB.php
1 <?php
2
3 require_once 'lib/WikiDB.php';
4
5 /**
6  * WikiDB layer for ADODB, which does nothing more than calling the
7  * mysql-specific ADODB backend.
8  * Support for a newer adodb library, the adodb extension library
9  * and more databases will come with PhpWiki v1.3.10
10  *
11  * @author: Lawrence Akka, Reini Urban
12  */
13 class WikiDB_ADODB extends WikiDB
14 {
15     function WikiDB_ADODB($dbparams)
16     {
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     {
47         $pagename = (string)$pagename;
48         if ($pagename === '') return false;
49         if (!array_key_exists($pagename, $this->_cache->_id_cache)) {
50             $this->_cache->_id_cache[$pagename] = $this->_backend->is_wiki_page($pagename);
51         }
52         return $this->_cache->_id_cache[$pagename];
53     }
54
55     // add surrounding quotes '' if string
56     function quote($in)
57     {
58         if (is_int($in) || is_double($in)) {
59             return $in;
60         } elseif (is_bool($in)) {
61             return $in ? 1 : 0;
62         } elseif (is_null($in)) {
63             return 'NULL';
64         } else {
65             return $this->_backend->_dbh->qstr($in);
66         }
67     }
68
69     // ADODB handles everything as string
70     // Don't add surrounding quotes '', same as in PearDB
71     function qstr($in)
72     {
73         return $this->_backend->_dbh->addq($in);
74     }
75
76     function isOpen()
77     {
78         global $request;
79         if (!$request->_dbi) return false;
80         return is_resource($this->_backend->connection());
81     }
82
83     // SQL result: for simple select or create/update queries
84     // returns the database specific resource type
85     function genericSqlQuery($sql, $args = false)
86     {
87         if ($args)
88             $result = $this->_backend->_dbh->Execute($sql, $args);
89         else
90             $result = $this->_backend->_dbh->Execute($sql);
91         if (!$result) {
92             trigger_error("SQL Error: " . $this->_backend->_dbh->ErrorMsg(), E_USER_WARNING);
93             return false;
94         } else {
95             return $result;
96         }
97     }
98
99     // SQL iter: for simple select or create/update queries
100     // returns the generic iterator object (count,next)
101     function genericSqlIter($sql, $field_list = NULL)
102     {
103         $result = $this->genericSqlQuery($sql);
104         return new WikiDB_backend_ADODB_generic_iter($this->_backend, $result, $field_list);
105     }
106
107 }
108
109 ;
110
111 // Local Variables:
112 // mode: php
113 // tab-width: 8
114 // c-basic-offset: 4
115 // c-hanging-comment-ender-p: nil
116 // indent-tabs-mode: nil
117 // End: