Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

How do I go about Blessing an Object?

by Buckaroo Buddha (Scribe)
on Jun 05, 2001 at 22:29 UTC ( #85933=perlquestion: print w/replies, xml ) Need Help??

Buckaroo Buddha has asked for the wisdom of the Perl Monks concerning the following question:

here's the error message:
Can't call method "Fields" on unblessed reference

I'm using ASP-Perl and taking a value from a form to execute a query against an SQL database.

my $SQLstring = "SELECT * FROM table WHERE field1='"; my $filter = $Request->Form('USERFIELD')->$Item(); # this is taken directly out of the pages of # the O'Reilly Book CGI Programming. # I try to "clean up" the data that was entered # by the user and then take that # 'untainted data' out of a system variable # # the program dosen't work with or without this statement $filter=~ /^([\w.])$/; $filter = $1; $SQLstring .= $filter my $Provider = "SQLOLEDB"; my $ConnectString = "driver={SQL Server};server=SRVR;database=DB"; my $Conn = $Server->CreateObject("ADODB.Connection"); $Conn->Open($ConnectString); my $RS = $Conn->Execute( "$SQLstring" ); # this is the line on which the error occurs while ( ! $RS->{EOF} ) { $Response->Write($RS->Fields(0)->{Value}); $RS->MoveNext; } $RS->close;

This whole thing is intended to happen within a subroutine. If i'm going to run into troubles passing ADODB Recordsets around, please lemme know. I'm figuring that they're references to objects and shouldn't matter but it might.

Replies are listed 'Best First'.
Re: How do I go about Blessing an Object?
by tomhukins (Curate) on Jun 05, 2001 at 22:53 UTC

    To find out how to bless an object, read up on perlfunc:bless or Perl's object documentation in general.

    However, in this case you shouldn't need to bless the object. Blessing should be done within the code that creates the object (in this case, $Conn->Execute where $RS is returned), not the code that uses the object.

    I notice that you never check to see if any of your calls fail. For example, what happens if your $Server->CreateObject call fails?

    Given the error message you're seeing, I suspect the my $RS = $Conn->Execute( "$SQLstring" ) is failing. Try something like my $rs = $Conn->Execute($SQLstring) or die instead. You'll probably want to replace the die call with something more appropriate for your application.

Re: How do I go about Blessing an Object?
by nysus (Vicar) on Jun 05, 2001 at 23:12 UTC
Re: How do I go about Blessing an Object?
by Anonymous Monk on Jun 05, 2001 at 23:42 UTC
    You never close the ' in the $SQLstring . Insert $SQLstring .= "'"; before my $RS = $Conn->Execute( "$SQLstring" );!
Re: How do I go about Blessing an Object?
by Buckaroo Buddha (Scribe) on Jun 05, 2001 at 22:52 UTC

    I should mention that I have read the manpages regarding BLESS but do not understand them.

    I'd appreciate a human explanation/solution

    Thanks tomkukins ... I tried that  my $RS = $Conn->Execute( "$query" ) or $Response->Write($query);
    and found that there is indeed a problem there

    I'll update again later to fully explain the answer to the problem once i figure it out exactly

    UPDATE #2:
    the Execution of the query was not occuring correctly bcause of the SQL syntax.
    it appears that one is not allowed to put brackets around the list of fields one wants returned by SQL server.
    thanks agian to tomkins for helping me sort out my error

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://85933]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-08-15 14:12 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (78 votes). Check out past polls.