简体   繁体   English

当我尝试在MariaDB数据库上创建此功能(使用点数据类型)时,为什么会出现此错误?

[英]Why I obtain this error when I try to create this funcion (that use point data type) on a MariaDB database?

I am not so into database and I have the following doubt implementing this tutorial: https://mariadb.org/jquery-and-gis-distance-in-mariadb/ 我不太喜欢数据库,在实现本教程时有以下疑问: https : //mariadb.org/jquery-and-gis-distance-in-mariadb/

So basically my doubt is relate to this SQL statment that create a function to calculate the distance between two point on a MariaDB database: 所以基本上我的疑问是涉及到创建一个函数来计算MariaDB的数据库上的两个之间的距离,这样SQL statment:

CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
    DETERMINISTIC
begin
  declare lon1, lon2 double;
  declare lat1, lat2 double;
  declare td double;
  declare d_lat double;
  declare d_lon double;
  declare a, c, R double;

  set lon1 = X(GeomFromText(AsText(point1)));
  set lon2 = X(GeomFromText(AsText(point2)));
  set lat1 = Y(GeomFromText(AsText(point1)));
  set lat2 = Y(GeomFromText(AsText(point2)));

  set d_lat = radians(lat2 - lat1);
  set d_lon = radians(lon2 - lon1);

  set lat1 = radians(lat1);
  set lat2 = radians(lat2);

  set R = 6372.8; -- in kilometers

  set a = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat1) * cos(lat2);
  set c = 2 * asin(sqrt(a));

  return R * c;
end

My problem is that performing the previous statment I obtain the following error message: 我的问题是,执行前一个语句会得到以下错误消息:

Error
----------------------------------------------------
Static analysis:

2 errors were found during analysis.
    1. Unrecognized data type. (near "point" at position 45)
    2. Unrecognized data type. (near "point" at position 59)

SQL query:

CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double DETERMINISTIC begin declare lon1, lon2 double 

MySQL said: 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 4

PhpMyAdmin sign with 2 red marker the point data type on the first line of the previous statment: 用2个红色标记标记的PhpMyAdmin符号在上一条语句的第一行上显示数据类型:

CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double

but I don't think that it could be the real problem (I think that maybe is something that PhpMyAdmin don't know) because it mark red also this cration query: 但我不认为它可能是真正的问题(我想,也许是一些phpMyAdmin的不知道),因为它标志着红也是这个cration查询:

CREATE TABLE gis_point  (g POINT);

but it works fine, give me no error and correctly create the table. 但它工作正常,没有错误,并正确创建了表。

So, whta is wrong? 那么,错了吗? Could depend by PhpMyAdmin or what am I missing? 可以依靠PhpMyAdmin还是我缺少什么? Where this function should be stored? 此功能应存储在哪里?

Change the delimiter. 更改定界符。 Otherwise the function definition ends at the first ; 否则,函数定义在第一个处结束; which would make it incomplete. 这将使其不完整。

delimiter ||
CREATE FUNCTION earth_circle_distance(point1 point, point2 point) RETURNS double
    DETERMINISTIC
begin
  declare lon1, lon2 double;
  declare lat1, lat2 double;
  declare td double;
  declare d_lat double;
  declare d_lon double;
  declare a, c, R double;

  set lon1 = X(GeomFromText(AsText(point1)));
  set lon2 = X(GeomFromText(AsText(point2)));
  set lat1 = Y(GeomFromText(AsText(point1)));
  set lat2 = Y(GeomFromText(AsText(point2)));

  set d_lat = radians(lat2 - lat1);
  set d_lon = radians(lon2 - lon1);

  set lat1 = radians(lat1);
  set lat2 = radians(lat2);

  set R = 6372.8; -- in kilometers

  set a = sin(d_lat / 2.0) * sin(d_lat / 2.0) + sin(d_lon / 2.0) * sin(d_lon / 2.0) * cos(lat1) * cos(lat2);
  set c = 2 * asin(sqrt(a));

  return R * c;
end
||

delimiter ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在MariaDB上创建表时为什么会收到此错误? “无法获取MyMariaDB的列:未知的系统变量'OPTION'” - Why I obtain this error when I create a table on MariaDB? “Could not getColumn for MyMariaDB: Unknown system variable 'OPTION'” 当我尝试使用 FOR UPDATE NOWAIT 时 MariaDB 抛出错误 - MariaDB throws an error when I try to use FOR UPDATE NOWAIT 尝试创建此表时为什么会出现此FK错误? errno:150“外键约束格式不正确 - Why I obtain this FK error when I try to create this table? errno: 150 "Foreign key constraint is incorrectly formed 尝试创建关系时出错:外键约束的格式不正确 - MariaDB - Error when i try to create a ralationship: Foreign key constraint is incorrectly formed - MariaDB 当我尝试创建MySQL数据库时,为什么我的权限被拒绝? - Why is my permission denied when I try to create a MySQL database? 当我尝试在多对多关联表上设置2个外键时,为什么会收到此错误消息? “外键约束的格式不正确” - Why I obtain this error message when I try to set 2 foreign keys on a many to many association table? “Foreign key constraint is incorrectly formed” 当我尝试创建触发器时出错 - Error when i try to create a trigger 当我尝试使用 UPDATE 更新我的数据库时,我不断收到错误消息 - I keep getting an error when i try to use UPDATE to update my database 为什么当我尝试使用 Perl 的 DBD::mysql 时出现错误? - Why do I get an error when I try to use Perl's DBD::mysql? 为什么我在 MySQL 数据库中创建表时总是出现这个错误? - Why always this error occured when I create table in MySQL database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM