1--TEST--
2PDO_DBLIB: Uniqueidentifier column data type stringifying
3--SKIPIF--
4<?php
5if (!extension_loaded('pdo_dblib')) die('skip not loaded');
6require __DIR__ . '/config.inc';
7if (in_array(get_tds_version(), ['4.2', '4.6'])) die('skip feature unsupported by this TDS version');
8?>
9--FILE--
10<?php
11require __DIR__ . '/config.inc';
12
13
14$testGUID = '82A88958-672B-4C22-842F-216E2B88E72A';
15$testGUIDBinary = base64_decode('WImogitnIkyELyFuK4jnKg==');
16
17$sql = "SELECT CAST('$testGUID' as uniqueidentifier) as [guid]";
18
19//--------------------------------------------------------------------------------
20// 1. Get and Set the attribute
21//--------------------------------------------------------------------------------
22$db->setAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true);
23var_dump(true === $db->getAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER));
24$db->setAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, false);
25var_dump(false === $db->getAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER));
26
27
28//--------------------------------------------------------------------------------
29// 2. Binary
30//--------------------------------------------------------------------------------
31$stmt = $db->query($sql);
32$row = $stmt->fetch(PDO::FETCH_ASSOC);
33
34var_dump($row['guid'] === $testGUIDBinary);
35
36
37//--------------------------------------------------------------------------------
38// 3. PDO::ATTR_STRINGIFY_FETCHES must not affect `uniqueidentifier` representation
39//--------------------------------------------------------------------------------
40$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
41$stmt = $db->query($sql);
42$row = $stmt->fetch(PDO::FETCH_ASSOC);
43$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
44
45var_dump($row['guid'] === $testGUIDBinary);
46
47
48//--------------------------------------------------------------------------------
49// 4. Stringifying
50// ! With TDS protocol version <7.0 binary will be returned and the test will fail !
51// TODO: something from PDO::ATTR_SERVER_VERSION, PDO::ATTR_CLIENT_VERSION or PDO::ATTR_SERVER_INFO should be used
52// to get TDS version and skip this test in this case.
53//--------------------------------------------------------------------------------
54$db->setAttribute(PDO::DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER, true);
55$stmt = $db->query($sql);
56$row = $stmt->fetch(PDO::FETCH_ASSOC);
57
58var_dump($row['guid'] === $testGUID);
59var_dump($row['guid']);
60
61?>
62--EXPECT--
63bool(true)
64bool(true)
65bool(true)
66bool(true)
67bool(true)
68string(36) "82A88958-672B-4C22-842F-216E2B88E72A"
69