Fix postgres comma problem that's been here for awhile. bug 73513
[project/views.git] / views.install
1 <?php
2 // $Id$
3
4 function views_install() {
5 drupal_set_message('Installing views');
6 switch ($GLOBALS['db_type']) {
7 case 'mysqli':
8 case 'mysql':
9 db_query("CREATE TABLE if not exists {view_view} (
10 vid int(10) unsigned NOT NULL default '0',
11 name varchar(32) NOT NULL UNIQUE,
12 description varchar(255),
13 access varchar(255),
14 -- page fields
15 page int(1),
16 page_title varchar(255),
17 page_header longtext,
18 page_header_format int(4) NOT NULL,
19 page_empty longtext,
20 page_empty_format int(4) NOT NULL,
21 page_footer longtext,
22 page_footer_format int(4) NOT NULL,
23 page_type varchar(20),
24 use_pager int(1),
25 nodes_per_page int(5),
26 url varchar(255),
27 -- menu fields
28 menu int(1),
29 menu_tab int(1),
30 menu_tab_default int(1),
31 menu_tab_weight int(4),
32 menu_title varchar(255),
33 -- block fields
34 block int(1),
35 block_title varchar(255),
36 block_use_page_header int(1),
37 block_header longtext,
38 block_header_format int(4) NOT NULL,
39 block_use_page_footer int(1),
40 block_footer longtext,
41 block_footer_format int(4) NOT NULL,
42 block_use_page_empty int(1),
43 block_empty longtext,
44 block_empty_format int(4) NOT NULL,
45 block_type varchar(20),
46 nodes_per_block int(5),
47 block_more int(1),
48 -- breadcrumb
49 breadcrumb_no_home int(1), -- true means start breadcrumb trail from 'Home'.
50 -- other
51 changed int(11),
52 query longtext,
53 countquery longtext,
54 view_args_php longtext,
55 PRIMARY KEY (vid),
56 KEY (name)
57 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
58
59 db_query("CREATE TABLE if not exists {view_sort} (
60 vid int(10) unsigned NOT NULL default '0',
61 position int(2),
62 field varchar(255),
63 sortorder varchar(5),
64 options varchar(255),
65 tablename varchar(255),
66 KEY (vid)
67 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
68
69 db_query("CREATE TABLE if not exists {view_argument} (
70 vid int(10) unsigned NOT NULL default '0',
71 type varchar(255),
72 argdefault varchar(255),
73 title varchar(255),
74 options varchar(255),
75 position int(2),
76 wildcard varchar(32),
77 wildcard_substitution varchar(32),
78 KEY (vid)
79 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
80
81 db_query("CREATE TABLE if not exists {view_tablefield} (
82 vid int(10) unsigned NOT NULL default '0',
83 tablename varchar(255),
84 field varchar(255),
85 label varchar(255),
86 handler varchar(255),
87 sortable int(1),
88 defaultsort varchar(5),
89 options varchar(255),
90 position int(2),
91 KEY (vid)
92 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
93
94 db_query("CREATE TABLE if not exists {view_filter} (
95 vid int(10) unsigned NOT NULL default '0',
96 tablename varchar(255),
97 field varchar(255),
98 value longtext,
99 operator varchar(20),
100 options varchar(255),
101 position int(2),
102 KEY (vid)
103 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
104
105 db_query("CREATE TABLE if not exists {view_exposed_filter} (
106 vid int(10) unsigned NOT NULL default '0',
107 field varchar(255),
108 label varchar(255),
109 optional int(1),
110 is_default int(1),
111 operator int(1),
112 single int(1),
113 position int(2),
114 KEY (vid)
115 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
116
117 $success = TRUE;
118 break;
119 case 'pgsql':
120 db_query("CREATE TABLE {view_view} (
121 vid SERIAL,
122 name varchar(32) NOT NULL UNIQUE,
123 description varchar(255),
124 access varchar(255),
125 -- page fields
126 page smallint,
127 page_title varchar(255),
128 page_header text,
129 page_header_format smallint NOT NULL,
130 page_empty text,
131 page_empty_format smallint NOT NULL,
132 page_footer text,
133 page_footer_format smallint NOT NULL,
134 page_type varchar(20),
135 use_pager smallint,
136 nodes_per_page smallint,
137 url varchar(255),
138 -- menu fields
139 menu smallint,
140 menu_tab smallint,
141 menu_tab_default smallint,
142 menu_tab_weight smallint,
143 menu_title varchar(255),
144 -- block fields
145 block smallint,
146 block_title varchar(255),
147 block_use_page_header smallint,
148 block_header text,
149 block_header_format smallint NOT NULL,
150 block_use_page_footer smallint,
151 block_footer text,
152 block_footer_format smallint NOT NULL,
153 block_use_page_empty smallint,
154 block_empty text,
155 block_empty_format smallint NOT NULL,
156 block_type varchar(20),
157 nodes_per_block smallint,
158 block_more smallint,
159 -- breadcrumb
160 breadcrumb_no_home smallint, -- true means start breadcrumb trail from 'Home'.
161 -- other
162 changed integer,
163 query text,
164 countquery text,
165 view_args_php text,
166 PRIMARY KEY (vid)
167 )");
168 db_query("CREATE INDEX {view_view}_name_idx ON {view_view} (name)");
169
170 db_query("CREATE TABLE {view_sort} (
171 vid integer NOT NULL default '0',
172 position smallint,
173 field varchar(255),
174 sortorder varchar(5),
175 options varchar(255),
176 tablename varchar(255)
177 )");
178 db_query("CREATE INDEX {view_sort}_vid_idx ON {view_sort} (vid)");
179
180 db_query("CREATE TABLE {view_argument} (
181 vid integer NOT NULL default '0',
182 type varchar(255),
183 argdefault varchar(255),
184 title varchar(255),
185 options varchar(255),
186 position smallint,
187 wildcard varchar(32),
188 wildcard_substitution varchar(32)
189 )");
190 db_query("CREATE INDEX {view_argument}_vid_idx ON {view_argument} (vid)");
191
192 db_query("CREATE TABLE {view_tablefield} (
193 vid integer NOT NULL default '0',
194 tablename varchar(255),
195 field varchar(255),
196 label varchar(255),
197 handler varchar(255),
198 sortable smallint,
199 defaultsort varchar(5),
200 options varchar(255),
201 position smallint
202 )");
203 db_query("CREATE INDEX {view_tablefield}_vid_idx ON {view_tablefield} (vid)");
204
205 db_query("CREATE TABLE {view_filter} (
206 vid integer NOT NULL default '0',
207 tablename varchar(255),
208 field varchar(255),
209 value text,
210 operator varchar(20),
211 options varchar(255),
212 position smallint
213 )");
214 db_query("CREATE INDEX {view_filter}_vid_idx ON {view_filter} (vid)");
215 db_query("CREATE TABLE {view_exposed_filter} (
216 vid integer NOT NULL default '0',
217 field varchar(255),
218 label varchar(255),
219 optional smallint,
220 is_default smallint,
221 operator smallint,
222 single smallint,
223 position smallint
224 )");
225 db_query("CREATE INDEX {view_exposed_filter}_vid_idx ON {view_exposed_filter} (vid)");
226
227 $success = TRUE;
228 break;
229 } // End case
230
231 if ($success) {
232 drupal_set_message(t('Views module installed tables successfully.'));
233 }
234 else {
235 drupal_set_message(t('The installation of views module was unsuccessful.'), 'error');
236 }
237 }
238
239 /*
240 * update module for UTF.
241 */
242 function views_update_1() {
243 return _system_update_utf8(array('view_view', 'view_tablefield', 'view_filter', 'view_sort', 'view_argument'));
244 }
245
246 /**
247 * Dummy function cause we're apparently not to skip update #s.
248 */
249 function views_update_2() {
250 // dummy function
251 return array();
252 }
253 /*
254 * update module for exposed filters.
255 */
256 function views_update_3() {
257 $ret = array();
258 // db_add_column($ret, 'view_view', 'page_empty', 'longtext');
259 // db_add_column($ret, 'view_view', 'page_empty_format', 'int(4)', array('not null' => TRUE));
260 // db_add_column($ret, 'view_view', 'block_use_page_empty', 'int(1)');
261 // db_add_column($ret, 'view_view', 'block_empty', 'longtext');
262 // db_add_column($ret, 'view_view', 'block_empty_format', 'int(4)', array('not null' => TRUE));
263 switch($GLOBALS['db_type']) {
264 case 'mysql':
265 case 'mysqli':
266 $ret[] = update_sql("CREATE TABLE if not exists {view_exposed_filter} (
267 vid int(10) unsigned NOT NULL default '0',
268 field varchar(255),
269 label varchar(255),
270 optional int(1),
271 is_default int(1),
272 operator int(1),
273 single int(1),
274 position int(2),
275 KEY (vid)
276 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;");
277 break;
278 case 'pgsql':
279 $ret[] = update_sql("CREATE TABLE {view_exposed_filter} (
280 vid numeric(10) unsigned NOT NULL default '0',
281 field varchar(255),
282 label varchar(255),
283 optional numeric(1),
284 is_default numeric(1),
285 operator numeric(1),
286 single numeric(1),
287 position numeric(2),
288 )");
289 $ret[] = update_sql("CREATE INDEX {view_exposed_filter}_vid_idx ON {view_exposed_filter} (vid)");
290 break;
291 }
292 return $ret;
293 }
294
295 function views_update_4() {
296 $ret = array();
297 db_add_column($ret, 'view_view', 'page_footer', 'longtext');
298 db_add_column($ret, 'view_view', 'page_footer_format', 'int(4)', array('default' => 0));
299 db_add_column($ret, 'view_view', 'block_use_page_footer', 'int(1)');
300 db_add_column($ret, 'view_view', 'block_footer', 'longtext');
301 db_add_column($ret, 'view_view', 'block_footer_format', 'int(4)', array('default' => 0));
302 db_add_column($ret, 'view_view', 'page_empty', 'longtext');
303 db_add_column($ret, 'view_view', 'page_empty_format', 'int(4)', array('default' => 0));
304 db_add_column($ret, 'view_view', 'block_use_page_empty', 'int(1)');
305 db_add_column($ret, 'view_view', 'block_empty', 'longtext');
306 db_add_column($ret, 'view_view', 'block_empty_format', 'int(4)', array('default' => 0));
307 return $ret;
308 }
309
310 function views_update_5() {
311 $ret = array();
312 db_add_column($ret, 'view_view', 'view_args_php', 'longtext');
313 return $ret;
314 }
315
316 function views_update_6() {
317 $ret = array();
318 db_add_column($ret, 'view_tablefield', 'options', 'varchar(255)');
319 return $ret;
320 }
321
322 function views_update_7() {
323 $ret = array();
324 $ret[] = update_sql("ALTER TABLE {view_argument} MODIFY type varchar(255)");
325 return $ret;
326 }
327
328 function views_update_8() {
329 $ret = array();
330 $ret[] = update_sql("ALTER TABLE {view_view} MODIFY nodes_per_page int(5)");
331 return $ret;
332 }
333
334 function views_update_9() {
335 $ret = array();
336 db_add_column($ret, 'view_argument', 'wildcard', 'varchar(32)');
337 db_add_column($ret, 'view_argument', 'wildcard_substitution', 'varchar(32)');
338 return $ret;
339 }