Solved

Perl, Postgres, Get error message from data base call

Posted on 2010-09-21
3
434 Views
Last Modified: 2012-05-10
How do I get  the error message from data base call.  For example, $num1 and $num2 was supposed to have interger, but instead I assigned it a string, which will cause a database error.

  $dbh = DBI->connect("dbi:Pg:dbname=mis;host=$gHost", "$gUser", "$gPassword", { RaiseError => 0, AutoCommit => 1 });
  $sth = $dbh->prepare("insert into myTable(a,b) values ('$num1','$num2',);");
  $sth->execute();
  if( $DBI::err ) {
    #How do I get the database error message?
  } else {
    $success = 1;
  }
0
Comment
Question by:rgbcof
3 Comments
 
LVL 15

Accepted Solution

by:
ishando earned 125 total points
ID: 33731275
$sth->err()
 $sth->errstr()
 
 These give the error number and error message for oracle. As these are DBI attributes and not DBD they should also work for postgres
 
0
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 125 total points
ID: 33731305
You could also use the variable $DBI::errstr, or call err() and errstr() on the $dbh.
0
 

Author Closing Comment

by:rgbcof
ID: 33774337
They both came up with the right solution.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question