Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Database problem

by jeroen_h (Initiate)
on Aug 06, 2005 at 18:57 UTC ( [id://481533]=note: print w/replies, xml ) Need Help??


in reply to Re: Database problem
in thread Database problem

Ofcourse I would not dare to ask for all of your help without first trying really hard to solve my problems myself... But ofcourse that does not always show when asking a question. Using the suggestions of all of you, I've come a bit closer to what the problem is (I think) I've striped the script of all I think I could do without, and after changing the variables that are send to the subroutine to fixed values, everything worked from both places. So next I tried to find the problem by changing them back to variables again and I found that the $receiver_id I get out of the regular expression in the soft command section seems to cause the problem. When I do my $receiver_id = $3; it gives an error but when I say my $receiver_id = "U1"; it all works... I've also tried to change the regular expression from using (.+) to (\w+) and (\w{2}) because that's what is used in the hard-command part, but then it breaks my regular expression... Does this help you people to point me at what I'm doing wrong here? The shortened script looks like this:
#!/usr/bin/perl use Time::HiRes qw( usleep ); use DBI; # use strict; use warnings; open (CONFIG, "<homenet.actiontrigger.conf") or die "Can't open Config + file: $!" ; while (readline CONFIG) { if ( $_ !~ /^\s*#\s*/ ) { if ($_ =~ /\S+/ ) { if ( $_ =~ /^\s*(\S+)\s*=\s*(\S+)\s*#*(.*)$/ ) {}; my $conf_key = $1; my $conf_value = $2; $conf{$conf_key} = $conf_value; } } } close (CONFIG); my $db_homenet = DBI->connect("DBI:mysql:$conf{DatabaseName}:$conf{Dat +abaseServer}",$conf{DatabaseUser},$conf{DatabaseSecret}); my $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 ) { my $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})(\w{2})>(\w+)>/ ) + # hard command { my $data_type = "hard_command"; my $sender_id = $1; my $receiver_id = $2; my $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 { my $data_type = "soft_command"; my $receiver_id = $3; my $command = $4; my $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); } else { print "data kan niet worden ontcijferd! \n"; } $Query_delete_from_que = "DELETE FROM `Input_Que` WHERE `nr +` = $nr LIMIT 1"; $db_homenet->do( $Query_delete_from_que ); } usleep 100000 } sub received_command { my $command_source = "*"; my $sbus = "*"; my $command_destination = "*"; my $dbus = "*"; my $data = "*"; ($command_source, $sbus, $command_destination, $dbus, $data) = @_; print "@_\n"; my $cod = "$command_destination"; # $Query_gettype = "SELECT `type` , `softv_high` , `softv_low` FROM + `master_devices` WHERE naam = ( '$command_destination' ) && bus = ( +'$dbus' ) LIMIT 1"; my $Query_gettype = "SELECT `type` , `softv_high` , `softv_low` FR +OM `master_devices` WHERE naam = ( '$cod' ) LIMIT 1"; print "$Query_gettype\n"; my $gettype = $db_homenet->prepare( $Query_gettype ); $gettype->execute(); my( $type, $swh, $swl ); $gettype->bind_columns( undef, \$type, \$swh, \$swl ); while( $gettype->fetch() ){} print "$type\n"; print "$swh\n"; print "$swl\n"; $devtype = "$type.$swh.$swl"; print "Device Type = $devtype\n"; }
By the way, this is the output I get when I have the soft-command problem:
./hbat-test "my" variable $data masks earlier declaration in same scope at ./hbat- +test line 41. 9873 - 20050806205302 - 10.54.1.250 - 1>h>U1>h> SOFT-COMMAND naar U1 op bus 10.54.1.250: Command = h S3 10.54.1.250 U1 10.54.1.250 h SELECT `type` , `softv_high` , `softv_low` FROM `master_devices` WHERE + naam = ( 'U1' ) LIMIT 1 Use of uninitialized value in concatenation (.) or string at ./hbat-te +st line 102. Use of uninitialized value in concatenation (.) or string at ./hbat-te +st line 103. Use of uninitialized value in concatenation (.) or string at ./hbat-te +st line 104. Use of uninitialized value in concatenation (.) or string at ./hbat-te +st line 105. Use of uninitialized value in concatenation (.) or string at ./hbat-te +st line 105. Use of uninitialized value in concatenation (.) or string at ./hbat-te +st line 105. Device Type = ..

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-28 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found