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