Dbi Raiseerror Print Error
Contents |
Related Modules Rose::DB::Object DBIx::Class Class::DBI more... By perl dbi raiseerror perlmonks.org CPAN RT New 14 Open 11 Stalled perl dbi escape 4 View/Report Bugs Module Version: 1.636 Source NAME SYNOPSIS
Perl Dbi Handleerror
GETTING HELP General Mailing Lists IRC Online Reporting a Bug NOTES DESCRIPTION Architecture of a DBI Application Notation and Conventions
Perl Dbi Connect Error Handling
Outline Usage General Interface Rules & Caveats Naming Conventions and Name Space SQL - A Query Language Placeholders and Bind Values THE DBI PACKAGE AND CLASS DBI Constants DBI Class Methods parse_dsn connect connect_cached available_drivers installed_drivers installed_versions data_sources trace perl dbi errstr visit_handles DBI Utility Functions data_string_desc data_string_diff data_diff neat neat_list looks_like_number hash sql_type_cast DBI Dynamic Attributes $DBI::err $DBI::errstr $DBI::state $DBI::rows $DBI::lasth METHODS COMMON TO ALL HANDLES err errstr state set_err trace trace_msg func can parse_trace_flags parse_trace_flag private_attribute_info swap_inner_handle visit_child_handles ATTRIBUTES COMMON TO ALL HANDLES Warn Active Executed Kids ActiveKids CachedKids Type ChildHandles CompatMode InactiveDestroy AutoInactiveDestroy PrintWarn PrintError RaiseError HandleError HandleSetErr ErrCount ShowErrorStatement TraceLevel FetchHashKeyName ChopBlanks LongReadLen LongTruncOk TaintIn TaintOut Taint Profile ReadOnly Callbacks private_your_module_name_* DBI DATABASE HANDLE OBJECTS Database Handle Methods clone data_sources do last_insert_id selectrow_array selectrow_arrayref selectrow_hashref selectall_arrayref selectall_array selectall_hashref selectcol_arrayref prepare prepare_cached commit rollback begin_work disconnect ping get_info table_info column_info primary_key_info primary_key foreign_key_info statistics_info tables type_info_all type_info quote quote_identifier take_imp_data Database Handle Attributes Aut
Q&A Tutorials Poetry RecentThreads NewestNodes Donate What'sNew on Dec 23, 2008 at 13:04UTC ( #732285=perlquestion: print w/replies, xml ) Need Help?? perlthirst has asked for the wisdom of the Perl Monks concerning the following question: Hi, From the manual page of
Perl Dbi Execute Return Value
DBI, i got the following informations PrintError: it will do a warn try catch in perl on an error. RaiseError: It will do a die on an error. Can any body explain, in which case perl dbi connect mysql we would want to warn on an error and in which case we would want to die on an error. I think we should always use RaiseError, for whatever error occurs http://search.cpan.org/perldoc?DBI it should do a die. If anybody have a better understanding about this, kindle explain. Comment on dbi: PrintError and RaiseError Replies are listed 'Best First'. RaisePetPeeve => 1 by Your Mother (Chancellor) on Dec 24, 2008 at 01:52UTC There can be good reasons for certain exceptions (accidental pun) but in general always RaiseError. Software that is broken should act broken. I'd always http://www.perlmonks.org/?node_id=732285 rather explain to a customer why an app stopped working over why an app put orders in the bit bucket for two weeks or sent reports with incorrect information while acting like everything was running fine. [reply] Re: RaisePetPeeve => 1 by gube (Parson) on Dec 24, 2008 at 05:52UTC I too agree to RaisePetPeeve. Most of the times if we try to delete 3 things as zwon mentioned and 1st and 3rd delete and 2nd record not getting delete due to some constraints, we may not known exactly in big application and it will create problem later. So, rather use RaiseError find the issue(constraint issue or whatever) and fix the problem.[reply] Re: dbi: PrintError and RaiseError by Tanktalus (Canon) on Dec 24, 2008 at 00:16UTC In general, RaiseError is a good idea. However, if, as an example, you were developing yet another Object-relational mapping system, you may want your objects to handle the errors, so you'd turn both PrintError and RaiseError off, and then check for errors and maybe throw an exception as appropriate, for the caller to handle. Since this is another full-fledged except
here for a quick overview of the site Help Center Detailed answers to any questions http://stackoverflow.com/questions/6649456/error-handling-on-dbi-connect you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers http://www.microhowto.info/troubleshooting/troubleshooting_perl_dbi.html or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a perl dbi community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Error handling on DBI->connect up vote 2 down vote favorite 1 Besides handling error using standard code die "Unable to connect: $DBI::errstr\n" is it possible to write a custom code like below? Standard: perl dbi connect $dbstore = DBI->connect($dsn, $user, $pw, {ora_session_mode => $mode, PrintError => 0, RaiseError => 0, AutoCommit => 0}) or die "Unable to connect: $DBI::errstr\n"; Custom: $dbstore = DBI->connect($dsn, $user, $pw, {ora_session_mode => $mode, PrintError => 0, RaiseError => 0, AutoCommit => 0}); if (!$dbstore) { CUSTOM_LOG_HANDLER("Could not connect to database: $DBI::errstr"); return; } Sample Standard Code: #!/usr/bin/perl # PERL MODULES WE WILL BE USING use DBI; use DBD::mysql; # HTTP HEADER print "Content-type: text/html \n\n"; # CONFIG VARIABLES $platform = "mysql"; $database = "store"; $host = "localhost"; $port = "3306"; $tablename = "inventory"; $user = "username"; $pw = "password"; #DATA SOURCE NAME $dsn = "dbi:mysql:$database:localhost:3306"; # PERL DBI CONNECT (RENAMED HANDLE) $dbstore = DBI->connect($dsn, $user, $pw) or die "Unable to connect: $DBI::errstr\n"; Thanks for you time. perl dbi share|improve this question asked Jul 11 '11 at 11:30 Hozy 1031210 Are there any other ways to exit gracefully without errors getting logged into the web server logs? –
click to enable Troubleshooting Perl DBI Content 1 Objective 2 Symptoms 3 Investigation 3.1 Strategy 3.2 Ensure that error messages are visible 3.3 View queries as they reach the database server 3.4 Test queries using a command-line database client 3.5 Dumping the data structure returned by the DBI module 3.6 Tracing the DBI module Objective To diagnose problems arising from use of the Perl DBI module Symptoms Most of the major problems that can occur when using the Perl DBI module cause a meaningful error message to be generated. Typically this is written to STDERR (but see below for how this could have been overridden). Scripts which run as daemons may redirect STDERR to a logfile, to syslog, or (less helpfully) to /dev/null. Similar considerations apply to scripts that are called by daemons (such as CGI scripts). Investigation Strategy There are five possibilities to consider: the DBI module is not being called in the manner that you intended, or the DBI module is not delivering the intended SQL statements to the database, or the SQL statements are not having the desired effect when they are executed by the database, or the DBI module is not correctly returning the result set to the client program, or the client program is misinterpreting the result set. If an error message is generated then it is likely that both the point of failure and the cause of failure will be obvious. Otherwise, it will be necessary to trace the query through its various stages of processing to determine where it deviates from what is expected. Ensure that error messages are visible The DBI module can report errors in several different ways: If $dbh is the connection handle then $dbh->err will be true if the most recent substantive operation failed, otherwise it will be undefined or false. If $dbh->err is true then $dbh->errstr should contain a h