UPDATE t_video
SET video = obj1
WHERE id=1;
EXCEPTION
WHEN ordsys.ordvideoexceptions.description_is_not_set THEN
dbms_output.put_line('Description: NOT SET');
END;
/
-- try the previous anonymous block again to
-- make sure that no exception is raised
-- try getting the format
DECLARE
obj ordsys.ordvideo;
BEGIN
SELECT video
INTO obj
FROM t_video
WHERE id = 1;
-- access methods
dbms_output.put_line('METHODS');
dbms_output.put_line('-------');
dbms_output.put_line('Format: '|| obj.getFormat);
EXCEPTION
WHEN ordsys.ordvideoexceptions.video_format_is_null THEN
dbms_output.put_line('Format: NOT SET');
END;
/
-- set all the attributes
DECLARE
obj1 ordsys.ordvideo;
ctx RAW(4000) := NULL;
BEGIN
SELECT video
INTO obj1
FROM t_video
WHERE id = 1
FOR UPDATE;
-- set description
obj1.setDescription('Video from a BFILE');
-- set mimetype
obj1.setMimeType('video/x-quicktime');
-- set source
obj1.setSource('FILE', 'VIDEODIR','sphere.mpg');
-- import data
obj1.import(ctx);
-- set video attributes
obj1.setKnownAttributes('MOOV', 400, 300, 1024, 10, 3600, 36000, 'NONE', 256,
28000);
UPDATE t_video
SET video = obj1
WHERE id = 1;
END;
/
-- try again and display different attributes
DECLARE
obj ordsys.ordvideo;
width INTEGER;
height INTEGER;
ctx RAW(4000) := NULL;
BEGIN
SELECT video
INTO obj
FROM t_video
WHERE id = 1;
-- use SQL statements to access length, mimetype and commentlength
SELECT t.video.getMimeType() MimeType
FROM t_video t
WHERE t.id = 1;
SELECT t.video.getContentLength()
FROM t_video t
WHERE t.id = 1;
SELECT t.video.getCommentLength()
FROM t_video t
WHERE t.id = 1;
-- now set the source for 2 rows
-----------------------------------------------------------------
-- NOTE THAT VIDEODIR has been defined and the appropriate video
-- file exists in the directory
--
-- If you are using URL then make sure that the specified URL
-- exists and that the video file is accessible from it
-----------------------------------------------------------------
DECLARE
obj1 ordsys.ordvideo;
obj2 ordsys.ordvideo;
BEGIN
SELECT video
INTO obj1
FROM t_video
WHERE id = 1
FOR UPDATE;
SELECT video
INTO obj2
FROM t_video
WHERE id = 2
FOR UPDATE;
UPDATE t_video
SET video = obj2
WHERE id=2;
COMMIT;
END;
/
-- check content lengths and also method not implemented exception
DECLARE
obj ordsys.ordvideo;
ctx RAW(4000) := NULL;
BEGIN
SELECT video
INTO obj
FROM t_video
WHERE id = 1 ;
dbms_output.put_line(obj.getSource);
dbms_output.put_line(obj.getContentLength(ctx));
EXCEPTION
WHEN ordsys.ordvideoexceptions.method_not_supported THEN
dbms_output.put_line('Content length not available for this source');
END;
/
-- check content lengths and also check for
-- source plugin exceptio exception
-- with the current scenario, it means that the
-- method is not implemented
DECLARE
obj2 ordsys.ordvideo;
ctx RAW(4000) := NULL;
BEGIN
SELECT video
INTO obj2
FROM t_video
WHERE id = 2;
dbms_output.put_line(obj2.getSource);
dbms_output.put_line(obj2.getContentLength(ctx));
EXCEPTION
WHEN ordsys.ordsourceexceptions.source_plugin_exception THEN
dbms_output.put_line('Source plugin raised an exception');
WHEN OTHERS THEN
dbms_output.put_line('EXCEPTION CAUGHT');
END;
/
-- import data from both the sources
-----------------------------------------------------
-- All the methods from this point on will only be useful
-- and will not raise exception if the data has been
-- made available
-----------------------------------------------------
DECLARE
obj1 ordsys.ordvideo;
obj2 ordsys.ordvideo;
ctx RAW(4000) := NULL;
BEGIN
SELECT video
INTO obj1
FROM t_video
WHERE id = 1
FOR UPDATE;
SELECT video
INTO obj2
FROM t_video
WHERE id = 2
FOR UPDATE;
dbms_output.put_line(obj1.getSource);
IF obj1.source.isLocal THEN
dbms_output.put_line('OBJ1: Data is local');
ELSE
dbms_output.put_line('OBJ1: Data is external');
END IF;
obj1.import(ctx);
dbms_output.put_line(obj1.getContentLength(ctx));
IF obj1.source.isLocal THEN
dbms_output.put_line('OBJ1: Data is local');
ELSE
dbms_output.put_line('OBJ1: Data is external');
END IF;
dbms_output.put_line(obj2.getSource);
IF obj2.source.isLocal THEN
dbms_output.put_line('OBJ2: Data is local');
ELSE
dbms_output.put_line('OBJ2: Data is external');
END IF;
obj2.import(ctx);
dbms_output.put_line(obj2.getContentLength(ctx));
IF obj2.source.isLocal THEN
dbms_output.put_line('OBJ2: Data is local');
ELSE
dbms_output.put_line('OBJ2: Data is external');
END IF;
UPDATE t_video
SET video = obj1
WHERE id = 1;
UPDATE t_video
SET video = obj2
WHERE id = 2;
COMMIT;
END;
/
-- INSTALL YOUR OWN FORMAT PLUGIN
-- 1. log onto ordplugins/<ordplugins_password>
-- 2. create the type ... see fplugins.sql and fpluginb.sql
-- 3. grant privs to public so that the plugin is visible
-- to all the users
set serveroutput on;
DECLARE
obj ordsys.ordvideo;
BEGIN
SELECT video
INTO obj
FROM t_video
WHERE id = 2
FOR UPDATE;
-- set description
obj.setDescription('Video from a BFILE');
-- set mimetype
obj.setMimeType('video/x-quicktime');
UPDATE t_video
SET VIDEO = obj
WHERE id=2;
END;
/
DECLARE
obj ordsys.ordvideo;
BEGIN
SELECT video
INTO obj
FROM t_video
WHERE id = 2
FOR UPDATE;
obj.setFormat('DEMO');
dbms_output.put_line('FORMAT NOW IS: '||obj.getFormat);
UPDATE t_video
SET video = obj
WHERE id=2;
COMMIt;
END;
/
-- get all stored attributes
DECLARE
obj ordsys.ordvideo;
width INTEGER;
height INTEGER;
ctx RAW(4000) := NULL;
BEGIN
SELECT video
INTO obj
FROM t_video
WHERE id = 2;
-- invoke plugin to get attributes
DECLARE
obj ordsys.ordvideo;
width INTEGER;
height INTEGER;
outdata RAW(4000);
retdata RAW(4000);
ctx RAW(4000) := NULL;
BEGIN
SELECT video
INTO obj
FROM t_video
WHERE id = 2;
-- get attributes by name
dbms_output.put_line('Copyright: '||obj.getAttribute(ctx, 'Copyright'));
dbms_output.put_line('Owner: '||obj.getAttribute(ctx, 'Owner'));
-- send a command to be processed
retdata := obj.processVideoCommand(ctx, 'increment','4', outdata);
dbms_output.put_line('Result of incrementing 4: '||
utl_raw.cast_to_varchar2(outdata));