📄 column.c
字号:
/*
+----------------------------------------------------------------------+
| |
| OCILIB - C Driver for Oracle |
| |
| (C Wrapper for Oracle OCI) |
| |
+----------------------------------------------------------------------+
| Website : http://ocilib.net |
+----------------------------------------------------------------------+
| Copyright (c) 2007-2009 Vincent ROGIER |
+----------------------------------------------------------------------+
| This library is free software; you can redistribute it and/or |
| modify it under the terms of the GNU Library General Public |
| License as published by the Free Software Foundation; either |
| version 2 of the License, or (at your option) any later version. |
| |
| This library is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| Library General Public License for more details. |
| |
| You should have received a copy of the GNU Library General Public |
| License along with this library; if not, write to the Free |
| Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
+----------------------------------------------------------------------+
| Author: Vincent ROGIER <vince.rogier@gmail.com> |
+----------------------------------------------------------------------+
*/
/* ------------------------------------------------------------------------ *
* $Id: column.c, v 3.2.0 2009/04/20 00:00 Vince $
* ------------------------------------------------------------------------ */
#include "ocilib_internal.h"
/* ************************************************************************ *
* PRIVATE FUNCTIONS
* ************************************************************************ */
/* ------------------------------------------------------------------------ *
* OCI_ColumnDescribe
* ------------------------------------------------------------------------ */
boolean OCI_ColumnDescribe(OCI_Column *col, OCI_Connection *con,
OCI_Statement *stmt, void *handle, int index,
int ptype)
{
void *ostr = NULL;
void *param = NULL;
boolean res = TRUE;
int osize = 0;
ub4 htype = 0;
ub4 attrname = 0;
/* get descriptor */
if (ptype == OCI_DESC_COLLECTION)
{
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) handle, (ub4) OCI_DTYPE_PARAM, (dvoid *) ¶m,
(ub4 *) NULL, (ub4) OCI_ATTR_COLLECTION_ELEMENT, con->err)
)
attrname = OCI_ATTR_TYPE_NAME;
}
else
{
if (ptype == OCI_DESC_RESULTSET)
htype = OCI_HTYPE_STMT;
else
htype = OCI_DTYPE_PARAM;
OCI_CALL1
(
res, con, stmt,
OCIParamGet((dvoid *) handle, htype, con->err, (void**) ¶m,
(ub4) index)
)
}
/* sql code */
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &col->ocode,
(ub4 *) NULL, (ub4) OCI_ATTR_DATA_TYPE, con->err)
)
/* size */
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &col->size,
(ub4 *) NULL, (ub4) OCI_ATTR_DATA_SIZE, con->err)
)
/* scale */
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &col->scale,
(ub4 *) NULL, (ub4) OCI_ATTR_SCALE, con->err)
)
/* precision */
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &col->prec,
(ub4 *) NULL, (ub4) OCI_ATTR_PRECISION, con->err)
)
/* charset form */
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &col->csfrm,
(ub4 *) NULL, (ub4) OCI_ATTR_CHARSET_FORM, con->err)
)
/* type of column length for string based column */
#if OCI_VERSION_COMPILE >= OCI_9
if ((OCILib.ver_runtime >= OCI_9) && (con->ver_maj >= OCI_9))
{
/* char used - no error checking because on Oracle 9.0, querying
this param that is not char/varchar based will cause an
error */
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &col->charused, (ub4 *) NULL,
(ub4) OCI_ATTR_CHAR_USED, con->err)
)
}
/* char size */
if (col->charused == TRUE)
{
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &col->charsize, (ub4 *) NULL,
(ub4) OCI_ATTR_CHAR_SIZE, con->err)
)
}
if ((OCILib.ver_runtime >= OCI_9) && (con->ver_maj >= OCI_9))
{
/* fractional time precision for timestamps */
if (col->ocode == SQLT_TIMESTAMP ||
col->ocode == SQLT_TIMESTAMP_TZ ||
col->ocode == SQLT_TIMESTAMP_LTZ)
{
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &col->prec, (ub4 *) NULL,
(ub4) OCI_ATTR_FSPRECISION, con->err)
)
}
/* leading and fractional precision for interval */
if (col->ocode == SQLT_INTERVAL_DS ||
col->ocode == SQLT_INTERVAL_YM)
{
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &col->prec, (ub4 *) NULL,
(ub4) OCI_ATTR_LFPRECISION, con->err)
)
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &col->prec2, (ub4 *) NULL,
(ub4) OCI_ATTR_FSPRECISION, con->err)
)
}
}
#endif
/* check nullable only for table based column */
if (ptype == OCI_DESC_RESULTSET)
{
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &col->null, (ub4 *) NULL,
(ub4) OCI_ATTR_IS_NULL, con->err)
)
}
else
col->null = TRUE;
/* name */
if (ptype == OCI_DESC_COLLECTION)
attrname = OCI_ATTR_TYPE_NAME;
else
attrname = OCI_ATTR_NAME;
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM, (dvoid *) &ostr,
(ub4 *) &osize, (ub4) attrname, con->err)
)
if ((res == TRUE) && (ostr != NULL))
{
col->name = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
((osize/sizeof(omtext))+ 1), TRUE);
if (col->name != NULL)
{
OCI_CopyString(ostr, col->name, &osize,
sizeof(omtext), sizeof(mtext));
}
else
res = FALSE;
}
/* user type descriptor */
if (col->ocode == SQLT_NTY || col->ocode == SQLT_REF)
{
OCI_CALL1
(
res, con, stmt,
OCIAttrGet((dvoid *) param, (ub4) OCI_DTYPE_PARAM,
(dvoid *) &ostr, (ub4 *) &osize,
(ub4) OCI_ATTR_TYPE_NAME, con->err)
)
if ((res == TRUE) && (ostr != NULL))
{
mtext *tmp = (mtext *) OCI_MemAlloc(OCI_IPC_STRING, sizeof(mtext),
((osize/sizeof(omtext))+ 1), TRUE);
if (tmp != NULL)
{
OCI_CopyString(ostr, tmp, &osize, sizeof(omtext), sizeof(mtext));
col->typinf = OCI_TypeInfoGet(con, tmp, OCI_SCHEMA_TYPE);
}
res = (col->typinf != NULL);
OCI_FREE(tmp);
}
}
if (param != NULL)
{
res = (OCI_SUCCESS == OCIDescriptorFree(param, OCI_DTYPE_PARAM));
}
return res;
}
/* ------------------------------------------------------------------------ *
* OCI_ColumnMap
* ------------------------------------------------------------------------ */
boolean OCI_ColumnMap(OCI_Column *col, OCI_Statement *stmt)
{
boolean res = TRUE;
OCI_CHECK(col == NULL, FALSE);
/* map Oracle SQL code to OCILIB types and setup of internal buffer size */
col->icode = col->ocode;
switch (col->icode)
{
case SQLT_INT:
col->type = OCI_CDT_NUMERIC;
/* set bufsize only if it's not a "returning into" placeholder */
if (col->bufsize == 0)
{
col->subtype = OCI_NUM_INT;
col->bufsize = sizeof(int);
}
break;
case SQLT_UIN:
col->type = OCI_CDT_NUMERIC;
/* set bufsize only if it's not a "returning into" placeholder */
if (col->bufsize == 0)
{
col->subtype = OCI_NUM_UINT;
col->bufsize = sizeof(unsigned int);
}
break;
case SQLT_FLT:
case SQLT_VNU:
case SQLT_PDN:
case SQLT_NUM:
#if OCI_VERSION_COMPILE >= OCI_10
case SQLT_BFLOAT:
case SQLT_BDOUBLE:
case SQLT_IBFLOAT:
case SQLT_IBDOUBLE:
#endif
col->type = OCI_CDT_NUMERIC;
col->subtype = OCI_NUM_NUMBER;
col->icode = SQLT_VNU;
col->bufsize = sizeof(OCINumber);
break;
case SQLT_DAT:
case SQLT_ODT:
col->type = OCI_CDT_DATETIME;
/* We map to SQLT_ODT only it the column is not part of a
"returning into" clause (workaround for Oracle
known bug #3269146
*/
if (col->bufsize == 0)
{
col->icode = SQLT_ODT;
col->bufsize = sizeof(OCIDate);
}
break;
case SQLT_CUR:
case SQLT_RSET:
col->type = OCI_CDT_CURSOR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -