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: mpeppler at itf dot ch (Michael Peppler)
Subject: Re: Problems with writing text
Date: Jan 25 1996 7:56AM

From: Rob_Osattin@ajc.com (Rob Osattin)
> 
> The purpose of the program is to continuously scan directories on the Sun
> and copy the contents of all files found to rows in a certain table. Each
> file goes into a text column in its own row. What we're seeing is that,
> after a while, files are being run together- the text in the most recently
> created row includes all the text of every row previously written since the
> program was started. This is not good!

Nope, that's not good...

I just ran some tests here, and I got some pretty weird results...

I used the script below to populate a dummy 'story' table that has two
fields: the name and the content (text). I ran it over two directories,
inserting 1650 files for a total of 94MB.

#!/usr/local/bin/sybperl.old
# I used the 1.012 version...
require 'sybperl.pl';

$d1 = &dblogin('mpeppler', 'guess-what', 'TROLL');

while(<*>) {
    open(IN, $_) || die "Can't open $_: $!\n";
    @lines = ;
    $text = "@lines";
    close(IN);
    print "Processing $_\n";
    &dbcmd($d1, "insert story values('$_', '')");
    &dbsqlexec($d1);
    while(&dbresults($d1) != $NO_MORE_RESULTS) {
	while(@dat = &dbnextrow($d1)) {
	    print "@dat\n";
	}
    }
    &dbcmd($d1, "select name, data from story where name = '$_'");
    &dbsqlexec($d1);
    &dbresults($d1);
    @dat = &dbnextrow($d1);
    &dbwritetext($d1, "story.data", $d1, 2, $text);
}

The populating of the table seemed to go fine, so I wrote a report script:

#!/usr/local/bin/sybperl.old

require 'sybperl.pl';

$d = &dblogin('mpeppler', 'mpeppler', 'TROLL');

&dbcmd($d, "select name, data from story");
&dbsqlexec($d);&dbresults($d);
while(@dat = &dbnextrow($d)) {
    print "File Name: $dat[0]\t\tText:\n$dat[1]\n==================\n";
}


And ran it. Then I looked at the output, and there was some weird stuff
going on... So I looked at the table (via isql) and all seemed fine (I
could retrieve the text of files and they all looked fine).

So the dbwritetext call works fine. But there seems to be a bug when
selecting TEXT fields. What seems to happen is that data from the
previously retrieved text column is still there, so that when an entry
is shorter than the previous one the end part of the previous one is
still visible (there *is* a NULL byte in there, but that's not enough).
eg:
Row 1 has: 'this is a longer line with lots of data...'
Row 2 has: 'this is short'

when retrieving these two rows one after the other the second row prints:
'this is short\0er line with lots of data...'

I'm going to have to dig into this a little bit, and I'll be back with
a fix (certainly for sybperl 2.x, possibly also for 1.0xx) later today
(I hope :-)

Michael