Geo-IP-RU-IpGeoBase

 view release on metacpan or  search on metacpan

bin/ip-geo-base-ru  view on Meta::CPAN

my $api = Geo::IP::RU::IpGeoBase->new(
    db => \%db,
);
if ( $opt{'create'} ) {
    print "Going to create a table\n" if $opt{'verbose'};
    $api->create_table;
}

update_ip_geo_base();

sub update_ip_geo_base{

    my ($blocks_file, $cities_file) = fetch();

    my %city_info;
    $api->process_file(
        $cities_file,
        fields   => [qw(city_id city region federal_district latitude longitude)],
        callback => sub {
            my $rec = shift;
            $city_info{ delete $rec->{'city_id'} } = $rec;

bin/ip-geo-base-ru  view on Meta::CPAN

            my $city = $city_info{ $rec->{'city_id'} }
                or return;

            delete @{$rec}{'country_code', 'city_id'};
            update( { %$city, %$rec } );
        },
    );
    $api->dbh->do("DELETE FROM $table WHERE in_update = 1");
}

sub update {
    my $rec = shift;
    $rec->{'in_update'} = 0;
    if ( $opt{'create'} ) {
        print "Inserting block $rec->{start} - $rec->{end} ($rec->{city}, $rec->{longitude})\n" if $opt{'verbose'};
        return $api->insert_record( %$rec );
    }
    elsif ( $api->fetch_record( $rec->{'istart'}, $rec->{'iend'} ) ) {
        print "Updating block $rec->{start} - $rec->{end}  ($rec->{city}, $rec->{longitude})\n" if $opt{'verbose'};
        return $api->update_record( %$rec );
    }

lib/Geo/IP/RU/IpGeoBase.pm  view on Meta::CPAN


    my $table = $self->db_info->{'quoted_table'};
    my @keys = keys %rec;
    my $dbh = $self->dbh;
    my $query = 
        "INSERT INTO $table(". join( ', ', map $dbh->quote_identifier($_), @keys) .")"
        ." VALUES (". join( ', ', map $dbh->quote( $rec{$_} ), @keys ) .")";
    return $dbh->do( $query ) || die "Couldn't execute '$query': ". $dbh->errstr;
}

sub update_record {
    my $self = shift;
    my %rec  = @_;

    my $table = $self->db_info->{'quoted_table'};

    my @keys = grep $_ ne 'istart' && $_ ne 'iend', keys %rec;
    my $dbh = $self->dbh;
    my $query =
        "UPDATE $table SET "
        . join(



( run in 0.230 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )