Fix spatial functions
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
parent
9ed068aacb
commit
3399e5babd
@ -420,7 +420,7 @@ echo '<div id="gis_data_output">';
|
||||
echo '<h3>' , __('Output') , '</h3>';
|
||||
echo '<p>';
|
||||
echo __(
|
||||
'Choose "GeomFromText" from the "Function" column and paste the'
|
||||
'Choose "ST_GeomFromText" from the "Function" column and paste the'
|
||||
. ' string below into the "Value" field.'
|
||||
);
|
||||
echo '</p>';
|
||||
|
||||
@ -1025,7 +1025,7 @@ class TableSearchController extends TableController
|
||||
return $where;
|
||||
} elseif ($geom_funcs[$geom_func]['params'] > 1) {
|
||||
// create gis data from the criteria input
|
||||
$gis_data = Util::createGISData($criteriaValues);
|
||||
$gis_data = Util::createGISData($criteriaValues, $this->dbi->getVersion());
|
||||
$where = $geom_func . '(' . Util::backquote($names)
|
||||
. ', ' . $gis_data . ')';
|
||||
return $where;
|
||||
@ -1046,7 +1046,7 @@ class TableSearchController extends TableController
|
||||
&& ! empty($criteriaValues)
|
||||
) {
|
||||
// create gis data from the criteria input
|
||||
$gis_data = Util::createGISData($criteriaValues);
|
||||
$gis_data = Util::createGISData($criteriaValues, $this->dbi->getVersion());
|
||||
$where = $geom_function_applied . " " . $func_type . " " . $gis_data;
|
||||
|
||||
} elseif (strlen($criteriaValues) > 0) {
|
||||
|
||||
@ -596,27 +596,50 @@ class Types
|
||||
return $ret;
|
||||
|
||||
case 'SPATIAL':
|
||||
return array(
|
||||
'GeomFromText',
|
||||
'GeomFromWKB',
|
||||
if ($serverVersion >= 50600) {
|
||||
return array(
|
||||
'ST_GeomFromText',
|
||||
'ST_GeomFromWKB',
|
||||
|
||||
'GeomCollFromText',
|
||||
'LineFromText',
|
||||
'MLineFromText',
|
||||
'PointFromText',
|
||||
'MPointFromText',
|
||||
'PolyFromText',
|
||||
'MPolyFromText',
|
||||
'ST_GeomCollFromText',
|
||||
'ST_LineFromText',
|
||||
'ST_MLineFromText',
|
||||
'ST_PointFromText',
|
||||
'ST_MPointFromText',
|
||||
'ST_PolyFromText',
|
||||
'ST_MPolyFromText',
|
||||
|
||||
'GeomCollFromWKB',
|
||||
'LineFromWKB',
|
||||
'MLineFromWKB',
|
||||
'PointFromWKB',
|
||||
'MPointFromWKB',
|
||||
'PolyFromWKB',
|
||||
'MPolyFromWKB',
|
||||
);
|
||||
'ST_GeomCollFromWKB',
|
||||
'ST_LineFromWKB',
|
||||
'ST_MLineFromWKB',
|
||||
'ST_PointFromWKB',
|
||||
'ST_MPointFromWKB',
|
||||
'ST_PolyFromWKB',
|
||||
'ST_MPolyFromWKB',
|
||||
);
|
||||
} else {
|
||||
return array(
|
||||
'GeomFromText',
|
||||
'GeomFromWKB',
|
||||
|
||||
'GeomCollFromText',
|
||||
'LineFromText',
|
||||
'MLineFromText',
|
||||
'PointFromText',
|
||||
'MPointFromText',
|
||||
'PolyFromText',
|
||||
'MPolyFromText',
|
||||
|
||||
'GeomCollFromWKB',
|
||||
'LineFromWKB',
|
||||
'MLineFromWKB',
|
||||
'PointFromWKB',
|
||||
'MPointFromWKB',
|
||||
'PolyFromWKB',
|
||||
'MPolyFromWKB',
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
@ -3482,18 +3482,20 @@ class Util
|
||||
* Generates GIS data based on the string passed.
|
||||
*
|
||||
* @param string $gis_string GIS string
|
||||
* @param int $mysqlVersion The mysql version as int
|
||||
*
|
||||
* @return string GIS data enclosed in 'GeomFromText' function
|
||||
* @return string GIS data enclosed in 'ST_GeomFromText' or 'GeomFromText' function
|
||||
*/
|
||||
public static function createGISData($gis_string)
|
||||
public static function createGISData($gis_string, $mysqlVersion)
|
||||
{
|
||||
$geomFromText = ($mysqlVersion >= 50600) ? 'ST_GeomFromText' : 'GeomFromText';
|
||||
$gis_string = trim($gis_string);
|
||||
$geom_types = '(POINT|MULTIPOINT|LINESTRING|MULTILINESTRING|'
|
||||
. 'POLYGON|MULTIPOLYGON|GEOMETRYCOLLECTION)';
|
||||
if (preg_match("/^'" . $geom_types . "\(.*\)',[0-9]*$/i", $gis_string)) {
|
||||
return 'GeomFromText(' . $gis_string . ')';
|
||||
return $geomFromText . '(' . $gis_string . ')';
|
||||
} elseif (preg_match("/^" . $geom_types . "\(.*\)$/i", $gis_string)) {
|
||||
return "GeomFromText('" . $gis_string . "')";
|
||||
return $geomFromText . "('" . $gis_string . "')";
|
||||
}
|
||||
|
||||
return $gis_string;
|
||||
|
||||
@ -121,6 +121,19 @@ $gis_from_text_functions = array(
|
||||
'MPolyFromText',
|
||||
);
|
||||
|
||||
if ($GLOBALS['dbi']->getVersion() >= 50600) {
|
||||
$gis_from_text_functions = array(
|
||||
'ST_GeomFromText',
|
||||
'ST_GeomCollFromText',
|
||||
'ST_LineFromText',
|
||||
'ST_MLineFromText',
|
||||
'ST_PointFromText',
|
||||
'ST_MPointFromText',
|
||||
'ST_PolyFromText',
|
||||
'ST_MPolyFromText',
|
||||
);
|
||||
}
|
||||
|
||||
$gis_from_wkb_functions = array(
|
||||
'GeomFromWKB',
|
||||
'GeomCollFromWKB',
|
||||
|
||||
@ -423,24 +423,24 @@ class TypesTest extends PmaTestCase
|
||||
array(
|
||||
'SPATIAL',
|
||||
array(
|
||||
'GeomFromText',
|
||||
'GeomFromWKB',
|
||||
'ST_GeomFromText',
|
||||
'ST_GeomFromWKB',
|
||||
|
||||
'GeomCollFromText',
|
||||
'LineFromText',
|
||||
'MLineFromText',
|
||||
'PointFromText',
|
||||
'MPointFromText',
|
||||
'PolyFromText',
|
||||
'MPolyFromText',
|
||||
'ST_GeomCollFromText',
|
||||
'ST_LineFromText',
|
||||
'ST_MLineFromText',
|
||||
'ST_PointFromText',
|
||||
'ST_MPointFromText',
|
||||
'ST_PolyFromText',
|
||||
'ST_MPolyFromText',
|
||||
|
||||
'GeomCollFromWKB',
|
||||
'LineFromWKB',
|
||||
'MLineFromWKB',
|
||||
'PointFromWKB',
|
||||
'MPointFromWKB',
|
||||
'PolyFromWKB',
|
||||
'MPolyFromWKB',
|
||||
'ST_GeomCollFromWKB',
|
||||
'ST_LineFromWKB',
|
||||
'ST_MLineFromWKB',
|
||||
'ST_PointFromWKB',
|
||||
'ST_MPointFromWKB',
|
||||
'ST_PolyFromWKB',
|
||||
'ST_MPolyFromWKB',
|
||||
)
|
||||
),
|
||||
array(
|
||||
|
||||
@ -27,15 +27,32 @@ class UtilTest extends PmaTestCase
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateGISData()
|
||||
public function testCreateGISDataOldMysql()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"abc",
|
||||
Util::createGISData("abc")
|
||||
Util::createGISData("abc", 50500)
|
||||
);
|
||||
$this->assertEquals(
|
||||
"GeomFromText('POINT()',10)",
|
||||
Util::createGISData("'POINT()',10")
|
||||
Util::createGISData("'POINT()',10", 50500)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for createGISData
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testCreateGISDataNewMysql()
|
||||
{
|
||||
$this->assertEquals(
|
||||
"abc",
|
||||
Util::createGISData("abc", 50600)
|
||||
);
|
||||
$this->assertEquals(
|
||||
"ST_GeomFromText('POINT()',10)",
|
||||
Util::createGISData("'POINT()',10", 50600)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user