#!/usr/bin/perl -w

use lib qw(/home/thebrain/perllib/i686-linux);
use strict;
use DBI;
use DBD::Oracle qw(:ora_types);
use Data::Dumper;

my $db = DBI->connect(
	'DBI:Oracle:test.stephenc.theiqgroup.com',
	'iqc',
	'einstein',
	{
		RaiseError      => 0,
		PrintError      => 1,
		AutoCommit      => 0,
		ChopBlanks      => 1,
		LongReadLen     => 10000000
	}
) or die "Unable to establish connection with Oracle server: $DBI::errstr";

$db->do('CREATE TABLE foo (insnum NUMBER(3), value CLOB)');
$db->do('DELETE FROM foo');

$db->trace(8);

my $st = $db->prepare('INSERT INTO foo (insnum, value) VALUES (?,?)');

$st->bind_param(1, 1);
$st->bind_param(2, 1, { ora_type => ORA_CLOB, ora_field => 'value' } );
$st->execute; # Not OK -- writes unknown character sequence or throws ORA-24801

$st->bind_param(1, 2);
$st->bind_param(2, 'A', { ora_type => ORA_CLOB, ora_field => 'value' } );
$st->execute; # OK

$st->bind_param(1, 3);
$st->bind_param(2, 3, { ora_type => ORA_CLOB, ora_field => 'value' } );
$st->execute; # Not OK -- writes 'A' instead

$st->bind_param(1, 4);
$st->bind_param(2, 'B', { ora_type => ORA_CLOB, ora_field => 'value' } );
$st->execute; # OK

$st->bind_param(1, 5);
$st->bind_param(2, 5, { ora_type => ORA_CLOB, ora_field => 'value' } );
$st->execute; # Not OK -- writes 'B' instead

$db->trace(0);

$db->commit;

$st = $db->prepare('SELECT * FROM foo ORDER BY insnum');
$st->execute;
my %data;
while (my $rec = $st->fetch) {
	$data{$rec->[0]} = $rec->[1]
}
print Dumper(\%data);

$db->disconnect;
