]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/ADODB.php
support enhanced search API
[SourceForge/phpwiki.git] / lib / WikiDB / ADODB.php
1 <?php // -*-php-*-
2 rcs_id('$Id: ADODB.php,v 1.11 2004-12-10 22:15:00 rurban Exp $');
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         if (is_array($dbparams['dsn']))
18             $backend = $dbparams['dsn']['phptype'];
19         elseif (preg_match('/^(\w+):/', $dbparams['dsn'], $m))
20             $backend = $m[1];
21         // Do we have a override? (currently: mysql, sqlite, oracle, mssql)
22         // TODO: pgsql, mysqlt (innodb or bdb)
23         if (FindFile("lib/WikiDB/backend/ADODB_$backend.php",true)) {
24             $backend = 'ADODB_' . $backend;
25         } else {
26             $backend = 'ADODB';
27         }
28         include_once("lib/WikiDB/backend/$backend.php");
29         $backend_class = "WikiDB_backend_$backend";
30         $backend = new $backend_class($dbparams);
31         $this->WikiDB($backend, $dbparams);
32     }
33     
34     /**
35      * Determine whether page exists (in non-default form).
36      * @see WikiDB::isWikiPage
37      */
38     function isWikiPage ($pagename) {
39         $pagename = (string) $pagename;
40         if ($pagename === '') return false;
41         if (!array_key_exists($pagename, $this->_cache->_id_cache)) {
42             $this->_cache->_id_cache[$pagename] = $this->_backend->is_wiki_page($pagename);
43         }
44         return $this->_cache->_id_cache[$pagename];
45     }
46
47     // add surrounding quotes '' if string
48     function quote ($in) {
49         if (is_int($in) || is_double($in)) {
50             return $in;
51         } elseif (is_bool($in)) {
52             return $in ? 1 : 0;
53         } elseif (is_null($in)) {
54             return 'NULL';
55         } else {
56             return $this->_backend->_dbh->qstr($in);
57         }
58     }
59     // ADODB handles everything as string
60     // Don't add surrounding quotes '', same as in PearDB
61     function qstr ($in) {
62         return $this->_backend->_dbh->addq($in);
63     }
64
65     function isOpen () {
66         global $request;
67         if (!$request->_dbi) return false;
68         return is_resource($this->_backend->connection());
69     }
70
71     // SQL result: for simple select or create/update queries
72     // returns the database specific resource type
73     function genericSqlQuery($sql, $args=false) {
74         if ($args)
75             $result = $this->_backend->_dbh->Execute($sql, $args);
76         else
77             $result = $this->_backend->_dbh->Execute($sql);
78         if (!$result) {
79             trigger_error("SQL Error: ".$this->_backend->_dbh->ErrorMsg(), E_USER_WARNING);
80             return false;
81         } else {
82             return $result;
83         }
84     }
85
86     // SQL iter: for simple select or create/update queries
87     // returns the generic iterator object (count,next)
88     function genericSqlIter($sql, $field_list = NULL) {
89         $result = $this->genericSqlQuery($sql);
90         return new WikiDB_backend_ADODB_generic_iter($this->_backend, $result, $field_list);
91     }
92
93 };
94   
95 // For emacs users
96 // Local Variables:
97 // mode: php
98 // tab-width: 8
99 // c-basic-offset: 4
100 // c-hanging-comment-ender-p: nil
101 // indent-tabs-mode: nil
102 // End:
103 ?>