Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: How to add columns with new row name using perl from mysql query?

by finddata (Sexton)
on Apr 06, 2017 at 12:08 UTC ( #1187263=note: print w/replies, xml ) Need Help??


in reply to Re^3: How to add columns with new row name using perl from mysql query?
in thread How to add columns with new row name using perl from mysql query?

I HAD USED AS FOLLOWS BUT IT THROWS AN ERROR AS could not in7sert_run_pend data
sub pending_running_partition { $var_data_running = ""; $var_data_pending = ""; my $str= shift; $DBH = &connect or die "Cannot connect to the sql server \n"; $DBH->do("USE $str;"); my $stmt="select queue_name,jobs_pending,jobs_running from(select +queue_name,jobs_pending,jobs_running from queues order by queue_name +limit 5)union all select 'others',sum(jobs_pending) as jobs_pending,s +um(jobs_running) as jobs_running from (select jobs_pending,jobs_runni +ng from queues order by queue_name limit -1 offset 5"; my $sth = $DBH->prepare( $stmt ); $sth->execute() or print "Could not in7sert_run_pend data"; my $tmp = 0; while(my @row_array=$sth->fetchrow_array) { if ($tmp == 0) { $var_data_running .= "\[\"$row_array[0] \($row_array[2]\)\",$r +ow_array[2]\]"; $var_data_pending .= "\[\"$row_array[0] \($row_array[1]\)\",$r +ow_array[1]\]"; $tmp++; } else { $var_data_running .= ",\[\"$row_array[0] \($row_array[2]\)\",$ +row_array[2]\]"; $var_data_pending .= ",\[\"$row_array[0] \($row_array[1]\)\",$ +row_array[1]\]"; } } $sth->finish; $DBH->disconnect(); }
  • Comment on Re^4: How to add columns with new row name using perl from mysql query?
  • Download Code

Replies are listed 'Best First'.
Re^5: How to add columns with new row name using perl from mysql query?
by Corion (Pope) on Apr 06, 2017 at 12:12 UTC

    There is no error message COULD NOT INSERT DATA in your code.

    Please show the exact error message you get, and the exact code you are running.

    Also consider creating your database connection with the RaiseError flag so that DBI automatically tells you when an error happens.

      It shows error message as Could not in7sert_run_pend data

        You did not show the SQL your code is running.

        Please change your code to the following to see the real error message your database gives you:

        $sth->execute or die $sth->errstr;

        ... or alternatively, as I already said, use the RaiseError flag when creating your database connection.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1187263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2019-12-11 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?