我想獲得使用DBIx :: Class的周界搜索,但到目前爲止還沒有成功。DBIx ::類外圍搜索
我想產生這樣看起來SQL:
SELECT
zip,
6371 * ACos(Cos(RADIANS(Lat)) * Cos(RADIANS(USERLAT)) * Cos(RADIANS(USERLNG) - RADIANS(Lng)) + Sin(RADIANS(Lat)) * Sin(RADIANS(USERLAT))) AS Distance
FROM
geopc
WHERE
6371 * ACos(Cos(RADIANS(Lat)) * Cos(RADIANS(USERLAT)) * Cos(RADIANS(USERLNG) - RADIANS(Lng)) + Sin(RADIANS(Lat)) * Sin(RADIANS(USERLAT))) <= DISTANCE
ORDER BY
Distance
凡USERLAT,USERLNG和距離應變量,這會在一個直通的WebRequest。
我DBIx ::類結果:
use utf8;
package MyApp::Models::Schema::Result::Geopc;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table("geopc");
__PACKAGE__->add_columns(
"id",
{ data_type => "bigint", is_nullable => 0, is_auto_increment => 1 },
"country",
{ data_type => "varchar", is_nullable => 0, size => 2 },
"language",
{ data_type => "varchar", is_nullable => 0, size => 2 },
"iso2",
{ data_type => "varchar", is_nullable => 0, size => 6 },
"region1",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"region2",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"region3",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"region4",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"zip",
{ data_type => "varchar", is_nullable => 0, size => 10 },
"city",
{ data_type => "varchar", is_nullable => 0, size => 60 },
"area1",
{ data_type => "varchar", is_nullable => 0, size => 80 },
"area2",
{ data_type => "varchar", is_nullable => 0, size => 80 },
"lat",
{ data_type => "double precision", is_nullable => 0 },
"lng",
{ data_type => "double precision", is_nullable => 0 },
"tz",
{ data_type => "varchar", is_nullable => 0, size => 30 },
"utc",
{ data_type => "varchar", is_nullable => 0, size => 10 },
"dst",
{ data_type => "varchar", is_nullable => 0, size => 1 },
);
__PACKAGE__->set_primary_key('id');
我身邊有GOOGLE上搜索,但沒有發現來處理這一個很好的方式。任何幫助將非常感激。
我使用MySQL的...對於這樣複雜的查詢
個人而言,我會爲此使用存儲過程。您不能在select中將參數綁定到函數arg。 – jordanm 2013-03-12 22:56:16
你應該可以通過子查詢和未記錄的'from' ResultSet屬性來做到這一點。我可以看看這是否明天有效。 – nwellnhof 2013-03-13 00:34:59