]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/ADODB_mssql.php
rcs_id no longer makes sense with Subversion global version number
[SourceForge/phpwiki.git] / lib / WikiDB / backend / ADODB_mssql.php
1 <?php // -*-php-*-
2 // rcs_id('$Id$');
3
4 /**
5  * MS SQL extensions for the ADODB DB backend.
6  */
7
8 require_once('lib/WikiDB/backend/ADODB.php');
9
10 class WikiDB_backend_ADODB_mssql
11 extends WikiDB_backend_ADODB
12 {
13     /**
14      * Constructor.
15      */
16     function WikiDB_backend_ADODB_mssql($dbparams) {
17         // Lowercase Assoc arrays
18         define('ADODB_ASSOC_CASE',0);
19
20         // Backend constructor
21         $this->WikiDB_backend_ADODB($dbparams);
22
23         // Empty strings in MSSQL?  NULLS?
24         $this->_expressions['notempty'] = "NOT LIKE ''";
25         // TEXT handling
26         //$this->_expressions['iscontent'] = "content NOT LIKE ''";
27
28         $this->_prefix = isset($dbparams['prefix']) ? $dbparams['prefix'] : '';
29     }
30     
31     /**
32      * Pack tables.
33      */
34     function optimize() {
35         // Do nothing here -- Leave that for the DB
36         // Cost Based Optimizer tuning vary from version to version
37         return 1;
38     }
39
40     /**
41      * Lock tables.
42      *
43      * We don't really need to lock exclusive, but I'll relax it when I fully 
44      * understand phpWiki locking ;-)
45      *
46      */
47     function _lock_tables($tables, $write_lock = true) {
48         if (!$tables) return;
49
50         $dbh = &$this->_dbh;
51         if($write_lock) {
52             // Next line is default behaviour, so just skip it
53             // $dbh->Execute("SET TRANSACTION READ WRITE");
54             foreach ($tables as $table) {
55                 if ($this->_prefix && !strstr($table, $this->_prefix)) {
56                     $table = $this->_prefix . $table;
57                 }
58                 $dbh->Execute("LOCK TABLE $table IN EXCLUSIVE MODE");
59             }
60         } else {
61             // Just ensure read consistency
62             $dbh->Execute("SET TRANSACTION READ ONLY");
63         }
64     }
65
66     /**
67      * Release the locks.
68      */
69     function _unlock_tables($tables) {
70         $dbh = &$this->_dbh;
71         $dbh->Execute("COMMIT WORK");
72     }
73
74     // Search callabcks
75     // Page name
76     function _sql_match_clause($word) {
77         $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
78         $word = $this->_dbh->qstr("%$word%");
79         return "LOWER(pagename) LIKE $word";
80     }
81
82     // Fulltext -- case sensitive :-\
83     function _fullsearch_sql_match_clause($word) {
84         $word = preg_replace('/(?=[%_\\\\])/', "\\", $word);
85         $wordq = $this->_dbh->qstr("%$word%");
86         return "LOWER(pagename) LIKE $wordq " 
87                . "OR CHARINDEX(content, '$word') > 0";
88     }
89
90     /**
91      * Serialize data
92      */
93     function _serialize($data) {
94         if (empty($data))
95             return '';
96         assert(is_array($data));
97         return serialize(addslashes($data));
98     }
99
100     /**
101      * Unserialize data
102      */
103     function _unserialize($data) {
104         return empty($data) ? array() : unserialize(stripslashes($data));
105     }
106
107 };
108
109 // (c-file-style: "gnu")
110 // Local Variables:
111 // mode: php
112 // tab-width: 8
113 // c-basic-offset: 4
114 // c-hanging-comment-ender-p: nil
115 // indent-tabs-mode: nil
116 // End:   
117 ?>