1--TEST--
2odbc_columns(): Basic test
3--EXTENSIONS--
4odbc
5--SKIPIF--
6<?php
7include 'skipif.inc';
8
9$conn = odbc_connect($dsn, $user, $pass);
10$result = @odbc_exec($conn, "SELECT @@Version");
11if ($result) {
12    $array = odbc_fetch_array($result);
13    $info = (string) reset($array);
14    if (!str_contains($info, "Microsoft SQL Server")) {
15       echo "skip MS SQL specific test";
16    }
17}
18?>
19--FILE--
20<?php
21
22include 'config.inc';
23
24$conn = odbc_connect($dsn, $user, $pass);
25odbc_exec($conn, 'CREATE DATABASE ColumnsTest');
26odbc_exec($conn, 'USE ColumnsTest');
27odbc_exec($conn, 'CREATE TABLE columns (foo INT NOT NULL, bar VARCHAR(20))');
28
29$res = odbc_columns($conn, "ColumnsTest", "dbo", "columns", "foo");
30var_dump(odbc_fetch_array($res));
31odbc_free_result($res);
32
33$res = odbc_columns($conn, "ColumnsTest", "dbo", "columns", null);
34var_dump(odbc_fetch_array($res));
35odbc_free_result($res);
36
37$res = odbc_columns($conn, "ColumnsTest", "dbo", null);
38var_dump(odbc_fetch_array($res));
39odbc_free_result($res);
40
41$res = odbc_columns($conn, "ColumnsTest", "db%", "columns", "foo");
42var_dump(odbc_fetch_array($res));
43odbc_free_result($res);
44
45$res = odbc_columns($conn, "ColumnsTest", "dbo", "column_", "bar");
46var_dump(odbc_fetch_array($res));
47odbc_free_result($res);
48
49$res = odbc_columns($conn, "ColumnsTest", "dbo", "columns", "b%");
50var_dump(odbc_fetch_array($res));
51odbc_free_result($res);
52
53?>
54--CLEAN--
55<?php
56require 'config.inc';
57$conn = odbc_connect($dsn, $user, $pass);
58odbc_exec($conn, 'USE ColumnsTest');
59odbc_exec($conn, 'DROP TABLE columns');
60odbc_exec($conn, 'USE master');
61odbc_exec($conn, 'DROP DATABASE ColumnsTest');
62?>
63--EXPECTF--
64array(29) {
65  ["TABLE_CAT"]=>
66  string(11) "ColumnsTest"
67  ["TABLE_SCHEM"]=>
68  string(3) "dbo"
69  ["TABLE_NAME"]=>
70  string(7) "columns"
71  ["COLUMN_NAME"]=>
72  string(3) "foo"
73  ["DATA_TYPE"]=>
74  string(1) "4"
75  ["TYPE_NAME"]=>
76  string(3) "int"
77  ["COLUMN_SIZE"]=>
78  string(2) "10"
79  ["BUFFER_LENGTH"]=>
80  string(1) "4"
81  ["DECIMAL_DIGITS"]=>
82  string(1) "0"
83  ["NUM_PREC_RADIX"]=>
84  string(2) "10"
85  ["NULLABLE"]=>
86  string(1) "0"
87  ["REMARKS"]=>
88  NULL
89  ["COLUMN_DEF"]=>
90  NULL
91  ["SQL_DATA_TYPE"]=>
92  string(1) "4"
93  ["SQL_DATETIME_SUB"]=>
94  NULL
95  ["CHAR_OCTET_LENGTH"]=>
96  NULL
97  ["ORDINAL_POSITION"]=>
98  string(1) "1"
99  ["IS_NULLABLE"]=>
100  string(2) "NO"
101  ["SS_IS_SPARSE"]=>
102  string(1) "0"
103  ["SS_IS_COLUMN_SET"]=>
104  string(1) "0"
105  ["SS_IS_COMPUTED"]=>
106  string(1) "0"
107  ["SS_IS_IDENTITY"]=>
108  string(1) "0"
109  ["SS_UDT_CATALOG_NAME"]=>
110  NULL
111  ["SS_UDT_SCHEMA_NAME"]=>
112  NULL
113  ["SS_UDT_ASSEMBLY_TYPE_NAME"]=>
114  NULL
115  ["SS_XML_SCHEMACOLLECTION_CATALOG_NAME"]=>
116  NULL
117  ["SS_XML_SCHEMACOLLECTION_SCHEMA_NAME"]=>
118  NULL
119  ["SS_XML_SCHEMACOLLECTION_NAME"]=>
120  NULL
121  ["SS_DATA_TYPE"]=>
122  string(2) "56"
123}
124array(29) {
125  ["TABLE_CAT"]=>
126  string(11) "ColumnsTest"
127  ["TABLE_SCHEM"]=>
128  string(3) "dbo"
129  ["TABLE_NAME"]=>
130  string(7) "columns"
131  ["COLUMN_NAME"]=>
132  string(3) "foo"
133  ["DATA_TYPE"]=>
134  string(1) "4"
135  ["TYPE_NAME"]=>
136  string(3) "int"
137  ["COLUMN_SIZE"]=>
138  string(2) "10"
139  ["BUFFER_LENGTH"]=>
140  string(1) "4"
141  ["DECIMAL_DIGITS"]=>
142  string(1) "0"
143  ["NUM_PREC_RADIX"]=>
144  string(2) "10"
145  ["NULLABLE"]=>
146  string(1) "0"
147  ["REMARKS"]=>
148  NULL
149  ["COLUMN_DEF"]=>
150  NULL
151  ["SQL_DATA_TYPE"]=>
152  string(1) "4"
153  ["SQL_DATETIME_SUB"]=>
154  NULL
155  ["CHAR_OCTET_LENGTH"]=>
156  NULL
157  ["ORDINAL_POSITION"]=>
158  string(1) "1"
159  ["IS_NULLABLE"]=>
160  string(2) "NO"
161  ["SS_IS_SPARSE"]=>
162  string(1) "0"
163  ["SS_IS_COLUMN_SET"]=>
164  string(1) "0"
165  ["SS_IS_COMPUTED"]=>
166  string(1) "0"
167  ["SS_IS_IDENTITY"]=>
168  string(1) "0"
169  ["SS_UDT_CATALOG_NAME"]=>
170  NULL
171  ["SS_UDT_SCHEMA_NAME"]=>
172  NULL
173  ["SS_UDT_ASSEMBLY_TYPE_NAME"]=>
174  NULL
175  ["SS_XML_SCHEMACOLLECTION_CATALOG_NAME"]=>
176  NULL
177  ["SS_XML_SCHEMACOLLECTION_SCHEMA_NAME"]=>
178  NULL
179  ["SS_XML_SCHEMACOLLECTION_NAME"]=>
180  NULL
181  ["SS_DATA_TYPE"]=>
182  string(2) "56"
183}
184array(29) {
185  ["TABLE_CAT"]=>
186  string(11) "ColumnsTest"
187  ["TABLE_SCHEM"]=>
188  string(3) "dbo"
189  ["TABLE_NAME"]=>
190  string(7) "columns"
191  ["COLUMN_NAME"]=>
192  string(3) "foo"
193  ["DATA_TYPE"]=>
194  string(1) "4"
195  ["TYPE_NAME"]=>
196  string(3) "int"
197  ["COLUMN_SIZE"]=>
198  string(2) "10"
199  ["BUFFER_LENGTH"]=>
200  string(1) "4"
201  ["DECIMAL_DIGITS"]=>
202  string(1) "0"
203  ["NUM_PREC_RADIX"]=>
204  string(2) "10"
205  ["NULLABLE"]=>
206  string(1) "0"
207  ["REMARKS"]=>
208  NULL
209  ["COLUMN_DEF"]=>
210  NULL
211  ["SQL_DATA_TYPE"]=>
212  string(1) "4"
213  ["SQL_DATETIME_SUB"]=>
214  NULL
215  ["CHAR_OCTET_LENGTH"]=>
216  NULL
217  ["ORDINAL_POSITION"]=>
218  string(1) "1"
219  ["IS_NULLABLE"]=>
220  string(2) "NO"
221  ["SS_IS_SPARSE"]=>
222  string(1) "0"
223  ["SS_IS_COLUMN_SET"]=>
224  string(1) "0"
225  ["SS_IS_COMPUTED"]=>
226  string(1) "0"
227  ["SS_IS_IDENTITY"]=>
228  string(1) "0"
229  ["SS_UDT_CATALOG_NAME"]=>
230  NULL
231  ["SS_UDT_SCHEMA_NAME"]=>
232  NULL
233  ["SS_UDT_ASSEMBLY_TYPE_NAME"]=>
234  NULL
235  ["SS_XML_SCHEMACOLLECTION_CATALOG_NAME"]=>
236  NULL
237  ["SS_XML_SCHEMACOLLECTION_SCHEMA_NAME"]=>
238  NULL
239  ["SS_XML_SCHEMACOLLECTION_NAME"]=>
240  NULL
241  ["SS_DATA_TYPE"]=>
242  string(2) "56"
243}
244array(29) {
245  ["TABLE_CAT"]=>
246  string(11) "ColumnsTest"
247  ["TABLE_SCHEM"]=>
248  string(3) "dbo"
249  ["TABLE_NAME"]=>
250  string(7) "columns"
251  ["COLUMN_NAME"]=>
252  string(3) "foo"
253  ["DATA_TYPE"]=>
254  string(1) "4"
255  ["TYPE_NAME"]=>
256  string(3) "int"
257  ["COLUMN_SIZE"]=>
258  string(2) "10"
259  ["BUFFER_LENGTH"]=>
260  string(1) "4"
261  ["DECIMAL_DIGITS"]=>
262  string(1) "0"
263  ["NUM_PREC_RADIX"]=>
264  string(2) "10"
265  ["NULLABLE"]=>
266  string(1) "0"
267  ["REMARKS"]=>
268  NULL
269  ["COLUMN_DEF"]=>
270  NULL
271  ["SQL_DATA_TYPE"]=>
272  string(1) "4"
273  ["SQL_DATETIME_SUB"]=>
274  NULL
275  ["CHAR_OCTET_LENGTH"]=>
276  NULL
277  ["ORDINAL_POSITION"]=>
278  string(1) "1"
279  ["IS_NULLABLE"]=>
280  string(2) "NO"
281  ["SS_IS_SPARSE"]=>
282  string(1) "0"
283  ["SS_IS_COLUMN_SET"]=>
284  string(1) "0"
285  ["SS_IS_COMPUTED"]=>
286  string(1) "0"
287  ["SS_IS_IDENTITY"]=>
288  string(1) "0"
289  ["SS_UDT_CATALOG_NAME"]=>
290  NULL
291  ["SS_UDT_SCHEMA_NAME"]=>
292  NULL
293  ["SS_UDT_ASSEMBLY_TYPE_NAME"]=>
294  NULL
295  ["SS_XML_SCHEMACOLLECTION_CATALOG_NAME"]=>
296  NULL
297  ["SS_XML_SCHEMACOLLECTION_SCHEMA_NAME"]=>
298  NULL
299  ["SS_XML_SCHEMACOLLECTION_NAME"]=>
300  NULL
301  ["SS_DATA_TYPE"]=>
302  string(2) "56"
303}
304array(29) {
305  ["TABLE_CAT"]=>
306  string(11) "ColumnsTest"
307  ["TABLE_SCHEM"]=>
308  string(3) "dbo"
309  ["TABLE_NAME"]=>
310  string(7) "columns"
311  ["COLUMN_NAME"]=>
312  string(3) "bar"
313  ["DATA_TYPE"]=>
314  string(2) "12"
315  ["TYPE_NAME"]=>
316  string(7) "varchar"
317  ["COLUMN_SIZE"]=>
318  string(2) "20"
319  ["BUFFER_LENGTH"]=>
320  string(2) "20"
321  ["DECIMAL_DIGITS"]=>
322  NULL
323  ["NUM_PREC_RADIX"]=>
324  NULL
325  ["NULLABLE"]=>
326  string(1) "1"
327  ["REMARKS"]=>
328  NULL
329  ["COLUMN_DEF"]=>
330  NULL
331  ["SQL_DATA_TYPE"]=>
332  string(2) "12"
333  ["SQL_DATETIME_SUB"]=>
334  NULL
335  ["CHAR_OCTET_LENGTH"]=>
336  string(2) "20"
337  ["ORDINAL_POSITION"]=>
338  string(1) "2"
339  ["IS_NULLABLE"]=>
340  string(3) "YES"
341  ["SS_IS_SPARSE"]=>
342  string(1) "0"
343  ["SS_IS_COLUMN_SET"]=>
344  string(1) "0"
345  ["SS_IS_COMPUTED"]=>
346  string(1) "0"
347  ["SS_IS_IDENTITY"]=>
348  string(1) "0"
349  ["SS_UDT_CATALOG_NAME"]=>
350  NULL
351  ["SS_UDT_SCHEMA_NAME"]=>
352  NULL
353  ["SS_UDT_ASSEMBLY_TYPE_NAME"]=>
354  NULL
355  ["SS_XML_SCHEMACOLLECTION_CATALOG_NAME"]=>
356  NULL
357  ["SS_XML_SCHEMACOLLECTION_SCHEMA_NAME"]=>
358  NULL
359  ["SS_XML_SCHEMACOLLECTION_NAME"]=>
360  NULL
361  ["SS_DATA_TYPE"]=>
362  string(2) "39"
363}
364array(29) {
365  ["TABLE_CAT"]=>
366  string(11) "ColumnsTest"
367  ["TABLE_SCHEM"]=>
368  string(3) "dbo"
369  ["TABLE_NAME"]=>
370  string(7) "columns"
371  ["COLUMN_NAME"]=>
372  string(3) "bar"
373  ["DATA_TYPE"]=>
374  string(2) "12"
375  ["TYPE_NAME"]=>
376  string(7) "varchar"
377  ["COLUMN_SIZE"]=>
378  string(2) "20"
379  ["BUFFER_LENGTH"]=>
380  string(2) "20"
381  ["DECIMAL_DIGITS"]=>
382  NULL
383  ["NUM_PREC_RADIX"]=>
384  NULL
385  ["NULLABLE"]=>
386  string(1) "1"
387  ["REMARKS"]=>
388  NULL
389  ["COLUMN_DEF"]=>
390  NULL
391  ["SQL_DATA_TYPE"]=>
392  string(2) "12"
393  ["SQL_DATETIME_SUB"]=>
394  NULL
395  ["CHAR_OCTET_LENGTH"]=>
396  string(2) "20"
397  ["ORDINAL_POSITION"]=>
398  string(1) "2"
399  ["IS_NULLABLE"]=>
400  string(3) "YES"
401  ["SS_IS_SPARSE"]=>
402  string(1) "0"
403  ["SS_IS_COLUMN_SET"]=>
404  string(1) "0"
405  ["SS_IS_COMPUTED"]=>
406  string(1) "0"
407  ["SS_IS_IDENTITY"]=>
408  string(1) "0"
409  ["SS_UDT_CATALOG_NAME"]=>
410  NULL
411  ["SS_UDT_SCHEMA_NAME"]=>
412  NULL
413  ["SS_UDT_ASSEMBLY_TYPE_NAME"]=>
414  NULL
415  ["SS_XML_SCHEMACOLLECTION_CATALOG_NAME"]=>
416  NULL
417  ["SS_XML_SCHEMACOLLECTION_SCHEMA_NAME"]=>
418  NULL
419  ["SS_XML_SCHEMACOLLECTION_NAME"]=>
420  NULL
421  ["SS_DATA_TYPE"]=>
422  string(2) "39"
423}
424