#include "yqrydata.h"
#include <process.h>
#pragma comment(lib,"ocidbtools.lib")
int type_test()
{
RDataItem item={0};
printf("size of RDataItem:%zd\n",sizeof(item));
return 0;
}
int SetDataSetItem(pOCIDataSet dataset,pColItem pcol,pDataItem pdata,int col_pos)
{
int col_index=0;
OCIDefine* pdef=(OCIDefine*)0;
sb2 default_value=0;
if(!dataset||!pcol||!pdata) return -1;
pcol->default_value=0;
switch((pcol)->type) {
case SQLT_RDD:
{
//rowid.
if(OCIDescriptorAlloc(dataset->connect->env,
(dvoid**)&pdata->var.var_prowid,
(ub4)OCI_DTYPE_ROWID,
(size_t)0,
(dvoid**)0)!=OCI_SUCCESS) return -1;
if(OCIDefineByPos(dataset->stmt,
&pdef,
dataset->err,
col_pos,
(dvoid*)&pdata->var.var_prowid,
(sword)(pcol)->size,
SQLT_RDD,
(dvoid*)(((pcol)->isnull_flag!=0)?&(pcol->default_value):0),
(ub2*)0,
(ub2*)0,
OCI_DEFAULT)!=OCI_SUCCESS) return -1;
} break;
case SQLT_DAT:
{
//SQLT_DAT : date
if(OCIDefineByPos(dataset->stmt,
&pdef,
dataset->err,
col_pos,
(dvoid*)&pdata->var.var_date,
(sword)(pcol)->size,
SQLT_ODT,
(dvoid*)(((pcol)->isnull_flag!=0)?&(pcol->default_value):0),
(ub2*)0,
(ub2*)0,
OCI_DEFAULT)!=OCI_SUCCESS) return -1;
} break;
case SQLT_TIMESTAMP_TZ:
{
if(OCIDescriptorAlloc(dataset->connect->env,
(dvoid**)&pdata->var.var_ptimestamp,
OCI_DTYPE_TIMESTAMP_TZ,
(size_t)0,
(dvoid**)0)!=OCI_SUCCESS) return -1;
if(OCIDefineByPos(dataset->stmt,
&pdef,
dataset->err,
col_pos,
(dvoid*)&pdata->var.var_ptimestamp,
(sword)(pcol)->size,
(pcol)->type,
(dvoid*)(((pcol)->isnull_flag!=0)?&(pcol->default_value):0),
(ub2*)0,
(ub2*)0,
OCI_DEFAULT)!=OCI_SUCCESS) return -1;
} break;
case SQLT_TIMESTAMP:
{
//SQLT_TIMESTAMP : timestamp
if(OCIDescriptorAlloc(dataset->connect->env,
(dvoid**)&pdata->var.var_ptimestamp,
OCI_DTYPE_TIMESTAMP,
(size_t)0,
(dvoid**)0)!=OCI_SUCCESS) return -1;
if(OCIDefineByPos(dataset->stmt,
&pdef,
dataset->err,
col_pos,
(dvoid*)&pdata->var.var_ptimestamp,
(sword)(pcol)->size,
(pcol)->type,
(dvoid*)(((pcol)->isnull_flag!=0)?&(pcol->default_value):0),
(ub2*)0,
(ub2*)0,
OCI_DEFAULT)!=OCI_SUCCESS) return -1;
} break;
case SQLT_AFC://SQLT_AFC-asci char: char(n)
case SQLT_CHR:
(pdata)->var.var_plt=malloc(sizeof(char)*((pcol)->size+1));
if(!(pdata)->var.var_plt) {
printf("var_plt malloc failed.\n");
return -1;
}
memset((pdata)->var.var_plt,0x00,_msize((pdata)->var.var_plt)/sizeof(char));
dataset->debug.app_mem_alloc_times++;
dataset->debug.app_mem_bytes+=pcol->size+1;
if(OCIDefineByPos(dataset->stmt,
&pdef,
dataset->err,
col_pos,
(dvoid*)(pdata)->var.var_plt,
(sword)(pcol)->size,
(pcol)->type,
(dvoid*)(((pcol)->isnull_flag!=0)?&(pcol->default_value):0),
(ub2*)0,
(ub2*)0,
OCI_DEFAULT)!=OCI_SUCCESS) return -1;
break;
case SQLT_NUM:
{
if(OCIDefineByPos(dataset->stmt,
&pdef,
dataset->err,
col_pos,
(dvoid*)&(pdata)->var.var_num,
(sword)(pcol)->size,
SQLT_VNU,
(dvoid*)(((pcol)->isnull_flag!=0)?&(pcol->default_value):0),
(ub2*)0,
(ub2*)0,
OCI_DEFAULT)!=OCI_SUCCESS) return -1;
} break;
case SQLT_CLOB:
{
if(OCIDescriptorAlloc(dataset->connect->env,
(dvoid**)&pdata->var.var_pclob,
OCI_DTYPE_LOB,
0,
NULL)!=OCI_SUCCESS) return -1;
if(OCILobCreateTemporary(dataset->connect->svrctx,
dataset->err,
pdata->var.var_pclob,
OCI_DEFAULT,
SQLCS_IMPLICIT,
OCI_TEMP_CLOB,
FALSE,
OCI_DURATION_SESSION)!=OCI_SUCCESS) return -1;
if(OCIDefineByPos(dataset->stmt,
&pdef,
dataset->err,
col_pos,
(dvoid*)&pdata->var.var_pclob,
(sword)(pcol)->size,
(pcol)->type,
(dvoid*)(((pcol)->isnull_flag!=0)?&(pcol->default_value):0),
(ub2*)0,
(ub2*)0,
OCI_DEFAULT)!=OCI_SUCCESS) return -1;
} break;
default:
printf("OCI data type:%d,required modification.\n",
(pcol)->type);
}
return 0;
}
int SetDataSetItem_MultiRows(pOCIDataSet dataset,pColItem pcol,pDataItem pdata,int col_pos,int fetch_rows,int column_count)
{
int col_index=0;
sb2 default_value=0;
if(!dataset||!pcol||!pdata) return -1;
pcol->default_value=0;
pcol->pdef=(OCIDefine*)0;
switch((pcol)->type) {
case SQLT_RDD:
{
//rowid.
for(int index=0;index<fetch_rows;index++)
{
//为每一行分配标识符
if(OCIDescriptorAlloc(dataset->connect->env,
(dvoid**)&(pdata+index*column_count)->var.var_prowid,
(ub4)OCI_DTYPE_ROWID,
(size_t)0,
(dvoid**)0)!=OCI_SUCCESS) {
return -1;
}
}
if(OCIDefineByPos(dataset->stmt,
&pcol->pdef,
dataset->err,
col_pos,
(dvoid*)&pdata->var.var_prowid,
(sword)(pcol)->size,
SQLT_RDD,
(dvoid*)(((pcol)->isnull_flag!=0)?pcol->default_list:0),
(ub2*)0,
(ub2*)0,
OCI_DEFAULT)!=OCI_SUCCESS) {
return -1;
}
//指定是数组绑定
if(OCIDefineArrayOfStruct(pcol->pdef,dataset->err,sizeof(RODITEM)*column_count,(((pcol)->isnull_fla