]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/WikiDB/backend/PearDB_sqlite.php
Whitespace only
[SourceForge/phpwiki.git] / lib / WikiDB / backend / PearDB_sqlite.php
1 <?php
2 /**
3  * SQLite PearDB backend by Matthew Palmer
4  * The SQLite DB will gain popularity with the current MySQL vs PHP license drama.
5  * It's in core since PHP-5.0, MySQL not anymore.
6  *
7  * Initial setup:
8  * sqlite -init /tmp/phpwiki-sqlite.db
9  * sqlite /tmp/phpwiki-sqlite.db < schemas/sqlite.sql
10  */
11
12 require_once 'lib/WikiDB/backend/PearDB.php';
13
14 //TODO: create tables on virgin wiki
15 /*
16     $db = &new DB_sqlite();
17     $db->connect($DBParams['dsn'], array('persistent'=> true) );
18     $result = $db->query("CREATE TABLE $table (comment varchar(50),
19       datetime varchar(50));");
20 */
21
22 class WikiDB_backend_PearDB_sqlite
23 extends WikiDB_backend_PearDB
24 {
25     /**
26      * Pack tables.
27      */
28     function optimize() {
29     // NOP
30     }
31
32     /**
33      * Lock tables.
34      */
35     function _lock_tables($write_lock = true) {
36     // NOP - SQLite does all locking automatically
37     }
38
39     /**
40      * Release all locks.
41      */
42     function _unlock_tables() {
43     // NOP
44     }
45
46     /**
47      * Serialize data
48      */
49     function _serialize($data) {
50         if (empty($data))
51             return '';
52         assert(is_array($data));
53         return base64_encode(serialize($data));
54     }
55
56     /**
57      * Unserialize data
58      */
59     function _unserialize($data) {
60         if (empty($data))
61             return array();
62         // Base64 encoded data does not contain colons.
63         //  (only alphanumerics and '+' and '/'.)
64         if (substr($data,0,2) == 'a:')
65             return unserialize($data);
66         return unserialize(base64_decode($data));
67     }
68
69     // same as DB::getSpecialQuery('tables')
70     /*
71     function sqlite_list_tables (&$dblink) {
72        $tables = array ();
73        $sql = "SELECT name FROM sqlite_master WHERE (type = 'table')";
74        if ($res = sqlite_query ($dblink, $sql)) {
75            while (sqlite_has_more($res)) {
76                $tables[] = sqlite_fetch_single($res);
77            }
78        }
79        return $tables;
80     }
81     */
82
83    function _table_exists (&$dblink, $table) {
84        $sql = "SELECT count(name) FROM sqlite_master WHERE ((type = 'table') and (name = '$table'))";
85        if ($res = sqlite_query ($dblink, $sql)) {
86            return sqlite_fetch_single($res) > 0;
87        } else {
88            return false; // or throw exception
89        }
90    }
91
92 };
93
94 // Local Variables:
95 // mode: php
96 // tab-width: 8
97 // c-basic-offset: 4
98 // c-hanging-comment-ender-p: nil
99 // indent-tabs-mode: nil
100 // End: