Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this a MySQLi bug? Returned fields are truncated to 8193 bytes under certain circumstances
    primarykey
    data
    text
    <p>When I SELECT a Geometry column with <code>AsText()</code>, the returned value is truncated to 8193 bytes. </p> <p>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? </p> <p>Chances are I either I'm Doing It Wrong, or there is a setting I don't know about.</p> <p>All test cases below except the first truncate the <code>geom</code> field to 8193 bytes. I'm pulling my hair out trying to determine the cause of this.</p> <p>PHP Version: <code>PHP 5.3.3-7 with Suhosin-Patch (cli) (built: Jan 5 2011 12:52:48)</code> MySQL Version: <code>mysql Ver 14.12 Distrib 5.0.32, for pc-linux-gnu (i486) using readline 5.2</code></p> <pre class="lang-php prettyprint-override"><code>&lt;?php $con = new mysqli(HOST, USER, PASS, DB); $con-&gt;query("DROP TABLE IF EXISTS `mytable`"); $con-&gt;query("CREATE TABLE `mytable` (`text` TEXT , `geom` GEOMETRY)"); for ($i = 0; $i &lt; 1300; ++$i) { $points[] = "$i $i"; } $wkt = "LINESTRING(" . implode(',', $points) . ")"; $con-&gt;query("INSERT INTO `mytable` (`text`,`geom`) VALUES ('$wkt', GeomFromText('$wkt'))"); /* CASE #1 */ echo "With store_result(), no string function on `text`:\n"; $stmt = $con-&gt;prepare('SELECT `text`, ASTEXT(`geom`) FROM `mytable`'); $stmt-&gt;execute(); $stmt-&gt;store_result(); $stmt-&gt;bind_result($text, $geom); $stmt-&gt;fetch(); $stmt-&gt;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-&gt;prepare('SELECT LEFT(`text`,10791), ASTEXT(`geom`) FROM `mytable`'); $stmt-&gt;execute(); $stmt-&gt;store_result(); $stmt-&gt;bind_result($text, $geom); $stmt-&gt;fetch(); $stmt-&gt;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-&gt;prepare('SELECT ASTEXT(`geom`) FROM `mytable`'); $stmt-&gt;execute(); $stmt-&gt;store_result(); $stmt-&gt;bind_result($geom); $stmt-&gt;fetch(); $stmt-&gt;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-&gt;prepare( 'SELECT `text`, ASTEXT(`geom`) FROM `mytable`'); $stmt-&gt;execute(); $stmt-&gt;bind_result($text, $geom); $stmt-&gt;fetch(); $stmt-&gt;close(); echo " Text is ".strlen($text)." bytes, Geom is ".strlen($geom)." bytes\n"; ?&gt; </code></pre> <p>Expected Result:</p> <pre><code>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 </code></pre> <p>Here is my actual result when running the above:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload