Dear Monks, I've written this little script that's behaving strangely (to me, but I'm not an expierenced programmer ;-) ) In a sub routine the script gets data from a (MySQL) database. When I call the schript from one place everything works fine and when I call it from another place (in exactly the same way) there are no results comming back from the database. When I do a print of the database Query and past that into phpmyadmin for testing, everything works fine, also with the query that does not return the data... Can anyone point me at what I'm doing wrong here? I don't know where the problem comes from so I'll post the whole script I have so far... (Sorry for the large part of code!)
#!/usr/bin/perl use Time::HiRes qw( usleep ); use DBI; open (CONFIG, "<homenet.actiontrigger.conf"); while (readline CONFIG) { if ( $_ !~ /^\s*#\s*/ ) { if ($_ =~ /\S+/ ) { if ( $_ =~ /^\s*(\S+)\s*=\s*(\S+)\s*#*(.*)$/ ) {}; $conf_key = $1; $conf_value = $2; $conf{$conf_key} = $conf_value; } } } close (CONFIG); $script_name = "action trigger"; $db_homenet = DBI->connect("DBI:mysql:$conf{DatabaseName}:$conf{Databa +seServer}",$conf{DatabaseUser},$conf{DatabaseSecret}); $X = 0; while( $X != 1 ) { $Query_lookque = "SELECT COUNT(*) FROM Input_Que"; my $lookque = $db_homenet->prepare( $Query_lookque ); $lookque->execute(); my ( $rows ); $lookque->bind_columns( undef, \$rows ); while( $lookque->fetch() ){} if ( $rows >= 1 ) { $data = ""; $Query_check_inputque = "SELECT * FROM `Input_Que` WHERE 1 +LIMIT 1"; my $check_inputque = $db_homenet->prepare( $Query_check_inp +utque ); $check_inputque->execute(); my( $nr, $timestamp, $busname, $data ); $check_inputque->bind_columns( undef, \$nr, \$timestamp, \$ +busname, \$data ); while( $check_inputque->fetch() ){ } print "$nr - $timestamp - $busname - $data"; if ( $data =~ /.*(\w{2})r(\w{2})=(\w{2})/ ) + # memory read data { $data_type = "alive_message"; $dev_id = $1; $memory_location = $2; $data = $3; print "MEMORY-DATA-READ van $dev_id op bus $busname +: Mem_loc = $memory_location, data = $data\n"; } elsif ( $data =~ /.*(\w{2})M(\w{2})=(\w{2})/ ) + # Meter reading { $data_type = "meter_reading"; $dev_id = $1; $dev_line = $2; $data = $3; print "METER-READING van $dev_id op bus $busname: D +evice_line = $dev_line, data = $data\n"; } elsif ( $data =~ /.*(\w{2})(\w{1})(\w{2})=(\w{2})/ ) + # alive message { $data_type = "alive_message"; $dev_id = $1; $short_type = $2; $version_high = $3; $version_low = $4; print "ALIVE-MESSAGE van $dev_id op bus $busname: T +ype = $short_type\n"; $query_sendcommand = "UPDATE `state-table` SET `la +stchange` = '$timestamp' WHERE `device` =('$dev_id') && `busname` =(' +$busname') LIMIT 1 ;"; $db_homenet->do( $query_sendcommand ); } elsif ( $data =~ /.*(\w{2})(\w{2})>(\w+)>/ ) + # hard command { $data_type = "hard_command"; $sender_id = $1; $receiver_id = $2; $command = $3; print "HARD-COMMAND van $sender_id naar $receiver_ +id op bus $busname: Command = $command\n"; received_command($sender_id, $busname, $receiver_i +d, $busname, $command); } elsif ( $data =~ /.*(\w+)>(\w+)>(.+)>(\w+)>/ ) + # soft command { $data_type = "soft_command"; $receiver_id = $3; $command = $4; $sender_id = "S3"; print "SOFT-COMMAND naar $receiver_id op bus $busn +ame: Command = $command\n"; received_command($sender_id, $busname, $receiver_i +d, $busname, $command); } elsif ( $data =~ /.*(\w+)\?(.+)\?/ ) + # memory read request { $data_type = "memory_read_request"; $receiver_id = $1; $memory_location = $2; print "MEMORY-READ-REQUEST naar $receiver_id op bu +s $busname: Memory Location = $memory_location\n"; } elsif ( $data =~ /.*(\w+)=(.{2})(.{2})=/ ) + # memory write request { $data_type = "memory_write_request"; $receiver_id = $1; $memory_location = $2; $write_data = $3; print "MEMORY-WRITE naar $receiver_id op bus $busn +ame: Memory Location = $memory_location, data = $write_data \n"; } else { print "data kan niet worden ontcijfert! \n"; } $Query_delete_from_que = "DELETE FROM `Input_Que` WHERE `nr +` = $nr LIMIT 1"; $db_homenet->do( $Query_delete_from_que ); print " ******************************************************* +************************ \n"; } usleep 100000 } sub received_command { print "(1)\n"; ($command_source, $sbus, $command_destination, $dbus, $data) = @_; print "@_\n"; # First: We get the device type and software version! print "(2)\n"; $cod = "$command_destination"; # $Query_gettype = "SELECT `type` , `softv_high` , `softv_low` FROM + `master_devices` WHERE naam = ( '$command_destination' ) && bus = ( +'$dbus' ) LIMIT 1"; $Query_gettype = "SELECT `type` , `softv_high` , `softv_low` FROM +`master_devices` WHERE naam = ( '$cod' ) LIMIT 1"; print "$Query_gettype\n"; my $gettype = $db_homenet->prepare( $Query_gettype ); print "(3)\n"; $gettype->execute(); print "(4)\n"; my( $type, $swh, $swl ); print "(5)\n"; $gettype->bind_columns( undef, \$type, \$swh, \$swl ); print "(6)\n"; while( $gettype->fetch() ){} print "$type\n"; print "$swh\n"; print "$swl\n"; print "(7)\n"; $devtype = "$type.$swh.$swl"; print "$type\n"; print "$swh\n"; print "$swl\n"; print "Device Type = $devtype\n"; # Then we look up the command in the command_matrix! $Query_getline = "SELECT `line`, `activate`, `deactivate`, `switch +`, `timerswitch`, `value` FROM `command_matrix` WHERE device_type = ( +'$devtype') && ( activate = ('$data') || deactivate = ('$data') || sw +itch = ('$data') || timerswitch = ('$data') || value = ('$data') ) LI +MIT 1"; my $getline = $db_homenet->prepare( $Query_getline ); # print "$Query_getline\n"; $getline->execute(); my( $line, $activate, $deactivate, $switch, $timerswitch, $value ) +; $getline->bind_columns( undef, \$line, \$activate, \$deactivate, \ +$switch, \$timerswitch, \$value ); while( $getline->fetch() ){} # print "$line, $on, $off, $switch, $timerswitch, $value\n" ; # print "$command_destination\n"; $sdev = "$command_destination.$line"; print "slave-device = $sdev\n"; # Next we see what command it is! # print "-$data-\n"; # print "-$activate-\n"; # print "-$deactivate-\n"; if ( $activate =~ $data ) { print "activate\n"; } elsif ( $deactivate =~ $data ) { print "deactivate\n"; } elsif ( $switch =~ $data ) { print "switch\n"; } elsif ( $timerswitch =~ $data ) { print "timerswitch\n"; } elsif ( $value =~ $data ) { print "value\n"; } }
The script works for the Hard Command but not for the Soft Command. Thanks a lot for any help you can give me on this!

In reply to Database problem by jeroen_h

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.