# Copyright(C) 2011-2016 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_geometry.inc
--source ../../../include/mroonga/have_mariadb.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)
);

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;

EXPLAIN
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
