Skip to content

Commit 9b0104d

Browse files
authored
Merge pull request #156 from samwilson/latlong-size-GH153
Alter osm_places table column to fit 3 digit latitudes
2 parents 391c6bc + a6ec950 commit 9b0104d

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

maintain.inc.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,31 @@ function plugin_install()
128128
$q = 'CREATE TABLE IF NOT EXISTS `'.osm_place_table.'` (
129129
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
130130
`latitude` double(8,6) NOT NULL,
131-
`longitude` double(8,6) NOT NULL,
131+
`longitude` double(9,6) NOT NULL,
132132
`name` varchar(255) DEFAULT NULL,
133133
`parentId` mediumint(8),
134134
PRIMARY KEY (id)
135135
) ENGINE=MyISAM DEFAULT CHARSET=utf8
136136
;';
137137
pwg_query($q);
138138

139+
// Increase size of longitude column from double(8,6) to double(9,6). GH#153.
140+
foreach(pwg_query('DESCRIBE '.osm_place_table) as $col_info)
141+
{
142+
$is_longitude = isset($col_info['Field'])
143+
&& $col_info['Field'] === 'longitude';
144+
$is_old_size = isset($col_info['Type'])
145+
&& $col_info['Type'] === 'double(8,6)';
146+
if ($is_longitude && $is_old_size)
147+
{
148+
$alter_longitude = 'ALTER TABLE `'.osm_place_table.'`'
149+
.' CHANGE `longitude` `longitude` double(9,6) NOT NULL';
150+
pwg_query($alter_longitude);
151+
// This is the only column to change, so we can leave the loop now.
152+
break;
153+
}
154+
}
155+
139156
// Create world map link
140157
$dir_name = basename( dirname(__FILE__) );
141158
$c = <<<EOF

0 commit comments

Comments
 (0)