X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~yarrgweb/git?p=ypp-sc-tools.db-test.git;a=blobdiff_plain;f=yarrg%2Fweb%2Fcheck_routestring;h=6741eaedec9db07656b66a55e6051992b6219961;hp=2cbe719cf4eec1afa16860f947da2b5044ee1490;hb=aecbbcbe68e6f59fe9319f307ac49f4e616cc351;hpb=3766fb8d851fe463a5b8b469cf148c28efb1c578 diff --git a/yarrg/web/check_routestring b/yarrg/web/check_routestring old mode 100755 new mode 100644 index 2cbe719..6741eae --- a/yarrg/web/check_routestring +++ b/yarrg/web/check_routestring @@ -29,70 +29,32 @@ sponsored by Three Rings. - This Mason component parses textual strings giving lists of islands - and archipelagoes, ie textual route strings. + This Mason component simply defines how to look up route entries. + It is called by qtextstring. -<%flags> -inherit => 'qtextstringcheck' - - -<%args> -$ocean -$format -$ctype => undef -$string -$returnhash => { } - - -<%perl> - -# typical url for this script: -# http://www.chiark.greenend.org.uk/ucgi/~clareb/mason/pirates/routetextstring?format=json&ocean=Midnight&string=d - -use CommodsWeb; - -my $dbh= dbw_connect($ocean); - -my $sth= $dbh->prepare("SELECT archipelago,islandid,islandname - FROM islands WHERE islandname LIKE ? - UNION ALL SELECT DISTINCT archipelago,NULL,archipelago - FROM islands WHERE archipelago LIKE ?"); - -my $emsg= ''; -my (@results, $canontext); - -foreach my $each (split m#[/|,]#, $string) { - $each =~ s/^\s*//; $each =~ s/\s*$//; $each =~ s/\s+/ /g; - next if !length $each; - my $err= sub { $emsg= sprintf $_[0], $each; last; }; - my %m; - my $results; - foreach my $pat ("$each\%", "\%$each\%") { - $sth->execute($pat,$pat); - $results= $sth->fetchall_arrayref(); - last if @$results==1; - map { $m{ $_->[2] }=1 } @$results; - $results= undef; - } - if (!$results) { - if (!%m) { - $err->('no island or arch matches "%s"'); - } elsif (keys(%m) > 5) { - $err->(' '); - } else { - $err->('ambiguous island or arch "%s",'. - ' could be '.join(', ', sort keys %m)); - } - } - push @results, $results->[0]; -}; - -$dbh->disconnect(); - -return $emsg, - (join ' | ', map { $_->[2] } @results), - [ @results ]; - - +<%attr> +multiple => 1 +maxambig => 5 + + +<%method sqlstmt> + SELECT islandname,islandid,archipelago + FROM islands WHERE islandname LIKE ? +UNION ALL SELECT DISTINCT archipelago,NULL,archipelago + FROM islands WHERE archipelago LIKE ? + + +<%method nomatch> + no island or arch matches <% $ARGS{specq} %> + + +<%method ambiguous> + ambiguous island or arch <% $ARGS{specq} %>, + could be <% $ARGS{couldbe} |h %> + + +<%method manyambig> +   +