File: PearDB_sqlite.php

package info (click to toggle)
phpwiki 1.3.12p3-5etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 16,956 kB
  • ctags: 21,608
  • sloc: php: 82,335; xml: 3,840; sh: 1,522; sql: 1,198; perl: 625; makefile: 562; awk: 28
file content (103 lines) | stat: -rw-r--r-- 2,540 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php // -*-php-*-
/** 
 * SQLite PearDB backend by Matthew Palmer
 * The SQLite DB will gain popularity with the current MySQL vs PHP license drama.
 * It's in core since PHP-5.0, MySQL not anymore.
 *
 * Initial setup:
 * sqlite -init /tmp/phpwiki-sqlite.db 
 * sqlite /tmp/phpwiki-sqlite.db < schemas/sqlite.sql
 */
rcs_id('$Id: PearDB_sqlite.php,v 1.3 2004/07/08 15:35:17 rurban Exp $');

require_once('lib/WikiDB/backend/PearDB.php');

//TODO: create tables on virgin wiki
/*
    $db = &new DB_sqlite();
    $db->connect($DBParams['dsn'], array('persistent'=> true) );
    $result = $db->query("CREATE TABLE $table (comment varchar(50), 
      datetime varchar(50));");
*/

class WikiDB_backend_PearDB_sqlite
extends WikiDB_backend_PearDB
{
    /**
     * Pack tables.
     */
    function optimize() {
    // NOP
    }

    /**
     * Lock tables.
     */
    function _lock_tables($write_lock = true) {
    // NOP - SQLite does all locking automatically
    }

    /**
     * Release all locks.
     */
    function _unlock_tables() {
    // NOP
    }

    /**
     * Serialize data
     */
    function _serialize($data) {
        if (empty($data))
            return '';
        assert(is_array($data));
        return base64_encode(serialize($data));
    }

    /**
     * Unserialize data
     */
    function _unserialize($data) {
        if (empty($data))
            return array();
        // Base64 encoded data does not contain colons.
        //  (only alphanumerics and '+' and '/'.)
        if (substr($data,0,2) == 'a:')
            return unserialize($data);
        return unserialize(base64_decode($data));
    }

    // same as DB::getSpecialQuery('tables')
    /*
    function sqlite_list_tables (&$dblink) {
       $tables = array ();
       $sql = "SELECT name FROM sqlite_master WHERE (type = 'table')";
       if ($res = sqlite_query ($dblink, $sql)) {
           while (sqlite_has_more($res)) {
               $tables[] = sqlite_fetch_single($res);
           }
       }
       return $tables;
    }
    */

   function _table_exists (&$dblink, $table) {
       $sql = "SELECT count(name) FROM sqlite_master WHERE ((type = 'table') and (name = '$table'))";
       if ($res = sqlite_query ($dblink, $sql)) {
           return sqlite_fetch_single($res) > 0;
       } else {
           return false; // or throw exception
       }
   }

};
    
// (c-file-style: "gnu")
// Local Variables:
// mode: php
// tab-width: 8
// c-basic-offset: 4
// c-hanging-comment-ender-p: nil
// indent-tabs-mode: nil
// End:   
?>