Skip to content

Commit b9c07cc

Browse files
committed
Revert "Improve errors for mysqli_stmt_attr_set()"
Because I can't figure out why Windows fails This reverts commit d3e9279.
1 parent 3a986ac commit b9c07cc

File tree

2 files changed

+32
-45
lines changed

2 files changed

+32
-45
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,52 +2252,26 @@ PHP_FUNCTION(mysqli_stmt_attr_set)
22522252
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "Oll", &mysql_stmt, mysqli_stmt_class_entry, &attr, &mode_in) == FAILURE) {
22532253
RETURN_THROWS();
22542254
}
2255+
22552256
MYSQLI_FETCH_RESOURCE_STMT(stmt, mysql_stmt, MYSQLI_STATUS_VALID);
22562257

22572258
if (mode_in < 0) {
22582259
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than or equal to 0");
22592260
RETURN_THROWS();
22602261
}
22612262

2263+
/* TODO Improve the mode to depend on the ATTR */
22622264
switch (attr) {
22632265
#if MYSQL_VERSION_ID >= 50107
22642266
case STMT_ATTR_UPDATE_MAX_LENGTH:
22652267
mode_b = (my_bool) mode_in;
22662268
mode_p = &mode_b;
22672269
break;
22682270
#endif
2269-
case STMT_ATTR_CURSOR_TYPE: {
2270-
switch (mode_in) {
2271-
case CURSOR_TYPE_NO_CURSOR:
2272-
case CURSOR_TYPE_READ_ONLY:
2273-
case CURSOR_TYPE_FOR_UPDATE:
2274-
case CURSOR_TYPE_SCROLLABLE:
2275-
break;
2276-
default:
2277-
zend_argument_value_error(ERROR_ARG_POS(3), "must be one of MYSQLI_CURSOR_TYPE_NO_CURSOR, "
2278-
"MYSQLI_CURSOR_TYPE_READ_ONLY, MYSQLI_CURSOR_TYPE_FOR_UPDATE, or MYSQLI_CURSOR_TYPE_SCROLLABLE "
2279-
"for attribute MYSQLI_STMT_ATTR_CURSOR_TYPE");
2280-
RETURN_THROWS();
2281-
}
2282-
mode = mode_in;
2283-
mode_p = &mode;
2284-
break;
2285-
}
2286-
case STMT_ATTR_PREFETCH_ROWS:
2287-
if (mode_in < 1) {
2288-
zend_argument_value_error(ERROR_ARG_POS(3), "must be greater than 0 for attribute MYSQLI_STMT_ATTR_PREFETCH_ROWS");
2289-
RETURN_THROWS();
2290-
}
2271+
default:
22912272
mode = mode_in;
22922273
mode_p = &mode;
22932274
break;
2294-
default:
2295-
zend_argument_value_error(ERROR_ARG_POS(2), "must be one of "
2296-
#if MYSQL_VERSION_ID >= 50107
2297-
"MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, "
2298-
#endif
2299-
"MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE");
2300-
RETURN_THROWS();
23012275
}
23022276

23032277
#ifndef MYSQLI_USE_MYSQLND

ext/mysqli/tests/mysqli_stmt_attr_set.phpt

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,29 @@ require_once("connect.inc");
3333
}
3434

3535
$stmt->prepare("SELECT * FROM test");
36-
// Invalid Attribute (2nd argument)
37-
try {
38-
mysqli_stmt_attr_set($stmt, -1, 0);
39-
} catch (\ValueError $e) {
40-
echo $e->getMessage() . \PHP_EOL;
36+
37+
mt_srand(microtime(true));
38+
39+
for ($i = -100; $i < 1000; $i++) {
40+
if (in_array($i, $valid_attr))
41+
continue;
42+
$invalid_attr = $i;
43+
try {
44+
if (false !== ($tmp = mysqli_stmt_attr_set($stmt, $invalid_attr, 0))) {
45+
printf("[006a] Expecting boolean/false for attribute %d, got %s/%s\n", $invalid_attr, gettype($tmp), $tmp);
46+
}
47+
} catch (\ValueError $e) {/* Suppress because RANDOM */}
48+
}
49+
50+
for ($i = 0; $i < 2; $i++) {
51+
do {
52+
$invalid_attr = mt_rand(-1 * (min(4294967296, PHP_INT_MAX) + 1), min(4294967296, PHP_INT_MAX));
53+
} while (in_array($invalid_attr, $valid_attr));
54+
try {
55+
if (false !== ($tmp = mysqli_stmt_attr_set($stmt, $invalid_attr, 0))) {
56+
printf("[006b] Expecting boolean/false for attribute %d, got %s/%s\n", $invalid_attr, gettype($tmp), $tmp);
57+
}
58+
} catch (\ValueError $e) {/* Suppress because RANDOM */}
4159
}
4260
// Invalid mode for MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH
4361
try {
@@ -117,9 +135,13 @@ require_once("connect.inc");
117135
$stmt = mysqli_stmt_init($link);
118136
$stmt->prepare("SELECT id, label FROM test");
119137

120-
// Invalid cursor type
121138
try {
122-
$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, -1);
139+
$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, -100);
140+
} catch (\ValueError $e) {
141+
echo $e->getMessage() . \PHP_EOL;
142+
}
143+
try {
144+
$stmt->attr_set(MYSQLI_STMT_ATTR_CURSOR_TYPE, 200);
123145
} catch (\ValueError $e) {
124146
echo $e->getMessage() . \PHP_EOL;
125147
}
@@ -195,13 +217,6 @@ require_once("connect.inc");
195217

196218
$stmt = mysqli_stmt_init($link);
197219
$stmt->prepare("SELECT id, label FROM test");
198-
// Invalid prefetch value
199-
try {
200-
$stmt->attr_set(MYSQLI_STMT_ATTR_PREFETCH_ROWS, 0);
201-
} catch (\ValueError $e) {
202-
echo $e->getMessage() . \PHP_EOL;
203-
}
204-
205220
if (true !== ($tmp = $stmt->attr_set(MYSQLI_STMT_ATTR_PREFETCH_ROWS, 1)))
206221
printf("[020] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
207222
$stmt->execute();
@@ -256,9 +271,7 @@ require_once("connect.inc");
256271
?>
257272
--EXPECT--
258273
Error: mysqli_stmt object is not fully initialized
259-
mysqli_stmt_attr_set(): Argument #2 ($attr) must be one of MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, MYSQLI_STMT_ATTR_PREFETCH_ROWS, or STMT_ATTR_CURSOR_TYPE
260274
mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be greater than or equal to 0
261275
bool(true)
262276
mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be greater than or equal to 0
263-
mysqli_stmt::attr_set(): Argument #2 ($mode_in) must be greater than 0 for attribute MYSQLI_STMT_ATTR_PREFETCH_ROWS
264277
done!

0 commit comments

Comments
 (0)