MK wrote:
> Hi Mason Users!
> 
> I've been frustrated with this all morning.  I have a particular spot 
> where (presumably) mason is not filling in a variable correctly and so 
> a DBI->do call is coming back with *no* return value (it is not undef, 
> either).  Here's some prelimary stuff that all works fine:
> 
> % my $db = DBI->connect("DBI:SQLite:$db_file");
> 
> % #######  Determine how we were called ######
> % # add subject to database?
> % if (exists $ARGS{name}) { $db->do("insert into subjects (name) values 
> ('$ARGS{name}');"); }
> 
> Then there are other possibilities using if (exists), this is the 
> problem one as it *should* be:
> 
> % # add docdir to database?
> % } elsif (exists $ARGS{title}) {
> %     $db->do(<<"DONE");
> %          insert into docdirs (title,path,subj_id,pages)  
> %          values ('$ARGS{title}','$ARGS{path}',
> %               '$ARGS{subjid}','$ARGS{pages}');
> %DONE
> %}
> 
> However, none of these variable is getting filled in altho they are 
> testing valid.  Here is what I'm looking at now after such testing:
> 
> % # add docdir to database?
> % } elsif (exists $ARGS{title}) {
> %   my $t=$ARGS{title}; my $p=$ARGS{path}; my $s=$ARGS{subjid}; 
> my $n=$ARGS{pages};
> 
> %#  my $r=$db->do("insert into docdirs (title,path,subj_id,pages) 
> values ('$t','$p','$s','$n');");
> 
> %   my $r=$db->do("insert into docdirs (title) values ('$t');");
>     <h2><%"($r) $t $p $s $n <-"%></h2>
> % }

i have some points to add, in addition to what the other responders have 
said.

one of the primary principles of debugging is to break the problem down 
into the simplest test case possible that still fails. besides helping 
you to better focus in on where the problem might be, you'd be amazed 
how many times you will find your syntactical or logical error when 
stripping away all but what is necessary for failure.

i find that it's good practice to any commands that will be passed off 
into another execution environment (database, system(), exec(), ``, 
etc.) into a local scalar.

%     my $sql = <<"DONE";
%          insert into docdirs (title,path,subj_id,pages)
%          values ('$ARGS{title}','$ARGS{path}',
%               '$ARGS{subjid}','$ARGS{pages}');
%DONE
%
%#     $m->out("sql: '$sql'<br />\n");
%     $db->do($sql);


that way, the first thing that you do when you have a problem is to 
print out exactly what string is being passed. it is very easy to make 
simple mistakes such as mistyping a variable name, or in this case a 
hash key, between the conditional statement and the actual insert. this 
also shows the value of using an <%args> block, as opposed to accessing 
the values directly in the %ARGS hash.

this fails, and does so in a very comprehensible way:

<%args>
   $subjid
</%args>

% $m->out( $subjjid );


while this does not fail, nor give any clear clues as to why the 
expected value is not being displayed.

% $m->out( $ARGS{'subjjid'} );


also, how are you checking for db errors? i didn't see any of the 
familiar options in your connect statement

% my $db = DBI->connect("DBI:SQLite:$db_file", {
%   RaiseError => 1,
%   PrintError => 0,
%   ShowErrorStatement => 1,
% } );

nor any active error checking and printing after attempted statement 
execution.

% my $rows = $dbh->do($statement) or die $dbh->errstr;

> 
> this contains my attempts to find a solution (eg by assigning tmp 
> variables from $ARGS).   I would note that no matter what variable 
> value I use (eg, $t="whatever") in the simplified, one value version at 
> the bottom, I get nothing.  If I change it to:
> 
> %   my $r=$db->do("insert into docdirs (title) values ('whatever');");
> 
> Ie, no variable to substitute, then $r is one and "whatever" is 
> successfully added to the db.  Again, all the variables do contain 
> correct values as verified by the <h2> line. This shows $r as nothing 
> (); but $r does not test positive for undef either.
> 
> I suspect this has something to do with the order in which Mason 
> performs substitutions, but in any case it seems like a real "bug" or 
> something to me; the variable is valid and the syntax is identical to 
> the syntax I am using elsewhere.  There is no SQL error in the http 
> logs.
> 
> If I can't find a better solution, I will just have to work around this 
> by breaking the page into seperate components -- since all my other db 
> insert calls work, the only thing I see different in this page is the 
> length and number of (potential) db operations, etc.  Since only one of 
> the potential operations will take place, I can't really blame DBI and 
> believe the page is just "too much" for mason to correctly parse*.  
> That is not a very satisfying solution!
> 
> _MK
> 
> * all of those other, almost identical ones, work, so I can't blame the 
> preceeding syntax either...the last one just appears to be "the straw 
> that broke the camel's back" ;)
> 
> 
> ------------------------------------------------------------------------------
> Crystal Reports - New Free Runtime and 30 Day Trial
> Check out the new simplified licensing option that enables unlimited
> royalty-free distribution of the report engine for externally facing 
> server and web deployment.
> http://p.sf.net/sfu/businessobjects
> _______________________________________________
> Mason-users mailing list
> Mason-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mason-users

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Mason-users mailing list
Mason-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to