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