Skip to content

Commit 1d36644

Browse files
committed
[pdo] fix set and get attr
1 parent 6bd680b commit 1d36644

14 files changed

+63
-44
lines changed

ext/pdo/pdo_dbh.c

+3
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,9 @@ PHP_METHOD(PDO, getAttribute)
913913
return;
914914
case PDO_ATTR_DEFAULT_FETCH_MODE:
915915
RETURN_LONG(dbh->default_fetch_type);
916+
917+
case PDO_ATTR_STRINGIFY_FETCHES:
918+
RETURN_BOOL(dbh->stringify);
916919
default:
917920
break;
918921
}

ext/pdo_dblib/dblib_driver.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ static bool dblib_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
290290
}
291291
return SUCCEED == dbsettime(lval);
292292
case PDO_DBLIB_ATTR_STRINGIFY_UNIQUEIDENTIFIER:
293-
if (!pdo_get_long_param(&lval, val)) {
293+
if (!pdo_get_bool_param(&bval, val)) {
294294
return false;
295295
}
296-
H->stringify_uniqueidentifier = lval;
296+
H->stringify_uniqueidentifier = bval;
297297
return true;
298298
case PDO_DBLIB_ATTR_SKIP_EMPTY_ROWSETS:
299299
if (!pdo_get_bool_param(&bval, val)) {
@@ -302,10 +302,10 @@ static bool dblib_set_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
302302
H->skip_empty_rowsets = bval;
303303
return true;
304304
case PDO_DBLIB_ATTR_DATETIME_CONVERT:
305-
if (!pdo_get_long_param(&lval, val)) {
305+
if (!pdo_get_bool_param(&bval, val)) {
306306
return false;
307307
}
308-
H->datetime_convert = lval;
308+
H->datetime_convert = bval;
309309
return true;
310310
default:
311311
return false;

ext/pdo_firebird/firebird_driver.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val)
10801080
char tmp[INFO_BUF_LEN];
10811081

10821082
case PDO_ATTR_AUTOCOMMIT:
1083-
ZVAL_LONG(val,dbh->auto_commit);
1083+
ZVAL_BOOL(val,dbh->auto_commit);
10841084
return 1;
10851085

10861086
case PDO_ATTR_CONNECTION_STATUS:
@@ -1124,6 +1124,18 @@ static int pdo_firebird_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val)
11241124
case PDO_ATTR_FETCH_TABLE_NAMES:
11251125
ZVAL_BOOL(val, H->fetch_table_names);
11261126
return 1;
1127+
1128+
case PDO_FB_ATTR_DATE_FORMAT:
1129+
ZVAL_STRING(val, H->date_format);
1130+
return 1;
1131+
1132+
case PDO_FB_ATTR_TIME_FORMAT:
1133+
ZVAL_STRING(val, H->time_format);
1134+
return 1;
1135+
1136+
case PDO_FB_ATTR_TIMESTAMP_FORMAT:
1137+
ZVAL_STRING(val, H->timestamp_format);
1138+
return 1;
11271139
}
11281140
return 0;
11291141
}

ext/pdo_firebird/tests/autocommit_change_mode.phpt

+8-8
Original file line numberDiff line numberDiff line change
@@ -91,42 +91,42 @@ echo "done!";
9191
--EXPECT--
9292
========== not in manually transaction ==========
9393
auto commit ON from ON
94-
int(1)
94+
bool(true)
9595
Success
9696

9797
auto commit OFF from ON
98-
int(0)
98+
bool(false)
9999
Success
100100

101101
auto commit OFF from OFF
102-
int(0)
102+
bool(false)
103103
Success
104104

105105
auto commit ON from OFF
106-
int(1)
106+
bool(true)
107107
Success
108108

109109
========== in manually transaction ==========
110110
begin transaction
111111

112112
auto commit ON from ON, expect error
113-
int(1)
113+
bool(true)
114114
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
115115

116116
auto commit OFF from ON, expect error
117-
int(1)
117+
bool(true)
118118
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
119119

120120
end transaction
121121
auto commit OFF
122122
begin transaction
123123

124124
auto commit ON from OFF, expect error
125-
int(0)
125+
bool(false)
126126
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
127127

128128
auto commit OFF from OFF, expect error
129-
int(0)
129+
bool(false)
130130
SQLSTATE[HY000]: General error: Cannot change autocommit mode while a transaction is already open
131131

132132
end transaction

ext/pdo_mysql/mysql_driver.c

+6-2
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_
532532
break;
533533

534534
case PDO_ATTR_AUTOCOMMIT:
535-
ZVAL_LONG(return_value, dbh->auto_commit);
535+
ZVAL_BOOL(return_value, dbh->auto_commit);
536536
break;
537537

538538
case PDO_ATTR_DEFAULT_STR_PARAM:
@@ -545,7 +545,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_
545545

546546
case PDO_ATTR_EMULATE_PREPARES:
547547
case PDO_MYSQL_ATTR_DIRECT_QUERY:
548-
ZVAL_LONG(return_value, H->emulate_prepare);
548+
ZVAL_BOOL(return_value, H->emulate_prepare);
549549
break;
550550

