如何将BLOB中的二进制文件倒出到操作系统中
1个回答
展开全部
tnsnames.ora中包含如下语句:
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
下面这个文件为lob2file.c,具体作用是将BLOB中的二进制文件倒出到操作系统中。
/*begin of lob2file.c*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <oci.h>
#include <ociextp.h>
#define DEFAULT_CHUNK_SIZE 1024
static int logging;
static char logfile[512];
static FILE *logfilep = NULL;
int lob2file ( OCILobLocator *a_lob, /* the LOB */
short lbind, /* LOB indicator */
char *path, /* file to write */
short pind, /* file indicator */
int plen, /* filename length */
char *lpath, /* logfile name */
short lpind, /* logfile indicator */
int lplen, /* logfile name length */
int logit, /* logging enabled? */
OCIExtProcContext *ctxt /* OCI Context */
)
{
sword errnum = 0;
OCIEnv *envhp = NULL;
OCISvcCtx *svchp = NULL;
OCIError *errhp = NULL;
char lobfile[512];
FILE *lobfilep = NULL;
/*
* If required, open the log file for writing
* Use the user provided logfile name if possible
* Otherwise, default the logfile to lob2file.log
*/
logging = logit;
if (logging)
{
if (lpind == -1 || lplen == 0 || lplen >= 512)
{
strcpy(logfile, "lob2file.log");
}
else
{
strncpy(logfile, lpath, lplen);
logfile[lplen] = '\0';
}
logfilep = fopen(logfile, "w");
if (logfilep == NULL)
{
if ((logfilep = fopen("lob2file.log", "w")) != NULL)
{
fprintf(logfilep, "Error: Unable to open logfile %s\n",
logfile);
fprintf(logfilep, "Error: errno = %d\n", errno);
}
}
}
/*
* Retrieve the environment, service context, and error handles
*/
if ((errnum = OCIExtProcGetEnv(ctxt, &envhp,
&svchp, &errhp)) != OCIEXTPROC_SUCCESS)
{
if (logging && logfilep != NULL)
{
fprintf(logfilep, "Error: Call to OCIExtProcGetEnv failed\n");
fprintf(logfilep, "Error: OCIExtProcGetEnv returned %d\n",
errnum);
fclose(logfilep);
return -1;
}
}
/*
* Verify that the user has provided a name for the output file
*/
if (pind == -1 || plen == 0)
{
char *errmsg = "Pathname is null or empty string";
if (logging && logfilep != NULL)
{
fprintf(logfilep, "Error: %s\n", errmsg);
fclose(logfilep);
}
errnum = 20001;
OCIExtProcRaiseExcpWithMsg(ctxt, errnum, (text *)errmsg,
strlen(errmsg));
return -1;
}
else /* Use the provided name */
{
strncpy(lobfile, path, plen);
lobfile[plen] = '\0';
}
/*
* Verify that the user has provided a valid LOB locator
*/
if (lbind == -1)
{
char *errmsg = "LOB locator is null";
if (logging && logfilep != NULL)
{
fprintf(logfilep, "Error: %s\n", errmsg);
fclose(logfilep);
}
errnum = 20002;
OCIExtProcRaiseExcpWithMsg(ctxt, errnum, (text *)errmsg,
strlen(errmsg));
return -1;
}
EXTPROC_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
)
(CONNECT_DATA =
(SID = PLSExtProc)
(PRESENTATION = RO)
)
)
下面这个文件为lob2file.c,具体作用是将BLOB中的二进制文件倒出到操作系统中。
/*begin of lob2file.c*/
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <oci.h>
#include <ociextp.h>
#define DEFAULT_CHUNK_SIZE 1024
static int logging;
static char logfile[512];
static FILE *logfilep = NULL;
int lob2file ( OCILobLocator *a_lob, /* the LOB */
short lbind, /* LOB indicator */
char *path, /* file to write */
short pind, /* file indicator */
int plen, /* filename length */
char *lpath, /* logfile name */
short lpind, /* logfile indicator */
int lplen, /* logfile name length */
int logit, /* logging enabled? */
OCIExtProcContext *ctxt /* OCI Context */
)
{
sword errnum = 0;
OCIEnv *envhp = NULL;
OCISvcCtx *svchp = NULL;
OCIError *errhp = NULL;
char lobfile[512];
FILE *lobfilep = NULL;
/*
* If required, open the log file for writing
* Use the user provided logfile name if possible
* Otherwise, default the logfile to lob2file.log
*/
logging = logit;
if (logging)
{
if (lpind == -1 || lplen == 0 || lplen >= 512)
{
strcpy(logfile, "lob2file.log");
}
else
{
strncpy(logfile, lpath, lplen);
logfile[lplen] = '\0';
}
logfilep = fopen(logfile, "w");
if (logfilep == NULL)
{
if ((logfilep = fopen("lob2file.log", "w")) != NULL)
{
fprintf(logfilep, "Error: Unable to open logfile %s\n",
logfile);
fprintf(logfilep, "Error: errno = %d\n", errno);
}
}
}
/*
* Retrieve the environment, service context, and error handles
*/
if ((errnum = OCIExtProcGetEnv(ctxt, &envhp,
&svchp, &errhp)) != OCIEXTPROC_SUCCESS)
{
if (logging && logfilep != NULL)
{
fprintf(logfilep, "Error: Call to OCIExtProcGetEnv failed\n");
fprintf(logfilep, "Error: OCIExtProcGetEnv returned %d\n",
errnum);
fclose(logfilep);
return -1;
}
}
/*
* Verify that the user has provided a name for the output file
*/
if (pind == -1 || plen == 0)
{
char *errmsg = "Pathname is null or empty string";
if (logging && logfilep != NULL)
{
fprintf(logfilep, "Error: %s\n", errmsg);
fclose(logfilep);
}
errnum = 20001;
OCIExtProcRaiseExcpWithMsg(ctxt, errnum, (text *)errmsg,
strlen(errmsg));
return -1;
}
else /* Use the provided name */
{
strncpy(lobfile, path, plen);
lobfile[plen] = '\0';
}
/*
* Verify that the user has provided a valid LOB locator
*/
if (lbind == -1)
{
char *errmsg = "LOB locator is null";
if (logging && logfilep != NULL)
{
fprintf(logfilep, "Error: %s\n", errmsg);
fclose(logfilep);
}
errnum = 20002;
OCIExtProcRaiseExcpWithMsg(ctxt, errnum, (text *)errmsg,
strlen(errmsg));
return -1;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询