1--TEST--
2odbc_primarykeys(): Basic test for odbc_primarykeys()
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?>
20--FILE--
21<?php
22
23include 'config.inc';
24
25$conn = odbc_connect($dsn, $user, $pass);
26odbc_exec($conn, 'CREATE DATABASE PrimarykeysTest');
27odbc_exec($conn, 'USE PrimarykeysTest');
28odbc_exec($conn, 'CREATE TABLE primarykeys (test INT NOT NULL)');
29
30$res = odbc_primarykeys($conn, "PrimarykeysTest", "dbo", "primarykeys");
31var_dump(odbc_fetch_array($res));
32odbc_free_result($res);
33
34odbc_exec($conn, 'ALTER TABLE primarykeys ADD CONSTRAINT primarykeys_pk PRIMARY KEY (test)');
35
36$res = odbc_primarykeys($conn, "PrimarykeysTest", "dbo", "");
37var_dump(odbc_fetch_array($res));
38odbc_free_result($res);
39
40$res = odbc_primarykeys($conn, "PrimarykeysTest", "", "primarykeys");
41var_dump(odbc_fetch_array($res));
42odbc_free_result($res);
43
44$res = odbc_primarykeys($conn, null, "dbo", "primarykeys");
45var_dump(odbc_fetch_array($res));
46odbc_free_result($res);
47
48$res = odbc_primarykeys($conn, "PrimarykeysTest", "dbo", "primarykeys");
49var_dump(odbc_fetch_array($res));
50odbc_free_result($res);
51
52?>
53--CLEAN--
54<?php
55require 'config.inc';
56$conn = odbc_connect($dsn, $user, $pass);
57odbc_exec($conn, 'USE PrimarykeysTest');
58odbc_exec($conn, 'DROP TABLE primarykeys');
59odbc_exec($conn, 'USE master');
60odbc_exec($conn, 'DROP DATABASE PrimarykeysTest');
61?>
62--EXPECTF--
63bool(false)
64bool(false)
65bool(false)
66array(%d) {
67  ["TABLE_CAT"]=>
68  string(%d) "PrimarykeysTest"
69  ["TABLE_SCHEM"]=>
70  string(%d) "dbo"
71  ["TABLE_NAME"]=>
72  string(%d) "primarykeys"
73  ["COLUMN_NAME"]=>
74  string(%d) "test"
75  ["KEY_SEQ"]=>
76  string(%d) "1"
77  ["PK_NAME"]=>
78  string(%d) "primarykeys_pk"
79}
80array(%d) {
81  ["TABLE_CAT"]=>
82  string(%d) "PrimarykeysTest"
83  ["TABLE_SCHEM"]=>
84  string(%d) "dbo"
85  ["TABLE_NAME"]=>
86  string(%d) "primarykeys"
87  ["COLUMN_NAME"]=>
88  string(%d) "test"
89  ["KEY_SEQ"]=>
90  string(%d) "1"
91  ["PK_NAME"]=>
92  string(%d) "primarykeys_pk"
93}
94