551551
#ifndef PDO_USE_MYSQLND
@@ -576,6 +576,10 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_
576576
}
577577
#endif
578578

579+
case PDO_ATTR_FETCH_TABLE_NAMES:
580+
ZVAL_BOOL(return_value, H->fetch_table_names);
581+
break;
582+
579583
default:
580584
PDO_DBG_RETURN(0);
581585
}

ext/pdo_mysql/tests/bug68371.phpt

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ $pdo->setAttribute (\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
1515

1616
$attrs = [
1717
// Extensive test: default value and set+get values
18-
PDO::ATTR_EMULATE_PREPARES => array(null, 1, 0),
19-
PDO::MYSQL_ATTR_DIRECT_QUERY => array(null, 0, 1),
18+
PDO::ATTR_EMULATE_PREPARES => array(null, true, false),
19+
PDO::MYSQL_ATTR_DIRECT_QUERY => array(null, false, true),
2020
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => array(null, false, true),
2121

2222
// Just test the default
@@ -67,16 +67,16 @@ foreach ($attrs as $a => $vals) {
6767

6868
?>
6969
--EXPECTF--
70-
int(1)
70+
bool(true)
7171
OK
7272
OK
73-
int(0)
73+
bool(false)
7474
OK
7575
OK
7676
bool(true)
7777
OK
7878
OK
79-
int(1)
79+
bool(true)
8080
ERR
8181
ERR
8282
int(2)
@@ -93,9 +93,9 @@ array(1) {
9393
[0]=>
9494
string(12) "PDOStatement"
9595
}
96-
ERR
96+
bool(false)
9797
ERR
9898
string(5) "mysql"
99-
ERR
99+
bool(false)
100100
ERR
101101
int(4)

ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt

+5-5
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ MySQLPDOTest::skip();
5454

5555
$defaults = [
5656
PDO::ATTR_PERSISTENT => false,
57-
PDO::ATTR_AUTOCOMMIT => 1,
57+
PDO::ATTR_AUTOCOMMIT => true,
5858
/* TODO - why is this a valid option if getAttribute() does not support it?! */
5959
PDO::ATTR_TIMEOUT => false,
60-
PDO::ATTR_EMULATE_PREPARES => 1,
60+
PDO::ATTR_EMULATE_PREPARES => true,
6161
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
6262
/* TODO getAttribute() does not handle it */
6363
PDO::MYSQL_ATTR_LOCAL_INFILE => false,
6464
/* TODO getAttribute() does not handle it */
65-
PDO::MYSQL_ATTR_DIRECT_QUERY => 1,
65+
PDO::MYSQL_ATTR_DIRECT_QUERY => true,
6666
PDO::MYSQL_ATTR_INIT_COMMAND => '',
6767
];
6868

@@ -151,8 +151,8 @@ MySQLPDOTest::skip();
151151
set_option_and_check(24, PDO::MYSQL_ATTR_INIT_COMMAND, '', 'PDO::MYSQL_ATTR_INIT_COMMAND');
152152
set_option_and_check(25, PDO::MYSQL_ATTR_INIT_COMMAND, 'INSERT INTO nonexistent(invalid) VALUES (1)', 'PDO::MYSQL_ATTR_INIT_COMMAND');
153153

154-
set_option_and_check(33, PDO::MYSQL_ATTR_DIRECT_QUERY, 1, 'PDO::MYSQL_ATTR_DIRECT_QUERY');
155-
set_option_and_check(34, PDO::MYSQL_ATTR_DIRECT_QUERY, 0, 'PDO::MYSQL_ATTR_DIRECT_QUERY');
154+
set_option_and_check(33, PDO::MYSQL_ATTR_DIRECT_QUERY, true, 'PDO::MYSQL_ATTR_DIRECT_QUERY');
155+
set_option_and_check(34, PDO::MYSQL_ATTR_DIRECT_QUERY, false, 'PDO::MYSQL_ATTR_DIRECT_QUERY');
156156

157157
if (defined('PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY')) {
158158
set_option_and_check(35, PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY, null, 'PDO::MYSQL_ATTR_LOCAL_INFILE_DIRECTORY');

ext/pdo_mysql/tests/pdo_mysql_attr_autocommit.phpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ MySQLPDOTest::skip();
1313
$db = MySQLPDOTest::factory();
1414

1515
// autocommit should be on by default
16-
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
16+
if (true !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
1717
printf("[001] Expecting int/1 got %s\n", var_export($tmp, true));
1818

1919
// lets see if the server agrees to that
@@ -33,7 +33,7 @@ MySQLPDOTest::skip();
3333
if (!$db->query('SET autocommit = 1'))
3434
printf("[005] Cannot turn on server autocommit mode, %s\n", var_export($db->errorInfo(), true));
3535

36-
if (0 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
36+
if (false !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
3737
printf("[006] Expecting int/0 got %s\n", var_export($tmp, true));
3838

3939
// off -> on
@@ -47,7 +47,7 @@ MySQLPDOTest::skip();
4747
if (!$row['_autocommit'])
4848
printf("[009] Server autocommit mode should be on, got '%s'\n", var_export($row['_autocommit']));
4949

50-
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
50+
if (true !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
5151
printf("[010] Expecting int/1 got %s\n", var_export($tmp, true));
5252

5353
$table = 'pdo_mysql_attr_autocommit';

ext/pdo_mysql/tests/pdo_mysql_begintransaction.phpt

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ MySQLPDOTest::skipNotTransactionalEngine();
1616

1717
MySQLPDOTest::createTestTable($table, $db, MySQLPDOTest::detect_transactional_mysql_engine($db));
1818

19-
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
19+
if (true !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
2020
printf("[001] Autocommit should be on by default\n");
2121

2222
if (false == $db->beginTransaction())
2323
printf("[002] Cannot start a transaction, [%s] [%s]\n",
2424
$db->errorCode(), implode(' ', $db->errorInfo()));
2525

26-
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
26+
if (true !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
2727
printf("[003] Autocommit should be on by default, beginTransaction() shall not impact it\n");
2828

2929
if (0 == $db->exec("DELETE FROM {$table}"))
@@ -50,7 +50,7 @@ MySQLPDOTest::skipNotTransactionalEngine();
5050
if (!$db->commit())
5151
printf("[008] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
5252

53-
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
53+
if (true !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
5454
printf("[009] Autocommit should be on after commit()\n");
5555

5656
if (!($stmt = $db->query(sprintf('SELECT id, label FROM %s WHERE id = %d', $table, $row['id']))))
@@ -91,7 +91,7 @@ MySQLPDOTest::skipNotTransactionalEngine();
9191
if (!$db->rollback())
9292
printf("[018] [%s] %s\n", $db->errorCode(), implode(' ', $db->errorInfo()));
9393

94-
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
94+
if (true !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
9595
printf("[019] Autocommit should be on after rollback\n");
9696

9797
if (!($stmt = $db->query(sprintf('SELECT id, label FROM %s WHERE id = %d', $table, $row['id']))))
@@ -132,7 +132,7 @@ MySQLPDOTest::skipNotTransactionalEngine();
132132

133133
// Turn off autocommit using a server variable
134134
$db->exec('SET @@autocommit = 0');
135-
if (1 === $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
135+
if (true === $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
136136
printf("[028] I'm confused, how can autocommit be on? Didn't I say I want to manually control transactions?\n");
137137

138138
if (!$db->beginTransaction())
@@ -155,7 +155,7 @@ MySQLPDOTest::skipNotTransactionalEngine();
155155
printf("[031] Cannot start a transaction, [%s] [%s]\n",
156156
$db->errorCode(), implode(' ', $db->errorInfo()));
157157

158-
if (1 !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
158+
if (true !== $db->getAttribute(PDO::ATTR_AUTOCOMMIT))
159159
printf("[032] Autocommit should be on my default, beginTransaction() should not change that\n");
160160

161161
if (0 == $db->exec("DELETE FROM {$table}"))

ext/pdo_mysql/tests/pdo_mysql_commit.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ MySQLPDOTest::skipNotTransactionalEngine();
3535

3636
// pdo_transaction_transitions should check this as well...
3737
// ... just to be sure the most basic stuff really works we check it again...
38-
if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
38+
if (true !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
3939
printf("[003] According to the manual we should be back to autocommit mode, got %s/%s\n",
4040
gettype($tmp), var_export($tmp, true));
4141

ext/pdo_mysql/tests/pdo_mysql_get_attribute.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ MySQLPDOTest::skipNotTransactionalEngine();
4343
return true;
4444
}
4545

46-
set_and_get(1, $db, PDO::ATTR_AUTOCOMMIT, 1);
46+
set_and_get(1, $db, PDO::ATTR_AUTOCOMMIT, true);
4747
/*
4848
set_and_get(2, $db, PDO::ATTR_AUTOCOMMIT, 0);
4949
set_and_get(3, $db, PDO::ATTR_AUTOCOMMIT, -1);

ext/pdo_mysql/tests/pdo_mysql_rollback.phpt

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ $db->exec('DROP TABLE IF EXISTS pdo_mysql_rollback');
9393
$db->exec('DROP TABLE IF EXISTS pdo_mysql_rollback_2');
9494
?>
9595
--EXPECT--
96-
int(1)
97-
int(0)
98-
int(1)
99-
int(0)
96+
bool(true)
97+
bool(false)
98+
bool(true)
99+
bool(false)
100100
done!

ext/pdo_odbc/odbc_driver.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static int odbc_handle_get_attr(pdo_dbh_t *dbh, zend_long attr, zval *val)
384384
case PDO_ATTR_CONNECTION_STATUS:
385385
break;
386386
case PDO_ODBC_ATTR_ASSUME_UTF8:
387-
ZVAL_BOOL(val, H->assume_utf8 ? 1 : 0);
387+
ZVAL_BOOL(val, H->assume_utf8);
388388
return 1;
389389

390390
}

ext/pdo_pgsql/tests/bug68371.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ array(1) {
9595
ERR
9696
ERR
9797
string(5) "pgsql"
98-
ERR
98+
bool(true)
9999
ERR
100100
int(4)

0 commit comments

Comments
 (0)