Annotation of embedaddon/php/ext/pdo_mysql/tests/pdo_mysql_get_attribute.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: MySQL PDO->getAttribute()
3: --SKIPIF--
4: <?php
5: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7: MySQLPDOTest::skip();
8: $db = MySQLPDOTest::factory();
9: if (false == MySQLPDOTest::detect_transactional_mysql_engine($db))
10: die("skip Transactional engine not found");
11: ?>
12: --FILE--
13: <?php
14: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
15: $db = MySQLPDOTest::factory();
16: MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
17:
18: function find_invalid_int($valid_options) {
19: do {
20: $invalid = mt_rand(-10000, 10000);
21: } while (in_array($invalid, $valid_options));
22: return $invalid;
23: }
24:
25: function set_and_get($offset, $db, $attribute, $value) {
26:
27: $value_type = gettype($value);
28: try {
29:
30: if (!$db->setAttribute($attribute, $value)) {
31: printf("[%03d] Cannot set attribute '%s' to value '%s'\n",
32: $offset, $attribute, var_export($tmp, true));
33: return false;
34: }
35:
36: if (gettype($value) != $value_type) {
37: printf("[%03d] Call to PDO::setAttribute(int attribute, mixed value) has changed the type of value from %s to %s, test will not work properly\n",
38: $offset, $value_type, gettype($value));
39: return false;
40: }
41:
42: $tmp = $db->getAttribute($attribute);
43: if ($tmp !== $value) {
44: printf("[%03d] Attribute '%s' was set to '%s'/%s but getAttribute() reports '%s'/%s\n",
45: $offset, $attribute, var_export($value, true), gettype($value), var_export($tmp, true), gettype($tmp));
46: return false;
47: }
48:
49: } catch (PDOException $e) {
50: printf("[%03d] %s, [%s] %s\n",
51: $offset, $e->getMessage(),
52: $db->errorCode(), implode(' ', $db->errorInfo()));
53: return false;
54: }
55:
56: return true;
57: }
58:
59: set_and_get(1, $db, PDO::ATTR_AUTOCOMMIT, 1);
60: /*
61: set_and_get(2, $db, PDO::ATTR_AUTOCOMMIT, 0);
62: set_and_get(3, $db, PDO::ATTR_AUTOCOMMIT, -1);
63: $obj = new stdClass();
64: set_and_get(4, $db, PDO::ATTR_AUTOCOMMIT, $obj);
65:
66: set_and_get(5, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, 1);
67: set_and_get(6, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, 0);
68: set_and_get(7, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, -1);
69: $tmp = array();
70: set_and_get(8, $db, PDO::MYSQL_ATTR_LOCAL_INFILE, $tmp);
71:
72: set_and_get(9, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, '');
73: set_and_get(10, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, 'SOME SQL');
74: set_and_get(11, $db, PPDO::MYSQL_ATTR_INIT_COMMAND, -1);
75:
76: */
77: /*
78: PDO::MYSQL_ATTR_READ_DEFAULT_FILE (integer)
79:
80: Read options from the named option file instead of from my.cnf.
81: PDO::MYSQL_ATTR_READ_DEFAULT_GROUP (integer)
82:
83: Read options from the named group from my.cnf or the file specified with MYSQL_READ_DEFAULT_FILE.
84: PDO::MYSQL_ATTR_MAX_BUFFER_SIZE (integer)
85:
86: Maximum buffer size. Defaults to 1 MiB.
87: PDO::MYSQL_ATTR_DIRECT_QUERY (integer)
88:
89: Perform direct queries, don't use prepared statements.
90: */
91: /*
92: TODO - read only
93: PDO::ATTR_CONNECTION_STATUS
94: PDO::ATTR_SERVER_INFO
95: */
96:
97: print "done!";
98: ?>
99: --CLEAN--
100: <?php
101: require dirname(__FILE__) . '/mysql_pdo_test.inc';
102: MySQLPDOTest::dropTestTable();
103: ?>
104: --EXPECTF--
105: [001] Call to PDO::setAttribute(int attribute, mixed value) has changed the type of value from integer to boolean, test will not work properly
106: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>