This discussion is archived
9 Replies Latest reply: Dec 6, 2012 6:22 AM by yasser_egypt RSS

forms 6i save photo inside database table

yasser_egypt Newbie
Currently Being Moderated
dear people
I have table with 2 fields no number(10), photo_path varchar2(300)
these 2 fields have number and the path of fotos, and i form to look at these paths and find the photo and save it on database table.
by the way i am using forms 6i and db 8i
please help me how to do it


Edited by: yasser_egypt on Nov 22, 2012 6:25 AM

Edited by: yasser_egypt on Nov 22, 2012 6:43 AM
  • 1. Re: forms 6i save photo inside database table
    Mrucha Newbie
    Currently Being Moderated
    Hi,

    Use BLOB Datatypes

    See below Example:

    The following article presents a simple methods for importing a file into a BLOB datatype. First a directory object is created to point to the relevant filesystem directory.

    CREATE OR REPLACE DIRECTORY images AS 'C:\';

    Next we create a table to hold the BLOB.

    CREATE TABLE tab1 (
    id NUMBER,
    blob_data BLOB
    );

    We import the file into a BLOB datatype and insert it into the table.

    DECLARE
    l_bfile BFILE;
    l_blob BLOB;
    BEGIN
    INSERT INTO tab1 (id, clob_data)
    VALUES (1, empty_blob())
    RETURN clob_data INTO l_blob;

    l_bfile := BFILENAME('IMAGES', 'MyImage.gif');
    DBMS_LOB.fileopen(l_bfile, Dbms_Lob.File_Readonly);
    DBMS_LOB.loadfromfile(l_blob, l_bfile, DBMS_LOB.getlength(l_bfile));
    DBMS_LOB.fileclose(l_bfile);

    COMMIT;
    END;
  • 2. Re: forms 6i save photo inside database table
    KhaledFarouk Explorer
    Currently Being Moderated
    Hi : Yasser

    There is 2 methods to store pic for your application
    1- one to store pics at the database directly like the way of ' Mrucha'
    2- the way way you asked about to store the path at your database and when the forms open it query for the path
    and it could work using this code

    create image item field note it will be non database item
    create this code at your level you may try when new form or something like that
    read_image_file('d:\apps\pic\CLIENT_logo.gif','gif','CLIENT_logo');
    where d:\apps\pic\CLIENT_logo.gif is the image stored at your folder
    gif is the type of photoes
    CLIENT_logo is your image item


    Respectfully
    Khaled Farouk
  • 3. Re: forms 6i save photo inside database table
    yasser_egypt Newbie
    Currently Being Moderated
    dear i do what you write for me but it gives me error 40735
    i put this code under button because i want that when i press it it save the foto which i defined into the blob field in the database
    and also i tried to make this code database procedures but give me these errors
    ERROR at line 1:
    ORA-22288: file or LOB operation FILEOPEN failed
    The system cannot find the file specified.
    ORA-06512: at "SYS.DBMS_LOB", line 744
    ORA-06512: at "HR.BLOB_DATA", line 11
    ORA-06512: at line 1
    pls also i am not understand what does it mean
    INSERT INTO foto (id, foto)
    VALUES (1, empty_blob())
    RETURN foto INTO l_blob;

    what is this empty_blob???????????

    pls help me
    Yasser

    Edited by: yasser_egypt on Nov 28, 2012 5:22 AM
  • 4. Re: forms 6i save photo inside database table
    KhaledFarouk Explorer
    Currently Being Moderated
    hello : yasser


    try this steps
    1- create table with this script
    --------------------------------------------------------------------------------------------------
    --------------------------------------------------------------------------------------------------
    CREATE TABLE X ( IM_ID NUMBER, PIC BLOB);

    --------------------------------------------------------------------------------------------------
    --------------------------------------------------------------------------------------------------
    then
    2- create form based on the table via wizard
    --------------------------------------------------------------------------------------------------
    --------------------------------------------------------------------------------------------------
    3- create PUSH_BUTTON with this code in "when button pressed"
    DECLARE
    filename VARCHAR2(256);
    BEGIN
    filename := GET_FILE_NAME (File_Filter => 'jpg (*.jpg)|*.*|');
    READ_IMAGE_FILE(filename, 'jpg', 'pic');
    END;


    --------------------------------------------------------------------------------------------------
    --------------------------------------------------------------------------------------------------

    that should work ISA

    * note you should apply oracle_forms_patch18 to have the forms 6i working with images.
    * i've created a sample form & it's working fine. you can download it from this link
    [http://www.4shared.com/rar/O4fJlmSv/pic.html]

    Respectfully
    Khaled Farouk
  • 5. Re: forms 6i save photo inside database table
    yasser_egypt Newbie
    Currently Being Moderated
    dear khalid thanks for your answer, i already download your sample and i press the button and choose the file and save normal without any problem, but when i make query, it gives me this error

    SELECT ROWID,IM_ID,PIC FROM x
    ORA-00932: inconsistent datatypes: expected got

    that is mean what? and how to solve it.
    Best regards khalid
  • 6. Re: forms 6i save photo inside database table
    KhaledFarouk Explorer
    Currently Being Moderated
    Hello Yasser

    really i don't know the reason but it may be one of 2
    1- the oracle_forms_patch18
    2- the database version
    and so ishould ask you about.
    did you apply the oracle_forms_patch18 ? because it may be one cause of this isseu

    if you didn't apply this patch please apply it first to be sure it's not a forms isseu.

    if you don't have it you can download it from this link

    [http://www.epa.gov/storet/archive/Oracle_Forms_6i_Patch_18.exe]


    Respectfully
    Khaled Farouk
  • 7. Re: forms 6i save photo inside database table
    yasser_egypt Newbie
    Currently Being Moderated
    thanks so much dear khalid, it was really solve my problem and now work very good,
    i just have last question hope if you can answered to me
    if i have text file with the paths of imagine files, can i make for them load inside blob field in database table?
    is there any way to do this task?
  • 8. Re: forms 6i save photo inside database table
    KhaledFarouk Explorer
    Currently Being Moderated
    Hello Yasser

    It seems good to hear about your first isseu.

    for the second isseu i didn't try to it before but i think it can be done .

    but let us think about the previous code fro inserting images in blob .


    when i added a message with the filename it appears the path like that
    -------------------------------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------------------------------
    DECLARE
    filename VARCHAR2(256);
    BEGIN
    filename := GET_FILE_NAME (File_Filter => 'jpg (*.jpg)|*.*|');
    READ_IMAGE_FILE(filename, 'jpg', 'IMAGE6');
    MESSAGE(filename);MESSAGE(filename); ---- = D:\KHALED_WORK\hr_demo\pic.jpg
    END;
    -------------------------------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------------------------------
    so i think if you tried to
    1- create 2 temp table
    FIRST one 2 columns holding the images path and you record id x_temp
    second 2 columns holding the image blob and you record id x_temp2
    2- creat an update form on the x_temp2 contains
    1- image
    2- your id pk
    3- two push_button
    3- the push putton should be like cursor loop at the temp table and updates your image table.
    like
    declare
    cursor pic is
    select p_path , p_id from x_temp;
    begin
    for i in pic loop
    READ_IMAGE_FILE(p_path, 'jpg', 'IMAGE6');
    record_id := i.p_id;
    commit;
    next_record;
    end loop;
    end;
    4- the second push putton updates the main table from the x_temp2 where id = id


    -------------------------------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------------------------------

    i think that senario should work like that

    try it and hope it works

    Respectfully
    Khaled Farouk
  • 9. Re: forms 6i save photo inside database table
    yasser_egypt Newbie
    Currently Being Moderated
    yes it work very good, thank you so much it is great
    thanks khalid

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points