Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

sql2008 Filestream

by ksublondie (Friar)
on Mar 01, 2011 at 18:10 UTC ( #890791=perlquestion: print w/replies, xml ) Need Help??
ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

I've got an apache server using FreeTDS, DBI & DBD::Sybase to connect to a sql2008 db. I would like to implement sql2008's Filestream functionality, but I've hit a wall.

sub printTransaction{ ... #$print is postscript content generated with Postscript::Simple my $statement ="insert into Printed (thisid,[datetime],id,printedby,da +ta) values ('$thisid','$now','$id','$userid',cast('$print' as varbinary(MA +X)))"; eval{ $db->do($statement); }; if ($@){ warn "Aborted because $@"; $db->rollback; return 0; } ... }
Yes, I'm actually printing the content to a physical printer, but I need to store a "snapshot" of the print job for auditing purposes since the information is sensitive. If I set $print to a simple test string (i.e. 'testing'), it works like a charm and I can see the text files on the sql server. However, when I try to set $print to my postscript content, I get the following error in the apache log:
[Mon Feb 28 17:54:25 2011] -e: DBD::Sybase::db do failed: Server messa +ge number=8179 severity=16 state=2 line=1 server=SQL2008\SQL2008 proc +edure=sp_unprepare text=Could not find prepared statement with handle + 0. [Mon Feb 28 17:54:25 2011] -e: Aborted because DBD::Sybase::db do fail +ed: Server message number=8179 severity=16 state=2 line=1 server=SQL2 +008\SQL2008 procedure=sp_unprepare text=Could not find prepared state +ment with handle 0.
...and then after restarting apache, I see:
[Tue Mar 01 10:39:20 2011] [notice] Graceful restart requested, doing +restart out of memory for rpc row!
...Which I only see after running my script with ps content and restarting apache. No other time.

I haven't been able to find much help from google, but I'm suspecting that the FreeTDS connection is getting overloaded by the volume of the content I'm trying to pass (???), however, sql2008 Filestream is designed for files larger than 1M. Anything smaller is defeating the purpose. Is it even possible to implement Filestream with perl scripts?

Replies are listed 'Best First'.
Re: sql2008 Filestream
by Eliya (Vicar) on Mar 01, 2011 at 18:21 UTC
    my $statement ="insert into ... values ('$thisid','$now','$id','$userid',cast('$print' as ... "

    Don't interpolate Postscript content ($print) into SQL statements, use placeholders instead (this is a good idea in general, not only for Postscript content).

    Postscript code can in theory (depending on how it's generated) contain arbitrary characters, and even if it's 7-bit only, it can still contain single quotes...

    As for the out-of-memory error with Apache, I don't know, but maybe it's indirectly caused by the other problem, so I would fix that first.

      Well, after using placeholders I'm not getting any errors anymore, but I'm not sure if the data is getting there properly. When I retrieve the binary data from the db (still have to figure out how to convert it back to ps), I'm only getting 161 characters out of the database when my original ps content was 1.3M. Can that be right???

      ...Oh, and the memory error is no longer showing up either...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://890791]
Approved by marto
[GotToBTru]: choroba++ the right tool for the job

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (11)
As of 2017-01-24 14:09 GMT
Find Nodes?
    Voting Booth?
    Do you watch meteor showers?

    Results (205 votes). Check out past polls.