Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 13 — I Need to Get To... 269


my @pointlist = split(/,/,$points);
my $routeid;

if (defined(param(‘routeid’)) && param(‘routeid’) != 0)
{
$routeid = param(‘routeid’);

$dbh->do(sprintf(‘update ch13_routesimple set title=%s, ‘.
‘description=%s where routeid=%s’,
$dbh->quote($title),
$dbh->quote($description),
$routeid));
$dbh->do(sprintf(‘delete from ch13_routepoints where routeid=%s’,
$routeid));
}
else
{
$dbh->do(sprintf(‘insert into ch13_routesimple values(0,%s,%s)’,
$dbh->quote($title),
$dbh->quote($description)));
$routeid = $dbh->{mysql_insertid};
}

foreach my $point (@pointlist)
{
my ($seqid,$x,$y) = split(/:/,$point);
$dbh->do(sprintf(‘insert into ch13_routepoints values(%s,%s,%s,%s)’,
$dbh->quote($routeid),
$dbh->quote($x),
$dbh->quote($y),
$dbh->quote($seqid)));
}
xmlmessage(‘Route added’,{routeid => $routeid});
}


Once the route has been added or updated in the database, the function returns a simple mes-
sage and the route ID of the route that was added or updated.


Deleting an Existing Route


To delete an existing route you need only execute the delete statement for the supplied route
ID on each table:


sub delroute
{
my ($routeid) = @_;


$dbh->do(sprintf(‘delete from ch13_routesimple where routeid=%s’,
$routeid));
$dbh->do(sprintf(‘delete from ch13_routepoints where routeid=%s’,
$routeid));

xmlmessage(‘Route deleted’);
}

Free download pdf