# Copyright(C) 2011 Kouhei Sutou <kou@clear-code.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

--source ../../../include/mroonga/have_mariadb.inc
--source ../../../include/mroonga/have_innodb.inc
--source ../../../include/mroonga/have_geometry.inc
--source ../../../include/mroonga/have_mroonga.inc

--disable_warnings
drop table if exists shops;
--enable_warnings

create table shops (
  id int primary key auto_increment,
  name text,
  location geometry NOT NULL,
  spatial key location_index (location)
) comment = 'engine "innodb"';
insert into shops (name, location)
           values ('nezu-no-taiyaki',
                   ST_GeomFromText('POINT(35.720253 139.762573)'));
insert into shops (name, location)
           values ('taiyaki-kataoka',
                   ST_GeomFromText('POINT(35.712521 139.715591)'));
insert into shops (name, location)
           values ('soba-taiyaki-ku',
                   ST_GeomFromText('POINT(35.683712 139.659088)'));
insert into shops (name, location)
           values ('kuruma',
                   ST_GeomFromText('POINT(35.721516 139.706207)'));
insert into shops (name, location)
           values ('hirose-ya',
                   ST_GeomFromText('POINT(35.714844 139.685608)'));
insert into shops (name, location)
           values ('sazare',
                   ST_GeomFromText('POINT(35.714653 139.685043)'));
insert into shops (name, location)
           values ('omede-taiyaki',
                   ST_GeomFromText('POINT(35.700516 139.817154)'));
insert into shops (name, location)
           values ('onaga-ya',
                   ST_GeomFromText('POINT(35.698254 139.81105)'));
insert into shops (name, location)
           values ('shiro-ya',
                   ST_GeomFromText('POINT(35.705517 139.638611)'));
insert into shops (name, location)
           values ('fuji-ya',
                   ST_GeomFromText('POINT(35.703938 139.637115)'));
insert into shops (name, location)
           values ('miyoshi',
                   ST_GeomFromText('POINT(35.644539 139.537323)'));
insert into shops (name, location)
           values ('juju-ya',
                   ST_GeomFromText('POINT(35.628922 139.695755)'));
insert into shops (name, location)
           values ('tatsumi-ya',
                   ST_GeomFromText('POINT(35.665501 139.638657)'));
insert into shops (name, location)
           values ('tetsuji',
                   ST_GeomFromText('POINT(35.680912 139.76857)'));
insert into shops (name, location)
           values ('gazuma-ya',
                   ST_GeomFromText('POINT(35.700817 139.647598)'));
insert into shops (name, location)
           values ('honma-mon',
                   ST_GeomFromText('POINT(35.722736 139.652573)'));
insert into shops (name, location)
           values ('naniwa-ya',
                   ST_GeomFromText('POINT(35.730061 139.796234)'));
insert into shops (name, location)
           values ('kuro-dai',
                   ST_GeomFromText('POINT(35.650345 139.704834)'));
insert into shops (name, location)
           values ('daruma',
                   ST_GeomFromText('POINT(35.681461 139.770599)'));
insert into shops (name, location)
           values ('yanagi-ya',
                   ST_GeomFromText('POINT(35.685341 139.783981)'));
insert into shops (name, location)
           values ('sharaku',
                   ST_GeomFromText('POINT(35.716969 139.794846)'));
insert into shops (name, location)
           values ('takane',
                   ST_GeomFromText('POINT(35.698601 139.560913)'));
insert into shops (name, location)
           values ('chiyoda',
                   ST_GeomFromText('POINT(35.642601 139.652817)'));
insert into shops (name, location)
           values ('da-ka-po',
                   ST_GeomFromText('POINT(35.627346 139.727356)'));
insert into shops (name, location)
           values ('matsushima-ya',
                   ST_GeomFromText('POINT(35.640556 139.737381)'));
insert into shops (name, location)
           values ('kazuya',
                   ST_GeomFromText('POINT(35.673508 139.760895)'));
insert into shops (name, location)
           values ('furuya-kogane-an',
                   ST_GeomFromText('POINT(35.680603 139.676071)'));
insert into shops (name, location)
           values ('hachi-no-ie',
                   ST_GeomFromText('POINT(35.608021 139.668106)'));
insert into shops (name, location)
           values ('azuki-chan',
                   ST_GeomFromText('POINT(35.64151 139.673203)'));
insert into shops (name, location)
           values ('kuriko-an',
                   ST_GeomFromText('POINT(35.712013 139.796829)'));
insert into shops (name, location)
           values ('yume-no-aru-machi-no-taiyaki-ya-san',
                   ST_GeomFromText('POINT(35.616199 139.712524)'));
insert into shops (name, location)
           values ('naze-ya',
                   ST_GeomFromText('POINT(35.609039 139.665833)'));
insert into shops (name, location)
           values ('sanoki-ya',
                   ST_GeomFromText('POINT(35.66592 139.770721)'));
insert into shops (name, location)
           values ('shigeta',
                   ST_GeomFromText('POINT(35.672626 139.780273)'));
insert into shops (name, location)
           values ('nishimi-ya',
                   ST_GeomFromText('POINT(35.671825 139.774628)'));
insert into shops (name, location)
           values ('hiiragi',
                   ST_GeomFromText('POINT(35.647701 139.711517)'));
select id, name, ST_AsText(location) as location_text from shops;
select id, name, ST_AsText(location) as location_text from shops
  where MBRContains(ST_GeomFromText('LineString(35.6684 139.7727, 35.7121 139.7038)'), location)
  order by id;
drop table shops;

--source ../../../include/mroonga/have_mroonga_deinit.inc
