📄 ocidbclass.cpp
字号:
break;
}
}
StrCat(erros, "字段名为:[");
StrCat(erros, FieldName);
StrCat(erros, "] 的字段不存在!");
throw Exception(erros);
//return -2;
}
//----------------------------------------------------------------------------
int TOCIQuery::GetBLOBFieldByNameToSteam(char FieldName[600],Classes::TStream* Stream)
{
char erros[200]="";
for (int i=0;i<(*(OCI_CURSOR*)sel_cursor).selinfo.outputnums;i++)
{
if (stricmp((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].FieldName,FieldName)==0)
{
if( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Type == OCI_TYPECODE_BLOB )
{
ub4 blobdatalen;
ub4 amtp;
status = OCILobGetLength( DBHandle.svchp, DBHandle.errhp, (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].blob, (ub4*)&blobdatalen );
if( blobdatalen == 0 || status < 0 )
return -1;
(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value = (char*)malloc( blobdatalen );
amtp = blobdatalen ;
status = OCILobRead( DBHandle.svchp, DBHandle.errhp, (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].blob, &amtp,1,(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value,blobdatalen,0,0,0,(ub1) SQLCS_IMPLICIT );
if( status != OCI_SUCCESS )
{
free( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value );
(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value = 0;
throw Exception("BLOB字段读错误");
//return -1;
}
Stream->Write((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value , blobdatalen);
free( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value );
return 0;
}
else
{
StrCat(erros, "字段名为:[");
StrCat(erros, FieldName);
StrCat(erros, "] 的字段为非BLOB字段不适合此函数取值!");
throw Exception(erros);
//return -1;
}
break;
}
}
StrCat(erros, "字段名为:[");
StrCat(erros, FieldName);
StrCat(erros, "] 的字段不存在!");
throw Exception(erros);
//return -2;
}
//-----------------------------------------------------------------------------
int TOCIQuery::GetBLOBFieldByIndexToSteam(int idx,Classes::TStream* Stream)
{
char erros[200]="";
if (idx >= (*(OCI_CURSOR*)sel_cursor).selinfo.outputnums)
{
StrCat(erros, "字段号:[");
StrCat(erros, IntToStr(idx).c_str());
StrCat(erros, "]不存在!");
throw Exception(erros);
// return -1;
}
if( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Type != OCI_TYPECODE_BLOB )
{
StrCat(erros, "字段号:[");
StrCat(erros, IntToStr(idx).c_str());
StrCat(erros, "]为非BLOB字段不适合此函数取值!");
throw Exception(erros);
// return -1;
}
ub4 blobdatalen;
ub4 amtp;
status = OCILobGetLength( DBHandle.svchp, DBHandle.errhp, (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].blob, (ub4*)&blobdatalen );
if( blobdatalen == 0 || status < 0 )
return -1;
(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value = (char*)malloc( blobdatalen );
amtp = blobdatalen ;
status = OCILobRead( DBHandle.svchp, DBHandle.errhp, (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].blob, &amtp,1,(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value,blobdatalen,0,0,0,(ub1) SQLCS_IMPLICIT );
if( status != OCI_SUCCESS )
{
free( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value );
(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value = 0;
throw Exception("BLOB字段读错误");
//return 1;
}
Stream->Write((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value , blobdatalen);
free( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value );
return 0;
}
//-----------------------------------------------------------------------------
char* TOCIQuery::GetFieldValueByIndex(int idx)
{
char erros[200]="";
if (idx >= (*(OCI_CURSOR*)sel_cursor).selinfo.outputnums)
{
StrCat(erros, "字段号:[");
StrCat(erros, IntToStr(idx).c_str());
StrCat(erros, "] 不存在!");
throw Exception(erros);
//return "";
}
if( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Type == OCI_TYPECODE_BLOB )
{
ub4 blobdatalen;
status = OCILobGetLength( DBHandle.svchp, DBHandle.errhp, (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].blob, (ub4*)&blobdatalen );
if( blobdatalen == 0 || status < 0 )
return "blob";
else
return "BLOB";
}
return (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value;
}
WY_DEFINEINFO * TOCIQuery::Fields(int idx)
{
char erros[200]="";
if (idx >= (*(OCI_CURSOR*)sel_cursor).selinfo.outputnums)
{
StrCat(erros, "字段号:[");
StrCat(erros, IntToStr(idx).c_str());
StrCat(erros, "]不存在!");
throw Exception(erros);
// return -1;
}
if( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Type == OCI_TYPECODE_BLOB )
{
ub4 blobdatalen;
status = OCILobGetLength( DBHandle.svchp, DBHandle.errhp, (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].blob, (ub4*)&blobdatalen );
if( blobdatalen == 0 || status < 0 )
StrCopy((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value,"blob");
else
StrCopy((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Value,"BLOB");
}
return &(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx];
}
WY_DEFINEINFO * TOCIQuery::FieldByName(char FieldName[200])
{
char erros[200]="";
for (int i=0;i<(*(OCI_CURSOR*)sel_cursor).selinfo.outputnums;i++)
{
if (stricmp((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].FieldName,FieldName)==0)
{
if( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Type != OCI_TYPECODE_BLOB )
{
return &(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i];
}
else
{
ub4 blobdatalen;
status = OCILobGetLength( DBHandle.svchp, DBHandle.errhp, (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].blob, (ub4*)&blobdatalen );
if( blobdatalen == 0 || status < 0 )
StrCopy((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value,"blob");
else
StrCopy((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value,"BLOB");
return &(*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i];
}
break;
}
}
StrCat(erros, "字段名为:[");
StrCat(erros, FieldName);
StrCat(erros, "] 的字段不存在!");
throw Exception(erros);
}
char* TOCIQuery::GetFieldName(int idx)
{
char erros[200]="";
if (idx >= (*(OCI_CURSOR*)sel_cursor).selinfo.outputnums)
{
StrCat(erros, "字段号:[");
StrCat(erros, IntToStr(idx).c_str());
StrCat(erros, "] 不存在!");
throw Exception(erros);
//return "";
}
return (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].FieldName;
}
int TOCIQuery::GetFieldType(int idx)
{
char erros[200]="";
if (idx >= (*(OCI_CURSOR*)sel_cursor).selinfo.outputnums)
{
StrCat(erros, "字段号:[");
StrCat(erros, IntToStr(idx).c_str());
StrCat(erros, "] 不存在!");
throw Exception(erros);
//return "";
}
return (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[idx].Type;
}
//---------------------------------------------------------------------------
char* TOCIQuery::GetFieldValueByName(char FieldName[200])
{
char erros[200]="";
for (int i=0;i<(*(OCI_CURSOR*)sel_cursor).selinfo.outputnums;i++)
{
if (stricmp((*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].FieldName,FieldName)==0)
{
if( (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Type != OCI_TYPECODE_BLOB )
{
return (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].Value;
}
else
{
ub4 blobdatalen;
status = OCILobGetLength( DBHandle.svchp, DBHandle.errhp, (*(OCI_CURSOR*)sel_cursor).selinfo.outputinfo[i].blob, (ub4*)&blobdatalen );
if( blobdatalen == 0 || status < 0 )
return "blob";
else
return "BLOB";
}
break;
}
}
StrCat(erros, "字段名为:[");
StrCat(erros, FieldName);
StrCat(erros, "] 的字段不存在!");
throw Exception(erros);
//return NULL;
}
int TOCIQuery::SetParamValue(char * ParamName,Variant PutValue)
{
PARAStruct[csCount].CSname=ParamName;
PARAStruct[csCount].sybz=true;
PARAStruct[csCount].CSvalue=PutValue;
csCount++;
return 0;
}
int TOCIQuery::SetBLOBParamValueFromFile(char * ParamName,char *FileName)
{
PARAStruct[csCount].CSname=ParamName;
PARAStruct[csCount].CFilename=FileName;
PARAStruct[csCount].sybz=true;
PARAStruct[csCount].CStype=SQLT_BLOB;
csCount++;
return 0;
}
int TOCIQuery::SetBLOBParamValueFromstream(char * ParamName,TMemoryStream *stream)
{
stream->SaveToFile(&ParamName[1]);
PARAStruct[csCount].CSname=ParamName;
PARAStruct[csCount].CFilename=&ParamName[1];
PARAStruct[csCount].sybz=true;
PARAStruct[csCount].CStype=SQLT_BLOB;
csCount++;
return 0;
}
int TOCIQuery::BINParamValue()
{
status=0;
if (stricmp(FSQLType,"SQL_SELECT")!=0)
binstmthp=stmthp1 ;
else
binstmthp= selecthp;
if (csCount==0)
return status;
for (int i=0; i<csCount ;i++)
{
if (PARAStruct[i].sybz==true)
{
if (PARAStruct[i].CSvalue.VType==3) //--数字
{
PARAStruct[i].CSbndhp=(OCIBind *) 0;
int intvalue=PARAStruct[i].CSvalue.VInteger;
char intvalue1[8000];
// (char *) intvalue;
StrCopy(intvalue1,IntToStr(intvalue).c_str());
if (OCIBindByName( binstmthp, &PARAStruct[i].CSbndhp, errhp,
PARAStruct[i].CSname, (sb4) strlen(PARAStruct[i].CSname),
(dvoid *)intvalue1, (sb4)strlen(intvalue1)+1, SQLT_STR,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT) )
{
_OCIErrorGet( DBHandle,tmpbuf );
strcpy( tmpname, "OCIBindByName()" );
sprintf( DBErrMsg,"=>调用 %s 错误(%s)",tmpname,tmpbuf);
return OCI_ERROR;
}
intvalue=PARAStruct[i].CSvalue.VInteger;
}
//-----------------------------------------
if (PARAStruct[i].CSvalue.VType==7) //--时间
{
TTime datevalue=PARAStruct[i].CSvalue.VDate;
if (OCIBindByName( binstmthp, &PARAStruct[i].CSbndhp, errhp,
PARAStruct[i].CSname, (sb4) strlen(PARAStruct[i].CSname),
(dvoid *)&datevalue, (sb4)sizeof(datevalue), SQLT_DAT,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT) )
{
_OCIErrorGet( DBHandle,tmpbuf );
strcpy( tmpname, "OCIBindByName()" );
sprintf( DBErrMsg,"=>调用 %s 错误(%s)",tmpname,tmpbuf);
return OCI_ERROR;
}
}
//---------------------------------------
if (PARAStruct[i].CSvalue.VType==256) //--字符
{
char charvalue[800];
StrCopy(charvalue,PARAStruct[i].CSvalue.pcVal);
if (OCIBindByName( binstmthp, &PARAStruct[i].CSbndhp, errhp,
PARAStruct[i].CSname, (sb4) strlen(PARAStruct[i].CSname),
(dvoid *)charvalue, (sb4)strlen(charvalue)+1, SQLT_STR,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT) )
{
_OCIErrorGet( DBHandle,tmpbuf );
strcpy( tmpname, "OCIBindByName()" );
sprintf( DBErrMsg,"=>调用 %s 错误(%s)",tmpname,tmpbuf);
return OCI_ERROR;
}
}
//---------------------------------------------
if (PARAStruct[i].CStype==SQLT_BLOB) //--BLOB
{
if( OCIDescriptorAlloc( (dvoid*) envhp, (dvoid**) &(PARAStruct[i].CSblob),
(ub4) OCI_DTYPE_LOB, (size_t)0,(dvoid**)0 ) != OCI_SUCCESS )
{
_OCIErrorGet( DBHandle,tmpbuf );
strcpy( tmpname, "OCIDescriptorAlloc()" );
sprintf( DBErrMsg,"=>调用 %s 错误(%s)",tmpname,tmpbuf);
return OCI_ERROR;
}
if (OCIBindByName( binstmthp, &PARAStruct[i].CSbndhp, errhp,
PARAStruct[i].CSname, (sb4) strlen(PARAStruct[i].CSname),
(dvoid *)&PARAStruct[i].CSblob, (sb4)-1, SQLT_BLOB,
(dvoid *) 0, (ub2 *)0, (ub2 *)0,
(ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT) )
{
_OCIErrorGet( DBHandle,tmpbuf );
strcpy( tmpname, "OCIBindByName()" );
sprintf( DBErrMsg,"=>调用 %s 错误(%s)",tmpname,tmpbuf);
return OCI_ERROR;
}
}
}
}
return status;
}
char TOCIQuery::GetRowid()
{
OCIRowid *Rowid;
if (OCIDescriptorAlloc((dvoid *) envhp, (dvoid **) &(Rowid),
(ub4) OCI_DTYPE_ROWID, (size_t) 0, (dvoid **) 0))
{
return NULL;
}
status=0;
ub2 len=4000;
char ss[4000];
char ss1[4000];
status=OCIAttrGet (selecthp,
OCI_HTYPE_STMT,
(dvoid *)Rowid,
0,
OCI_ATTR_ROWID,
errhp);
if (status!=0)
{
_OCIErrorGet( DBHandle,tmpbuf );
strcpy( tmpname, "OCIBindByName()" );
sprintf( DBErrMsg,"=>调用 %s 错误(%s)",tmpname,tmpbuf);
return NULL;
}
//status=OCIRowidToChar(Rowid,(unsigned char*)ss,&len,errhp);
Move(ss,ss1,len);
return ss1[0];
}
//---------------------------------------------------------------------------------------
TOCIQuery::TOCIQuery()
{
StrCopy(FSQLType,"");
prefetch = 1 ;
}
//----------------------------------------------------------------------------
TOCIQuery::~TOCIQuery()
{
RowCount=0;
if( binstmthp!= 0 )
OCIHandleFree( binstmthp, OCI_HTYPE_STMT );
if (stricmp(FSQLType,"SQL_SELECT")==0)
FreeSelectInfo( &((*(OCI_CURSOR*)sel_cursor).selinfo));
FreeSel_cursor( (OCI_CURSOR *) sel_cursor );
}
//---------------------------------------------------------------------------
#pragma package(smart_init)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -