使用ORADBI读取存储在BLOB字段里的多个文件,并还原到指定的路径下。下面是完整的代码://// read_blobfile。c - 读BLOBFILE的例子//内存泄漏检测// 在需要检测的地方放置语句:// _CrtDumpMemoryLeaks();// 以下3句的次序不能改变#define _CRTDBG_MAP_ALLOC#include#include// 包含唯一的ORADBI 头文件#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 tablecreate table TEST(BM VARCHAR2(10),NAME VARCHAR2(100),BIRTH DATE,DATA BLOB)tablespace USERSpctfree 10initrans 1maxtrans 255storage(initial 64Kminextents 1maxextents unlimited);====================================================*///// 显示如何把从BLOB字段读出数据并还原为文件//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;// 创建连接rc = ORA_connection_create( &con, ORADB_SERVICE, ORADB_LOGUSER, ORADB_PASSWORD, OCI_THREADED|OCI_OBJECT, FALSE, &err);assert(rc==ORC_SUCCESS);// 创建SQL, 只取一行记录: where rownum<2rc = ORA_sqlstmt_create( &stmt, con, "select BM,NAME,BIRTH,DATA from TEST where rownum<2", -1, 0, &err );assert(rc==ORC_SUCCESS);// 执行选取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)){// BMcol = 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);// NAMEcol = 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);// BIRTHcol = 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);// DATAcol = ORA_rowset_get_column_by_index(rs, 4, &err);assert(ORA_column_not_null(col));// 读取LOB字段数据, 写入文件:rc = ORA_column_read_lobfile(col, "c:\temp", &pp_fnames, &num_files, &err);assert(rc==ORC_SUCCESS);for(ui=0; ui
以上是我对于这个问题的解答,希望能够帮到大家。
全部