How to read a file in an Oracle BLOB field

Source: Internet
Author: User
Tags assert printf stmt

Use ORADBI to read multiple files stored in a BLOB field and restore to a specified path.

Here's the complete code:

//


//READ_BLOBFILE.C-Read the blobfile example


//cheungmine@gmail.com//


//Memory leak detection


//Place the statement where needed to be detected:


//_CrtDumpMemoryLeaks ();


//The Order of the following 3 sentences cannot be changed


#define _CRTDBG_MAP_ALLOC


#include <stdlib.h>


#include <crtdbg.h>





//contains a unique ORADBI header file


#include ". /oradbi.h "





#ifdef _DEBUG


#pragma comment (lib, ". /oradbi_dll/debug/oradbid.lib ")


#else


#pragma comment (lib, ". /oradbi_dll/release/oradbi.lib ")


#endif








#define Oradb_service "CHEUNG"


#define Oradb_loguser "MINEUSR"


#define Oradb_password "Minepwd"





/*==================================================


--Create table


CREATE TABLE TEST


(


BM VARCHAR2 (10),


NAME VARCHAR2 (100),


Birth DATE,


DATA BLOB


)


tablespace USERS


Pctfree 10


Initrans 1


Maxtrans 255


Storage


  (


Initial 64K


minextents 1


Maxextents Unlimited


  );


====================================================*/





//


//shows how to read data from a BLOB field and revert to a file


//


void Select_blob_data ()


{


Lresult RC;


ora_error_t err;


ora_connection con = 0;


ora_sqlstmt stmt = 0;


Ora_rowset rs = 0;


Ora_column Col;


Ora_datetime odt;


Char *psz;


Char buf[30];


char **pp_fnames = 0;


ushort num_files = 0;


UShort UI;








//Create connection


rc = Ora_connection_create (&con, Oradb_service, Oradb_loguser, Oradb_password, oci_threaded| Oci_object, FALSE, &err);


assert (rc==orc_success);





//Create SQL, take only one line of records: where Rownum<2


rc = ora_sqlstmt_create (&stmt, con, "select Bm,name,birth,data from TEST where rownum<2",-1, 0, &er R);


assert (rc==orc_success);





//Executive selection


rc = Ora_sqlstmt_select (stmt, Mod_default, &rs, &err);


assert (rc==orc_success);





printf ("N BM NAME birth Datan---------------------------------------------------- --n ");





while (Ora_rowset_next (RS))


    {


//BM


col = Ora_rowset_get_column_by_index (RS, 1, &err);


assert (Ora_column_not_null (col));


ora_column_as_string (col, &psz, &err);


printf ("%s", psz);





//NAME


col = Ora_rowset_get_column_by_index (RS, 2, &err);


assert (Ora_column_not_null (col));


ora_column_as_string (col, &psz, &err);


printf ("%s", psz);





//Birth


col = Ora_rowset_get_column_by_index (RS, 3, &err);


assert (Ora_column_not_null (col));


Ora_column_as_datetime (col, &odt, &err);


ora_datetime_to_string (ODT, "Yyyy-mm-dd HH:UU:SS", buf, &err);


printf ("%s", buf);





//DATA


col = Ora_rowset_get_column_by_index (RS, 4, &err);


assert (Ora_column_not_null (col));





//Read LOB field data, write to file:


rc = ora_column_read_lobfile (col, "C:\Temp", &pp_fnames, &num_files, &err);


assert (rc==orc_success);





for (ui=0 ui<num_files; ui++) {


printf ("n%s", Pp_fnames[ui]);


        }


Ora_string_list_free (Pp_fnames, num_files);





printf ("n");


    }





//Release


Ora_rowset_free (RS);


Ora_sqlstmt_free (stmt);


ora_connection_free (con);


}





//


//Main program


//


int main (int argc, char* argv[])


{


Select_blob_data ();





_CrtDumpMemoryLeaks ();





return 0;


}

Download Source: http://download.csdn.net/source/589896

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.