Hi I'm hoping someone can help with this?

I'm executing code similar to the code bellow (Not actual but it replicates the problem)

I'm inserting point data into a PostgreSQL/PostGIS database

I spotted this warning and managed to hit the keyboard pause button before it disappeared of the screen.

"WARNING: OGC WKT expected, EWKT provided - use GeomFromEWKT() for this"

The error was caused by badly formatted coordinates that is secondary and will need human intervention to resolve!

My question is how do I trap the warning so I can then do something sensible with the problem record(s).

The database doesn’t return an error through DBI->errstr but returns a non existent lastID

I thought it was Perl warnings but that code doesn’t fire

I’m using version 3.5.1 of DBD::PG

#!C:/strawberry/perl/bin/perl.exe use strict; use warnings; use DBI; use DBD::Pg; my $pwd ="MyPwd"; # my $dbh = DBI->connect('dbi:Pg:dbname=my_geo_table;host=dbhost', 'user', $pwd, { PrintError => 0, HandleError => \&handle_error, } ) or handle_error(DBI->errstr); my $some_text ="hello World"; my $LongDEC = "017.12.270"; my $LatDEC = "44.82115"; my $post_id = 123; my $cmd = "insert into latlong (post_id,some_text,geom) VALUES (" +. $dbh->quote($post_id) . "," . $dbh->quote($some_text) . ", ST_GeomFromText('POINT($LongDEC $LatDEC)', 4326) )"; my $query_handle = $dbh->prepare($cmd); $query_handle->execute(); my $lastID = $dbh->last_insert_id(undef,undef,"latlong",unde +f); if(defined(DBI->errstr)) { ## not getting here my $ErrMsg .= "Error: " . handle_error(DBI->errstr); print $ErrMsg . "\n"; } else { print "Finished with $post_id lastid =[$lastID]\n"; } sub handle_error { my $message = shift; return ("### The Error message from DB is '$message' ###\n"); } ## These subs are for trapping warnings local $SIG{__WARN__} = sub { my $message = shift; print "warning $message\n"; # not getting here logger('warning', $message); }; sub logger { my ($level, $msg) = @_; if (open my $out, '>>', $dir . "\\log.txt") { chomp $msg; print $out "$level - $msg\n"; } } #### print out to cmd WARNING: OGC WKT expected, EWKT provided - use GeomFromEWKT() for thi +s Finished with 123 lastid =[567] 1 records processed 0 error-ed

In reply to Capturing warnings from DBD:PG by HeadScratcher

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.