📄 statement.c
字号:
{
if (bnd->plrcds == NULL)
{
bnd->plrcds = (ub2 *) OCI_MemAlloc(OCI_IPC_PLS_RCODE_ARRAY,
sizeof(ub2), nbelem, TRUE);
}
res = (bnd->plrcds != NULL);
}
}
/* for handle based datatypes, we need to allocate an array of handles for
bind calls because OCILIB uses external arrays of OCILIB Objects */
if ((res == TRUE) && (mode == OCI_BIND_INPUT))
{
if (type != OCI_CDT_RAW &&
type != OCI_CDT_LONG &&
type != OCI_CDT_CURSOR &&
#ifndef OCI_CHECK_DATASTRINGS
type != OCI_CDT_TEXT &&
#endif
(type != OCI_CDT_NUMERIC || code == SQLT_VNU)
)
{
bnd->alloc = TRUE;
if (bnd->buf.data == NULL)
{
bnd->buf.data = (void **) OCI_MemAlloc(OCI_IPC_BUFF_ARRAY, size,
nbelem, TRUE);
}
res = (bnd->buf.data != NULL);
}
else
bnd->buf.data = (void **) data;
}
/* setup data length array */
if (res == TRUE && ((is_pltbl == TRUE) || (type == OCI_CDT_RAW)))
{
if (bnd->buf.lens == NULL)
{
bnd->buf.lens = (void *) OCI_MemAlloc(OCI_IPC_LEN_ARRAY, sizeof(ub2),
nbelem, TRUE);
}
res = (bnd->buf.lens != NULL);
/* initialize length array with buffer default size */
if (res == TRUE)
{
for (i=0; i < nbelem; i++)
{
*(ub2*)(((ub1 *)bnd->buf.lens) + sizeof(ub2) * i) = (ub2) size;
}
}
}
/* initialize bind object */
if (res == TRUE)
{
/* initialize bind attributes */
bnd->stmt = stmt;
bnd->input = (void **) data;
bnd->type = type;
bnd->size = size;
bnd->code = (ub2) code;
bnd->subtype = (ub1) subtype;
if (bnd->name == NULL)
{
bnd->name = mtsdup(name);
}
/* initialize buffer */
bnd->buf.count = nbelem;
bnd->buf.sizelen = sizeof(ub2);
/* if we bind an OCI_Long or any output bind, we need to change the
execution mode to provide data at execute time */
if (bnd->type == OCI_CDT_LONG)
{
stmt->long_size = size;
exec_mode = OCI_DATA_AT_EXEC;
}
else if (mode == OCI_BIND_OUTPUT)
{
exec_mode = OCI_DATA_AT_EXEC;
}
}
/* OCI binding */
if (res == TRUE)
{
if (stmt->bind_mode == OCI_BIND_BY_POS)
{
OCI_CALL1
(
res, stmt->con, stmt,
OCIBindByPos(stmt->stmt, (OCIBind **) &bnd->buf.handle,
stmt->con->err, (ub4) index, (void *) bnd->buf.data,
bnd->size, bnd->code, bnd->buf.inds, bnd->buf.lens,
bnd->plrcds, (ub4) (is_pltbl == TRUE ? nbelem : 0),
pnbelem, exec_mode)
)
}
else
{
void * ostr = NULL;
int osize = -1;
ostr = OCI_GetInputMetaString(bnd->name, &osize);
OCI_CALL1
(
res, stmt->con, stmt,
OCIBindByName(stmt->stmt, (OCIBind **) &bnd->buf.handle,
stmt->con->err, (OraText *) ostr, (sb4) osize,
(void *) bnd->buf.data, bnd->size, bnd->code,
bnd->buf.inds, bnd->buf.lens, bnd->plrcds,
(ub4) (is_pltbl == TRUE ? nbelem : 0),
pnbelem, exec_mode)
)
OCI_ReleaseMetaString(ostr);
}
if (code == SQLT_NTY || code == SQLT_REF)
{
OCI_CALL1
(
res, stmt->con, stmt,
OCIBindObject((OCIBind *) bnd->buf.handle, stmt->con->err,
(OCIType *) typinf->tdo, (void **) bnd->buf.data,
(ub4 *) NULL, (void **) NULL,
(ub4 *) bnd->buf.inds)
)
}
if (mode == OCI_BIND_OUTPUT)
{
/* register output placeholder */
OCI_CALL1
(
res, stmt->con, stmt,
OCIBindDynamic((OCIBind *) bnd->buf.handle, stmt->con->err,
(dvoid *) bnd, OCI_ProcInBind,
(dvoid *) bnd, OCI_ProcOutBind)
)
}
/* setup national charset from flag if needed */
if (
(
(bnd->type == OCI_CDT_LOB) &&
(bnd->subtype == OCI_NCLOB)
)
#ifdef OCI_USERDATA_UNICODE
||
(
(bnd->type == OCI_CDT_TEXT) &&
(OCI_GetVersionConnection(stmt->con) >= OCI_9) &&
(bnd->buf.lens == NULL)
)
#endif
)
{
ub1 csfrm = SQLCS_NCHAR;
OCI_CALL1
(
res, stmt->con, stmt,
OCIAttrSet((dvoid *) bnd->buf.handle, (ub4) OCI_HTYPE_BIND,
(dvoid *) &csfrm, (ub4) sizeof(csfrm),
(ub4) OCI_ATTR_CHARSET_FORM, bnd->stmt->con->err)
)
}
if (bnd->type == OCI_CDT_TEXT)
{
OCI_CALL1
(
res, stmt->con, stmt,
OCIAttrSet((dvoid *) bnd->buf.handle, (ub4) OCI_HTYPE_BIND,
(dvoid *) &bnd->size, (ub4) sizeof(bnd->size),
(ub4) OCI_ATTR_MAXDATA_SIZE, bnd->stmt->con->err)
)
}
#ifdef OCI_CHARSET_MIXED
/* setup Unicode mode for user data in mixed builds */
{
ub2 csid = OCI_UTF16ID;
OCI_CALL1
(
res, stmt->con, stmt,
OCIAttrSet((dvoid *) bnd->buf.handle, (ub4) OCI_HTYPE_BIND,
(dvoid *) &csid, (ub4) sizeof(csid),
(ub4) OCI_ATTR_CHARSET_ID, stmt->con->err)
)
}
#endif
}
/* on success, we :
- add the bind handle to the bind array
- add the bind index to the map
*/
if (res == TRUE)
{
if (mode == OCI_BIND_INPUT)
{
if (reused == FALSE)
{
stmt->ubinds[stmt->nb_ubinds++] = bnd;
/* for user binds, add a positive index */
OCI_HashAddInt(stmt->map, name, stmt->nb_ubinds);
}
}
else
{
/* for register binds, add a negative index */
stmt->rbinds[stmt->nb_rbinds++] = bnd;
index = (int) stmt->nb_rbinds;
OCI_HashAddInt(stmt->map, name, -index);
}
}
OCI_RESULT(res);
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_BindGetIndex
* ------------------------------------------------------------------------ */
int OCI_BindGetIndex(OCI_Statement *stmt, const mtext *name)
{
OCI_HashEntry *he = NULL;
int index = -1;
OCI_CHECK_PTR(OCI_IPC_STATEMENT, stmt, -1);
OCI_CHECK_PTR(OCI_IPC_STRING, name, -1);
if (stmt->map != NULL)
{
he = OCI_HashLookup(stmt->map, name, FALSE);
while (he != NULL)
{
/* no more entries or key matched => so we got it ! */
if (he->next == NULL || mtscasecmp(he->key, name) == 0)
{
/* in order to sue the same map for user binds and
register binds :
- user binds are stored as positive values
- registers binds are stored as negatives values
*/
index = he->values->value.num;
if (index < 0)
index = -index;
break;
}
}
}
return index;
}
/* ------------------------------------------------------------------------ *
* OCI_FetchIntoUserVariables
* ------------------------------------------------------------------------ */
boolean OCI_FetchIntoUserVariables(OCI_Statement *stmt, va_list args)
{
OCI_Resultset *rs = NULL;
boolean res = FALSE;
int i, n;
/* get resultset */
rs = OCI_GetResultset(stmt);
/* fetch data */
if (rs != NULL)
res = OCI_FetchNext(rs);
if (res == TRUE)
{
/* loop on column list for updating user given placeholders */
for (i = 1, n = OCI_GetColumnCount(rs); i <= n && res == TRUE; i++)
{
OCI_Column *col = OCI_GetColumn(rs, i);
int type = va_arg(args, int);
switch (type)
{
case OCI_ARG_SHORT:
{
short src, *dst;
src = OCI_GetShort(rs, i);
dst = va_arg(args, short *);
if (dst != NULL)
*dst = src;
break;
}
case OCI_ARG_USHORT:
{
unsigned short src, *dst;
src = OCI_GetUnsignedShort(rs, i);
dst = va_arg(args, unsigned short *);
if (dst != NULL)
*dst = src;
break;
}
case OCI_ARG_INT:
{
int src, *dst;
src = OCI_GetInt(rs, i);
dst = va_arg(args, int *);
if (dst != NULL)
*dst = src;
break;
}
case OCI_ARG_UINT:
{
unsigned int src, *dst;
src = OCI_GetUnsignedInt(rs, i);
dst = va_arg(args, unsigned int *);
if (dst != NULL)
*dst = src;
break;
}
case OCI_ARG_BIGINT:
{
big_int src, *dst;
src = OCI_GetBigInt(rs, i);
dst = va_arg(args, big_int *);
if (dst != NULL)
*dst = src;
break;
}
case OCI_ARG_BIGUINT:
{
big_uint src, *dst;
src = OCI_GetUnsignedBigInt(rs, i);
dst = va_arg(args, big_uint *);
if (dst != NULL)
*dst = src;
break;
}
case OCI_ARG_DOUBLE:
{
double src, *dst;
src = OCI_GetDouble(rs, i);
dst = va_arg(args, double *);
if (dst != NULL)
*dst = src;
break;
}
case OCI_ARG_DATETIME:
{
OCI_Date *src, *dst;
src = OCI_GetDate(rs, i);
dst = (OCI_Date *) va_arg(args, OCI_Date *);
if (src != NULL && dst != NULL)
res = OCI_DateAssign(dst, src);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -