DBD-PrimeBase

 view release on metacpan or  search on metacpan

t/40blobs.t  view on Meta::CPAN

	#
	#   Create a new table
	#
	if (!$state) {
	    $def = TableDefinition($table,
				   ["id",   "INTEGER",      4, 0],
				   ["name", "BLOB",     $size, 0]);
	    print "Creating table:\n$def\n";
	}
	Test($state or $dbh->do($def))
	    or DbiError($dbh->err, $dbh->errstr);


	#
	#  Create a blob
	#
	my ($blob, $qblob) = "";
	if (!$state) {
	    my $b = "";
	    # PrimeBase Change:
	    # The idea of inserting blob data as a quoted string is some what dubious
	    # but if you are going to do it you must be sure that it doesn't contain 
	    # null characters. Hence start at $j = 1 not $j = 0.
	    for ($j = 1;  $j < 256;  $j++) {
			$b .= chr($j);
	    }
	    for ($i = 0;  $i < $size;  $i++) {
			$blob .= $b;
	    }
	    if ($mdriver eq 'pNET') {
			# Quote manually, no remote quote
			$qblob = eval "DBD::" . $dbdriver . "::db->quote(\$blob)";
	    } else {
			$qblob = $dbh->quote($blob);
	    }
	}

	# PrimeBase Change:
	# PrimeBase limits the size of the data returned  to LongReadLen bytes.
	$dbh->{LongReadLen} = 40000;

	#
	#   Insert a row into the test table.......
	#
	my($query);
	if (!$state) {
	    $query = "INSERT INTO $table VALUES(1, $qblob)";
	    if ($ENV{'SHOW_BLOBS'}  &&  open(OUT, ">" . $ENV{'SHOW_BLOBS'})) {
		print OUT $query;
		close(OUT);
	    }
	}
        Test($state or $dbh->do($query))
	    or DbiError($dbh->err, $dbh->errstr);

	#
	#   Now, try SELECT'ing the row out.
	#
	
	
	Test($state or $cursor = $dbh->prepare("SELECT * FROM $table"
					       . " WHERE id = 1"))
	       or DbiError($dbh->err, $dbh->errstr);

	Test($state or $cursor->execute)
	       or DbiError($dbh->err, $dbh->errstr);

	Test($state or (defined($row = $cursor->fetchrow_arrayref)))
	    or DbiError($cursor->err, $cursor->errstr);


	Test($state or (@$row == 2  &&  $$row[0] == 1  &&  $$row[1] eq $blob))
	    or (ShowBlob($blob),
		ShowBlob(defined($$row[1]) ? $$row[1] : ""));

	Test($state or $cursor->finish)
	    or DbiError($cursor->err, $cursor->errstr);

	Test($state or undef $cursor || 1)
	    or DbiError($cursor->err, $cursor->errstr);

	#
	#   Finally drop the test table.
	#
	Test($state or $dbh->do("DROP TABLE $table"))
	    or DbiError($dbh->err, $dbh->errstr);
    }
}



( run in 0.910 second using v1.01-cache-2.11-cpan-39bf76dae61 )