
set serverout on size unlimited;
exec dbms_java.set_output(2000000);
set define off

select JDBMS_JACKSUM.GET_CHECKSUM(JDBMS_LOB.FILE_TO_BLOB('H:\myopensource\oracle-jutils\doc', 'oracle-jutils.xml.chm'),
	'crc32',
	8,--JDBMS_JACKSUM.ENCODING_HEX_UPPERCASE
	null,--separator
	'#CHECKSUM',-- put a standard output fomrat
	-1,
	null) as CRC32
from dual;

select JDBMS_JACKSUM.GET_CHECKSUM(JDBMS_LOB.FILE_TO_BLOB('H:\myopensource\oracle-jutils\doc', 'oracle-jutils.xml.chm'),
	'crc32',
	8,--JDBMS_JACKSUM.ENCODING_HEX_UPPERCASE
	null,--separator
	'filesize = #FILESIZE crc32 = #CHECKSUM',-- put a standard output fomrat
	-1,
	null)
from dual;

select JDBMS_JACKSUM.GET_CHECKSUM('oracle-jutils is just cool',
	'md5',
	8,--JDBMS_JACKSUM.ENCODING_HEX_UPPERCASE
	null,--separator
	'#CHECKSUM',-- put a standard output fomrat
	-1,
	null) as "md5"
from dual;


-- oupss so you want to build clickable edk url ?
select replace(JDBMS_JACKSUM.GET_CHECKSUM('H:\Incoming',
											'oracle-jutils.xml.chm',
											'ed2k',
											1,--JDBMS_JACKSUM.ENCODING_HEX_UPPERCASE
											null,--separator
											'<a href="ed2k://|file|#FILENAME|#FILESIZE|#FINGERPRINT|/">#FILENAME</a>',
											-1,
											null),
		'H:\Incoming',
		'') as ed2k_HTML_URL
from dual;

-- Test overloaded and simplified checksum fucntions
select JDBMS_JACKSUM.GET_CHECKSUM(JDBMS_LOB.FILE_TO_BLOB('H:\myopensource\oracle-jutils\doc', 'oracle-jutils.xml.chm'), 'crc32') as crc32 from dual;
select JDBMS_JACKSUM.GET_CHECKSUM('H:\Incoming', 'oracle-jutils.xml.chm', 'crc32') as crc32 from dual;
select JDBMS_JACKSUM.GET_CHECKSUM('Tell me what''s my checksum ;-p', 'crc32') as crc32 from dual;


-- Get the list of Jacksum algorithms
select * from VW_JACKSUM_ALGOS;

select substr(name, 1, 3) "Alg.",
count(*) from VW_JACKSUM_ALGOS "Freq."
group by substr(name, 1, 3);

select substr(name, 1, 3) "Alg.",
count(*) from VW_JACKSUM_ALGOS "Freq."
group by substr(name, 1, 3)
having count(*) > 1;

-- compare two methods for crc32 computations
set timing on
select JDBMS_JACKSUM.GET_CHECKSUM(JDBMS_LOB.FILE_TO_BLOB('H:\myopensource\oracle-jutils\doc', 'oracle-jutils.xml.chm'),
JDBMS_LOB.FILE_TO_BLOB('H:\myopensource\oracle-jutils\doc', 'oracle-jutils.xml.chm'),
'crc32') as crc32 from dual;

select JDBMS_CHECKSUM.GET_CRC32(JDBMS_LOB.FILE_TO_BLOB('H:\myopensource\oracle-jutils\doc', 'oracle-jutils.xml.chm'),
JDBMS_LOB.FILE_TO_BLOB('H:\myopensource\oracle-jutils\doc', 'oracle-jutils.xml.chm')) as crc32 from dual;