PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: writebinary/writetext
Date: Oct 23 1997 4:36PM

John Gilmore-Baldwin wrote:
> 
> I need to start using writebinary and writetext commands.  Never really
> dealt with that much before.
> 
> Does anyone have any examples or caveats before I jump in?

The caveat is that you need to make sure that @@TEXTSIZE (or the
DBTEXTSIZE option) is large enough for the values you are
going to insert. The default is 32k (32768) bytes.

Look at the dbtext.pl script in the eg directory for an example on
how to use dbwritetext().

Here's a portion of a script which inserts a new record into
a bugtracking database:



$dbh = new Sybase::DBlib mpeppler;
$dbh->dbuse('BugTrack');

# insert the new bug record:

$sum_string = $dbh->dbsafestr($bugheaders{$summary});

# Insert everything *except* the TEXT field:

$dbh->dbcmd("
begin tran
insert bug(category, id, type, sub_by, summary, priority, description)
values(\"$bugheaders{$category}\", 0, \"$bugheaders{$type}\",
\"$address\",
       \"$sum_string\", $bugheaders{$priority}, \"\")
select max(id) from bug
commit tran
");
$dbh->dbsqlexec != FAIL || ++$fail;
while(($ret = $dbh->dbresults) != NO_MORE_RESULTS)
{
    ++$fail if($ret == FAIL);
    if($dbh->DBROWS)
    {
	($bug_id) = $dbh->dbnextrow;
    }
}

die "Arghh!! \$bug_id has not been set!" if($bug_id == -1);

# Now select the 'description' (TEXT) column from the row
# we just inserted:
$dbh->dbcmd("select description from bug where id = $bug_id");
$dbh->dbsqlexec; $dbh->dbresults;
($dat) = $dbh->dbnextrow;
$dbh->dbwritetext("bug.description", $dbh, 1, $body) != FAIL || ++$fail;

if(!$fail)
{
    open(MAIL, "|/usr/ucb/Mail -s 'Bug Report' $sender mpeppler") ||
	die "Can't open Mail: $!";

    print MAIL <<"EOF_MAIL";
Dear $friendly,

Your bug report has been correctly received, and has been attributed
the Id# $bug_id.

Your message follows:

EOF_MAIL

    print MAIL "$orig_body\n";
    close(MAIL);
}
else
{
    &mail_problem("Database access problems - email mpeppler\@itf.ch for
help");
}

# End excerpt.


Hope this helps!

Michael
-- 
Michael Peppler       -||-  Data Migrations Inc.
mpeppler@datamig.com  -||-  http://www.mbay.net/~mpeppler