Re: inserting BLOB data

"Wagner, Chris (GEAE, CBTS)" <[email protected]> Mon, 17 Dec 2007 20:51:05 -0500
Newsgroups gmane.comp.db.mysql.perl
Organization GE Aircraft Engines \Cincinnati Bell
Message-ID <[email protected]>
Hi.  If all u want to do is locate things in the file, like say finding
out where "1 2 3 4" occurs, straight Perl is what u want.  However if u
want to be able to find those substrings *a lot*, then it may be worth
it to use MySQL.  That's because u'll have an index.  I was able to scan
a 19 MB file for a couple hundred matches in about 2 seconds with this
script. :)  Still wanna use MySQL?

This script should do what u want.

$string = $ARGV[0] or die;
$file = $ARGV[1] or die;
$offset = 0;
$chunksize = 65536;
$chaff = length($string) - 1;
open FILE, $file;
while (my $read = read FILE, $buffer, $chunksize) {
	last unless $read;
	#print "checking $read byte block at offset $offset\n";
	$buffer .= $save;
	$save = "";
	$position = 0;
	while (my $loc = index $buffer, $string, $position) {
	    last unless $loc >= 0;
	    print "found $string at offset ", $offset + $loc, "\n" if $loc >=0;
	    $position = $loc + $chaff + 1;
	}
	$save = substr $buffer, -$chaff, $chaff;
	#print "Saving chaff value of $save\n";
	$offset = $offset + $read - $chaff;
	undef $buffer;
}
close FILE;

The other scripts posted will take down ur machine with large files. :)



Kiran Annaiah wrote:
> 
> The contents of the file.
> The reason i wanted to insert the contents of the file into the table was so I could query the table and be able to extract out substrings of that particular content.
> The file basically has 550,000 columns of single digit numbers (except one/2 columns) represented in a single row.
> 0 12345 1 2 1 0 1 2 1 1 1 1 1 1 1 2 0 1 0 1 1 1 1 1 1 1 ...etc
> 
> I will have when all is done around 100,000 of such files.



-- 
Chris Wagner
CBTS
GE Aircraft Engines
[email protected]

-- 
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe:    http://lists.mysql.com/[email protected]