📄 dirpath.c
字号:
if (col->scale != 0)
{
OCI_CALL2
(
res, dp->con,
OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &col->scale, sizeof(col->scale),
(ub4) OCI_ATTR_SCALE, dp->con->err)
)
}
/* set column date/time format attribute */
if ((res == TRUE) && (dpcol->type != OCI_DDT_NUMBER) &&
(dpcol->format != NULL) && (dpcol->format[0] != 0))
{
osize = -1;
ostr = OCI_GetInputMetaString(dpcol->format, &osize);
OCI_CALL2
(
res, dp->con,
OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
(dvoid *) ostr, (ub4) osize,
(ub4) OCI_ATTR_DATEFORMAT, dp->con->err)
)
OCI_ReleaseMetaString(ostr);
}
#ifdef OCI_CHARSET_UNICODE
/* setup Unicode mode for Unicode user data */
if (dpcol->type == OCI_DDT_TEXT)
{
ub2 csid = OCI_UTF16ID;
OCI_CALL2
(
res, dp->con,
OCIAttrSet((dvoid *) hattr, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &csid, (ub4) sizeof(csid),
(ub4) OCI_ATTR_CHARSET_ID, dp->con->err)
)
}
#endif
/* free param handle */
OCIDescriptorFree(hattr, OCI_DTYPE_PARAM);
}
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_DirPathPrepare
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_DirPathPrepare(OCI_DirPath *dp)
{
boolean res = TRUE;
ub4 i;
OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_NOT_PREPARED, FALSE);
/* prepare direct path operation */
OCI_CALL2
(
res, dp->con,
OCIDirPathPrepare(dp->ctx, dp->con->cxt, dp->con->err)
)
/* allocate column array handle */
if (res == TRUE)
{
res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) dp->ctx,
(dvoid **) (void *) &dp->arr,
(ub4) OCI_HTYPE_DIRPATH_COLUMN_ARRAY,
(size_t) 0, (dvoid **) NULL));
}
/* allocate stream handle */
if (res == TRUE)
{
res = (OCI_SUCCESS == OCI_HandleAlloc((dvoid *) dp->ctx,
(dvoid **) (void *) &dp->strm,
(ub4) OCI_HTYPE_DIRPATH_STREAM,
(size_t) 0, (dvoid **) NULL));
}
/* check the number of rows allocated */
if (res == TRUE)
{
ub4 size = sizeof(dp->nb_rows);
OCI_CALL2
(
res, dp->con,
OCIAttrGet(dp->arr, OCI_HTYPE_DIRPATH_COLUMN_ARRAY, &dp->nb_rows,
&size, OCI_ATTR_NUM_ROWS, dp->con->err)
)
dp->nb_cur = dp->nb_rows;
}
/* now, we need to allocate internal buffers */
if (res == TRUE)
{
for (i = 0; i < dp->nb_cols; i++)
{
OCI_DirPathColumn *col = &dp->cols[i];
/* data buffers */
col->data = (ub1 *) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY, col->bufsize,
dp->nb_cur, TRUE);
if (col->data == NULL)
{
res = FALSE;
break;
}
/* data sizes */
col->lens = (ub4 *) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY,sizeof(ub4),
dp->nb_cur, TRUE);
if (col->lens == NULL)
{
res = FALSE;
break;
}
/* data flags */
col->flags = (ub1 *) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY, sizeof(ub1),
dp->nb_cur, TRUE);
if (col->flags == NULL)
{
res = FALSE;
break;
}
}
}
if (res == TRUE)
dp->status = OCI_DPS_PREPARED;
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_DirPathSetEntry
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_DirPathSetEntry(OCI_DirPath *dp, unsigned int row,
unsigned int index, void *value,
unsigned int size, boolean complete)
{
boolean res = TRUE;
OCI_DirPathColumn *dpcol = NULL;
OCI_Column *col = NULL;
ub1 *data;
ub1 flag;
OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, FALSE);
OCI_CHECK_BOUND(dp->con, index, 1, dp->nb_cols, FALSE);
OCI_CHECK_BOUND(dp->con, row, 1, dp->nb_cur, FALSE);
dpcol = &dp->cols[index-1];
col = &dp->typinf->cols[dpcol->index];
/* check size */
if (size > dpcol->maxsize)
size = (unsigned int) dpcol->maxsize;
/* setup column flag */
if (value == NULL)
{
flag = OCI_DIRPATH_COL_NULL;
}
else if (complete == TRUE)
{
flag = OCI_DIRPATH_COL_COMPLETE;
}
else
{
flag = OCI_DIRPATH_COL_PARTIAL;
}
/* for character based column, parameter size was the number of characters */
if (dpcol->sqlcode == SQLT_CHR)
{
size *= sizeof(dtext);
}
/* get internal data cell */
data = ((ub1 *) dpcol->data) + ((row-1) * dpcol->bufsize);
#if defined(OCI_CHECK_DATASTRINGS)
/* we weed to pack the buffer if wchar_t is 4 bytes */
if (dpcol->type == OCI_DDT_TEXT)
{
int osize = -1;
OCI_GetOutputString(value, data, &size, sizeof(dtext), sizeof(odtext));
}
else
#endif
#if defined(OCI_USERDATA_UNICODE)
/* input Unicode numeric values causes oracle conversion error.
so, let's convert them to ansi */
if (dpcol->type == OCI_DDT_OTHERS)
{
size = (int) wcstombs((char *) data, value, dpcol->bufsize - 1);
}
else
#endif
/* if a format was provided for a numeric column, we convert the input
buffer to a OCINumber */
if (dpcol->type == OCI_DDT_NUMBER)
{
OCINumber *num = (OCINumber *) data;
res = OCI_NumberConvertStr(dp->con, num, (dtext *) value, size,
dpcol->format, dpcol->format_size);
if (res == TRUE)
{
size = (unsigned int) num->OCINumberPart[0];
}
}
else
{
#if defined(OCI_CHARSET_MIXED)
/* with mixed charset builds, OCIDirPrepare() causes a segfault if the
attribute OCI_ATTR_CHARSET_ID has been set with OCI_UTF16.
In the OCILIB direct path implementation, the code is the same for
Unicode and mixed charset. This only difference is the
environment mode set of UTF16...
So let's convert the data back to ANSI until Oracle corrects this bug */
if (dpcol->type == OCI_DDT_TEXT)
{
size = (int) wcstombs((char *) data, value, dpcol->bufsize - 1);
}
else
#endif
{
memcpy(data, value, size);
}
}
dpcol->lens[row-1] = size;
dpcol->flags[row-1] = flag;
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_DirPathReset
* ------------------------------------------------------------------------ */
boolean OCI_API OCI_DirPathReset(OCI_DirPath *dp)
{
boolean res = TRUE;
OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
/* reset array */
OCI_CALL2
(
res, dp->con,
OCIDirPathColArrayReset(dp->arr, dp->con->err)
)
/* reset stream */
OCI_CALL2
(
res, dp->con,
OCIDirPathStreamReset(dp->strm, dp->con->err)
)
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_DirPathConvert
* ------------------------------------------------------------------------ */
unsigned int OCI_API OCI_DirPathConvert(OCI_DirPath *dp)
{
unsigned int res = OCI_DPR_COMPLETE;
OCI_DirPathColumn *dpcol = NULL;
sword ret = OCI_SUCCESS;
ub1 *data;
ub4 size;
ub1 flag;
ub4 i, j;
OCI_CHECK_PTR(OCI_IPC_DIRPATH, dp, FALSE);
OCI_CHECK_DIRPATH_STATUS(dp, OCI_DPS_PREPARED, FALSE);
dp->err_col = -1;
dp->nb_prcsd = 0;
/* set entries */
for (i = 0; (i < dp->nb_cols) && (res == TRUE); i++)
{
dpcol = &(dp->cols[i]);
for (j = 0; (j < dp->nb_cur) && (res == TRUE); j++)
{
/* get internal data cell */
data = ((ub1 *) dpcol->data) + (j * dpcol->bufsize);
size = dpcol->lens[j];
flag = dpcol->flags[j];
if (dpcol->sqlcode == SQLT_NUM)
{
OCINumber *num = (OCINumber *) data;
data = &num->OCINumberPart[1];
}
/* set entry value */
OCI_CALL2
(
res, dp->con,
OCIDirPathColArrayEntrySet(dp->arr, dp->con->err, (ub4) j,
(ub2) (i), (ub1*) data,
(ub4) size, flag)
)
}
}
if (res == TRUE)
{
/* conversion */
ret = OCIDirPathColArrayToStream(dp->arr, dp->ctx, dp->strm, dp->con->err,
(ub4) dp->nb_cur, (ub4) 0);
switch (ret)
{
case OCI_SUCCESS:
{
dp->status = OCI_DPS_CONVERTED;
dp->nb_prcsd = dp->nb_cur;
dp->err_col = -1;
dp->err_row = -1;
res = OCI_DPR_COMPLETE;
break;
}
case OCI_ERROR:
{
res = OCI_DPR_ERROR;
OCI_ExceptionOCI(dp->con->err, dp->con, NULL);
break;
}
case OCI_CONTINUE:
{
res = OCI_DPR_FULL;
break;
}
case OCI_NEED_DATA:
{
res = OCI_DPR_PARTIAL;
break;
}
}
if (ret != OCI_SUCCESS)
{
ub4 size;
size = sizeof(dp->nb_prcsd);
OCIAttrGet(dp->arr, OCI_HTYPE_DIRPATH_COLUMN_ARRAY, &dp->nb_prcsd,
&size, OCI_ATTR_NUM_ROWS, dp->con->err);
size = sizeof(dp->err_col);
OCIAttrGet(dp->arr, OCI_HTYPE_DIRPATH_COLUMN_ARRAY, &dp->err_col,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -