Solved

Perl, Postgres, Get error message from data base call

Posted on 2010-09-21
3
432 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
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.

920 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now