-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.inc
122 lines (116 loc) · 2.9 KB
/
install.inc
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* @file
* Installation code for DB2 embedded database engine.
*/
/**
* Specifies installation tasks for DB2 and equivalent databases.
*/
class DatabaseTasks_ibm extends DatabaseTasks {
/**
* The PDO driver name for DB2 and equivalent databases.
*
* @var string
*/
protected $pdoDriver = 'ibm';
public function __construct() {
$this->tasks[] = array(
'function' => 'initializeDatabase',
'arguments' => array(),
);
}
/**
* Returns a human-readable name string for DB2 and equivalent databases.
*/
public function name() {
return st('DB2');
}
/**
* Returns the minimum version for DB2.
*/
public function minimumVersion() {
return '10.1';
}
/**
* Make DB2 Drupal friendly.
*/
public function initializeDatabase() {
try {
db_query('CREATE OR REPLACE
FUNCTION greatest
(
p1 NUMBER,
p2 NUMBER,
p3 NUMBER DEFAULT NULL)
RETURN NUMBER
AS
BEGIN
IF p3 IS NULL THEN
IF p1 > p2 OR p2 IS NULL THEN
RETURN p1;
ELSE
RETURN p2;
END IF;
ELSE
RETURN greatest(p1, greatest(p2, p3));
END IF;
END;');
db_query('CREATE OR REPLACE
FUNCTION substring
(
p_s NVARCHAR2,
p_start NUMBER,
p_length NUMBER DEFAULT NULL)
RETURN NVARCHAR2
AS
BEGIN
IF p_length IS NULL THEN
RETURN SUBSTR(p_s, p_start);
ELSE
RETURN SUBSTR(p_s, p_start, p_length);
END IF;
END;');
db_query('CREATE OR REPLACE
FUNCTION substring_index
(
p_buff NVARCHAR2,
p_delimiter NVARCHAR2,
p_count NUMBER)
RETURN NVARCHAR2
AS
v_end NUMBER:= 1;
BEGIN
IF p_count > 0 THEN
FOR i IN 1..p_count
LOOP
v_end := instr(p_buff, p_delimiter, v_end + 1);
IF v_end = 0 THEN
v_end:= LENGTH(p_buff);
END IF;
END LOOP;
RETURN SUBSTR(p_buff, 1, v_end - 1);
ELSE
v_end := LENGTH(p_buff);
FOR i IN 1..(p_count* - 1)
LOOP
v_end := instr(p_buff, p_delimiter, (LENGTH(p_buff) - (v_end - 2))* - 1);
IF v_end = 0 THEN
v_end:= LENGTH(p_buff);
END IF;
END LOOP;
RETURN SUBSTR(p_buff, v_end + 1);
END IF;
END;');
db_query('CREATE OR REPLACE
FUNCTION rand
RETURN NUMBER
AS
BEGIN
RETURN ABS(MOD(DBMS_RANDOM.RANDOM,10000001)/10000000);
END;');
}
catch (Exception $e) {
$this->fail(st('Drupal could not be correctly setup with the existing database. Revise any errors.'));
}
}
}