When I SELECT a Geometry column with AsText(), the returned value is truncated to 8193 bytes.
This looks like a bug to me, but I’d like to post here first to see if I’m missing anything with the way prepared statements work under MySQLi. Are there any settings I’m overlooking here?
Chances are I either I’m Doing It Wrong, or there is a setting I don’t know about.
All test cases below except the first truncate the geom field to 8193 bytes. I’m pulling my hair out trying to determine the cause of this.
PHP Version: PHP 5.3.3-7 with Suhosin-Patch (cli) (built: Jan 5 2011 12:52:48)
MySQL Version: mysql Ver 14.12 Distrib 5.0.32, for pc-linux-gnu (i486) using readline 5.2
<?php
$con = new mysqli(HOST, USER, PASS, DB);
$con->query("DROP TABLE IF EXISTS `mytable`");
$con->query("CREATE TABLE `mytable` (`text` TEXT , `geom` GEOMETRY)");
for ($i = 0; $i < 1300; ++$i) {
$points[] = "$i $i";
}
$wkt = "LINESTRING(" . implode(',', $points) . ")";
$con->query("INSERT INTO `mytable` (`text`,`geom`) VALUES ('$wkt', GeomFromText('$wkt'))");
/* CASE #1 */
echo "With store_result(), no string function on `text`:\n";
$stmt = $con->prepare('SELECT `text`, ASTEXT(`geom`) FROM `mytable`');
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($text, $geom);
$stmt->fetch();
$stmt->close();
echo " Text is ".strlen($text)." bytes, Geom is ".strlen($geom)." bytes\n";
unset($text);
unset($geom);
/* CASE #2 */
echo "With store_result(), left(`text`,10791):\n";
$stmt = $con->prepare('SELECT LEFT(`text`,10791), ASTEXT(`geom`) FROM `mytable`');
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($text, $geom);
$stmt->fetch();
$stmt->close();
echo " Text is ".strlen($text)." bytes, Geom is ".strlen($geom)." bytes\n";
unset($text);
unset($geom);
/* CASE #3 */
echo "With store_result(), only the `geom` column:\n";
$stmt = $con->prepare('SELECT ASTEXT(`geom`) FROM `mytable`');
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($geom);
$stmt->fetch();
$stmt->close();
echo " Text is ".@strlen($text)." bytes, Geom is ".strlen($geom)." bytes\n";
unset($text);
unset($geom);
/* CASE #4 */
echo "Without store_result(), no string function on `text`:\n";
$stmt = $con->prepare( 'SELECT `text`, ASTEXT(`geom`) FROM `mytable`');
$stmt->execute();
$stmt->bind_result($text, $geom);
$stmt->fetch();
$stmt->close();
echo " Text is ".strlen($text)." bytes, Geom is ".strlen($geom)." bytes\n";
?>
Expected Result:
With store_result(), no string function on `text`:
Text is 10791 bytes, Geom is 10791 bytes
With store_result(), left(`text`,10791):
Text is 10791 bytes, Geom is 10791 bytes
With store_result(), only the `geom` column:
Text is 0 bytes, Geom is 10791 bytes
Without store_result(), no string function on `text`:
Text is 10791 bytes, Geom is 10791 bytes
Here is my actual result when running the above:
With store_result(), no string function on `text`:
Text is 10791 bytes, Geom is 10791 bytes
With store_result(), left(`text`,10791):
Text is 10791 bytes, Geom is 8193 bytes
With store_result(), only the `geom` column:
Text is 0 bytes, Geom is 8193 bytes
Without store_result(), no string function on `text`:
Text is 10791 bytes, Geom is 8193 bytes
This issue went away when PHP was upgraded to 5.3.8.