diff options
author | Ulf Wendel <uw@php.net> | 2009-09-11 13:38:47 +0000 |
---|---|---|
committer | Ulf Wendel <uw@php.net> | 2009-09-11 13:38:47 +0000 |
commit | 30a6d1b85137f7159169eaae6ffb20292dcc4a87 (patch) | |
tree | cf81894a41ea8b7c4eee33c42520856bf29a76a8 | |
parent | a69c19879090afb7f58008c5ca3d95bab1f81fdf (diff) | |
download | php-git-30a6d1b85137f7159169eaae6ffb20292dcc4a87.tar.gz |
Fix for bug #49357 (MySQLi extension fails to recognize POINT (spatial) colums).
Do yourself a favour and use mysqlnd. mysqlnd has no isuses here.
If you insist on using the MySQL Client Library (libmysql) I strongly recommend to use mysqli_stmt_store_result() when fetching geometry data using prepared statements. When streaming data, which is the default for prepared statements, ext/mysqli will have to make a guess on the size of the result buffer it needs. The guess is based on a length reported by the MySQL CLient Library (libmysql). The MySQL Client Library reports 4GB (!) for a POINT - a conservative and safe guess. Consequently, ext/mysqli will try to allocate 4GB of RAM. The true (maximum) size of the column is not available before buffering the result on the client using mysqli_stmt_store_result(). If you call mysqli_stmt_store_result(), the result buffers will not get bigger than needed. However, store_result()/buffering is usually not what you want when you ask for prepared statements.
-rw-r--r-- | ext/mysqli/mysqli_api.c | 4 | ||||
-rw-r--r-- | ext/mysqli/tests/mysqli_stmt_fetch_geom.phpt | 4 |
2 files changed, 5 insertions, 3 deletions
diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index 7d367e670c..72301d3fa9 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -370,6 +370,7 @@ mysqli_stmt_bind_result_do_bind(MY_STMT *stmt, zval ***args, unsigned int argc, case MYSQL_TYPE_LONG_BLOB: case MYSQL_TYPE_TIMESTAMP: case MYSQL_TYPE_DECIMAL: + case MYSQL_TYPE_GEOMETRY: #ifdef FIELD_TYPE_NEWDECIMAL case MYSQL_TYPE_NEWDECIMAL: #endif @@ -2346,7 +2347,8 @@ PHP_FUNCTION(mysqli_stmt_store_result) for (i = mysql_stmt_field_count(stmt->stmt) - 1; i >=0; --i) { if (stmt->stmt->fields && (stmt->stmt->fields[i].type == MYSQL_TYPE_BLOB || stmt->stmt->fields[i].type == MYSQL_TYPE_MEDIUM_BLOB || - stmt->stmt->fields[i].type == MYSQL_TYPE_LONG_BLOB)) + stmt->stmt->fields[i].type == MYSQL_TYPE_LONG_BLOB || + stmt->stmt->fields[i].type == MYSQL_TYPE_GEOMETRY)) { my_bool tmp=1; mysql_stmt_attr_set(stmt->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &tmp); diff --git a/ext/mysqli/tests/mysqli_stmt_fetch_geom.phpt b/ext/mysqli/tests/mysqli_stmt_fetch_geom.phpt index 7d7ef79f30..fc9cc64a7f 100644 --- a/ext/mysqli/tests/mysqli_stmt_fetch_geom.phpt +++ b/ext/mysqli/tests/mysqli_stmt_fetch_geom.phpt @@ -45,7 +45,7 @@ mysqli_stmt_fetch - geometry / spatial types return false; } - if (!mysqli_stmt_execute($stmt)) { + if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_store_result($stmt)) { printf("[%04d] [%d] %s\n", $offset + 8, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); mysqli_stmt_close($stmt); return false; @@ -65,7 +65,7 @@ mysqli_stmt_fetch - geometry / spatial types $num = 0; $rows = array(); - while (true === mysqli_stmt_fetch($stmt)) { + while (true === @mysqli_stmt_fetch($stmt)) { $rows[] = array('id' => $id, 'label' => $bind_res); $num++; } |