Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use feature qw(say);
- use strict;
- use warnings;
- {
- my @tests = (
- [1, 'Empty table error - data load failed.'],
- [1, {'message' => 'Prepare failed: [Teradata][ODBC Teradata Driver][Teradata Database](-5628)Column DWH_TENANT_ID not found in Q. (SQL-HY000) '}],
- [1, {'message' =>
- {'message' => 'Prepare failed: [Teradata][ODBC Teradata Driver][Teradata Database](-5628)Column not found . (SQL-HY000) '}}],
- [1, {'message' =>
- {'message' =>
- {'message' => 'Prepare failed: [Teradata][ODBC Teradata Driver][Teradata Database](-5628)Column not found . (SQL-HY000) ' }}}],
- [2, {'message' =>
- {'message' =>
- {'sql_stmt' => ' select * from db.table',
- 'message' => 'Execute failed: [Teradata][ODBC Teradata Driver][Teradata Database](-2631)Transaction ABORTed due to Deadlock. (SQL-40001)' }}}],
- );
- for my $i (0..$#tests) {
- my $test = $tests[$i];
- my $type = $test->[0];
- my $hash = { "_errlist_" => [$test->[1]] };
- if ( $type == 1 ) {
- my $errmsg = extract_err( $hash->{_errlist_}[0], $type );
- say "Test #$i: $errmsg";
- }
- elsif ( $type == 2 ) {
- my $sql_statement = $hash->{_errlist_}[0]{message}{message}{sql_stmt};
- say "Test #$i: (sql) : $sql_statement";
- }
- }
- }
- sub extract_err {
- my ( $hash ) = @_;
- if (ref $hash eq "HASH") {
- return extract_err( $hash->{message} );
- }
- elsif (!(ref $hash)) {
- return $hash;
- }
- else {
- die "Unexpected reference type: ", ref $hash, "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement