Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// +----------------------------------------------------------------------+
3
// | PHP versions 4 and 5                                                 |
4
// +----------------------------------------------------------------------+
5
// | Copyright (c) 2006-2007 Lorenzo Alberton                             |
6
// | All rights reserved.                                                 |
7
// +----------------------------------------------------------------------+
8
// | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
9
// | API as well as database abstraction for PHP applications.            |
10
// | This LICENSE is in the BSD license style.                            |
11
// |                                                                      |
12
// | Redistribution and use in source and binary forms, with or without   |
13
// | modification, are permitted provided that the following conditions   |
14
// | are met:                                                             |
15
// |                                                                      |
16
// | Redistributions of source code must retain the above copyright       |
17
// | notice, this list of conditions and the following disclaimer.        |
18
// |                                                                      |
19
// | Redistributions in binary form must reproduce the above copyright    |
20
// | notice, this list of conditions and the following disclaimer in the  |
21
// | documentation and/or other materials provided with the distribution. |
22
// |                                                                      |
23
// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
24
// | Lukas Smith nor the names of his contributors may be used to endorse |
25
// | or promote products derived from this software without specific prior|
26
// | written permission.                                                  |
27
// |                                                                      |
28
// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
29
// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
30
// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
31
// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
32
// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
33
// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
34
// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
35
// |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
36
// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
37
// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
38
// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
39
// | POSSIBILITY OF SUCH DAMAGE.                                          |
40
// +----------------------------------------------------------------------+
41
// | Author: Lorenzo Alberton <l.alberton@quipo.it>                       |
42
// +----------------------------------------------------------------------+
43
//
44
// $Id: MDB2_nonstandard_pgsql.php,v 1.5 2007/03/04 21:36:08 quipo Exp $
45
 
46
class MDB2_nonstandard_pgsql extends MDB2_nonstandard {
47
 
48
    var $trigger_body = '';
49
 
50
    function createTrigger($trigger_name, $table_name) {
51
        $this->trigger_body = 'EXECUTE PROCEDURE '.$trigger_name.'_func();';
52
        $table_name = $this->db->quoteIdentifier($table_name);
53
        $sql = 'CREATE OR REPLACE FUNCTION '.$trigger_name.'_func() RETURNS trigger AS \'
54
                DECLARE
55
                    id_number INTEGER;
56
                BEGIN
57
                    SELECT INTO id_number id FROM '. $table_name .' WHERE id = NEW.id;
58
                    RETURN NEW;
59
                END;
60
                \' LANGUAGE \'plpgsql\';';
61
        $res = $this->db->exec($sql);
62
        if (PEAR::isError($res)) {
63
            return $res;
64
        }
65
 
66
        $query = 'CREATE TRIGGER '. $trigger_name .' AFTER UPDATE ON '. $table_name .'
67
                  FOR EACH ROW ' .$this->trigger_body;
68
        return $this->db->exec($query);
69
    }
70
 
71
    function checkTrigger($trigger_name, $table_name, $def) {
72
        parent::checkTrigger($trigger_name, $table_name, $def);
73
        $this->test->assertEquals($this->trigger_body, $def['trigger_body']);
74
    }
75
 
76
    function dropTrigger($trigger_name, $table_name) {
77
        return $this->db->exec('DROP TRIGGER '.$trigger_name .' ON '. $table_name);
78
    }
79
 
80
    function createFunction($name) {
81
        $query = "CREATE FUNCTION $name (Decimal(6,2), Decimal(6,2)) RETURNS Decimal(6,2)
82
AS 'select $1 + $2;'
83
LANGUAGE SQL
84
IMMUTABLE
85
RETURNS NULL ON NULL INPUT";
86
        return $this->db->exec($query);
87
    }
88
 
89
    function dropFunction($name) {
90
        return $this->db->exec('DROP FUNCTION '.$name.' (Decimal(6,2), Decimal(6,2))');
91
    }
92
}
93
 
94
?>