⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqlora.c

📁 Linux下的操作oracle数据库的连接库
💻 C
📖 第 1 页 / 共 5 页
字号:
  }}/*---------------------------------------------------------------------------*//** * Compares two thread ids and returns if they are equal * @return TRUE if they are equal, FALSE if not. */static inline bool_tDEFUN(_thread_id_equal, (id1, id2),       sqlo_thread_t   id1      AND       sqlo_thread_t   id2 ){#if ENABLE_ORATHREADS  boolean result;  OCIThreadIdSame(_oci_envhp, _oci_errhp, id1, id2, &result);  return result ? TRUE : FALSE;#else  return id1 == id2 ? TRUE : FALSE;#endif}/*-------------------------------------------------------------------------*//** * Returns a free stmt struct ptr from  @ref dbp->stmtv[]. * * @param dbp I - The database ptr. * @return The new entry, marked as used, or NULL if all are in use */static sqlo_stmt_struct_ptr_t DEFUN(_get_stmt_ptr, (dbp), const_sqlo_db_struct_ptr_t dbp){  register unsigned stmt_idx;  bool_t found_free;  register sqlo_stmt_struct_ptr_t stp;  TRACE(4, fprintf(_get_trace_fp(dbp),                   "_get_stmt_ptr: stmtv_size=%d\n", dbp->stmtv_size););  /* check for initialization */  if ((! _sqlo_init) || (dbp->stmtv_size <= 0))    return (NULL) ;    /* we need to check first if there is an unused allocated slot */  found_free         = FALSE;  for (stmt_idx = 0, stp = dbp->stmtv;        stmt_idx < dbp->stmtv_size;        ++stmt_idx, ++stp) {    if ( !stp->used ) {  /* free entry found */      found_free = TRUE;      break ;    }  }    TRACE(4, fprintf(_get_trace_fp(dbp),                   "_get_stmt_ptr: found_free=%d, stmt_idx=%d\n",                    found_free, stmt_idx););  if (found_free) {    TRACE(3, fprintf(_get_trace_fp(dbp),                     "_get_stmt_ptr: Reusing handle %u\n", stmt_idx););    stp->sth = stmt_idx ;    stp->used = TRUE ;   } else {     stp = NULL;  }  return (stp) ;}/*-------------------------------------------------------------------------*//** * Initializes the stmt structure * Sets the dbp into stp and copies stmt into the structure. * @return SQLO_SUCCESS or SQLO_ERRMALLOC */static intDEFUN(_stmt_init, (stp, dbp, stmt),       sqlo_stmt_struct_ptr_t     stp    AND       sqlo_db_struct_ptr_t       dbp    AND       const char *               stmt ){  unsigned int len = (unsigned int)strlen(stmt) + 1;  stp->dbp       = dbp;  stp->stmthp    = NULL;  stp->stype     = 0;  stp->opened    = FALSE;  stp->prepared  = FALSE;  stp->still_executing = FALSE;  stp->num_executions  = 0;  stp->cursor_type = DEFAULT;  if (!stp->stmt) {    if ( MIN_STMT_SIZE > len )      len = MIN_STMT_SIZE;        ERRMALLOC(stp->dbp, stp->stmt, sizeof(char) * len,               "_stmt_init(alloc stmt)", SQLO_ERRMALLOC);    stp->stmt_size = len;      } else if (stp->stmt_size < len ) {        ERREALLOC(stp->dbp, stp->stmt, sizeof(char) * len,               "_stmt_init(realloc stmt))", SQLO_ERRMALLOC);    stp->stmt_size = len;  }  strcpy(stp->stmt, stmt);      return SQLO_SUCCESS;}/*-------------------------------------------------------------------------*//** * Creates a new stmt. * Allocates the stmt entry via @ref _get_stmt_ptr, allocates the statement handle and * initializes the structure. * The stmt structure is initialized. *  * @return SQLO_SUCCESS or < 0 on error. */static intDEFUN(_stmt_new, (dbp, stmt, stpp),      sqlo_db_struct_ptr_t       dbp    AND      const char *               stmt   AND      sqlo_stmt_struct_ptr_t *   stpp ){  register sqlo_stmt_struct_ptr_t  stp;  stp = _get_stmt_ptr(dbp);  if (! stp) {    sprintf(dbp->errmsg, "SLQORALIB *** FATAL *** : allocation of statement failed") ;    dbp->status = SQLO_ERRMALLOC;    return (dbp->status);  }  /* init the structure */  if (SQLO_SUCCESS != (dbp->status = _stmt_init(stp, dbp, stmt))) {    _stmt_release(stp);    return (dbp->status);  }  /*    * Allocate the statement handle   */  dbp->status = OCIHandleAlloc( (dvoid *) dbp->envhp, 			   (dvoid **) &stp->stmthp,                           OCI_HTYPE_STMT, 			   (size_t) 0, 			   (dvoid **) 0			   );  if (dbp->status != OCI_SUCCESS) {    _stmt_release( stp );  } else {    *stpp = stp;  }  return ( dbp->status );}/*-------------------------------------------------------------------------*//** * * (Re)allocates space for stp->bindpv[] and stp->indpv[] if necessary. * Sets stp->bindpv_size to the new size. * Allocates always in steps of MIN_BINDP, to avoid too many reallocations. * Sets stp->dbp->status. * * @param stp  I - The statement pointer. * @param size I - The requested size. *  * @return <ul> * <li>SQLO_SUCCESS on error. * <li>SQLO_ERRMALLOC on failure. * </ul> */static int DEFUN(_alloc_bindp, (stp, size),       sqlo_stmt_struct_ptr_t  stp    AND       unsigned int            size ){  register int num_new;  sqlo_db_struct_ptr_t dbp;  assert( stp->dbp != NULL );  dbp = stp->dbp;  dbp->status = SQLO_SUCCESS;  TRACE(4, fprintf(_get_trace_fp(dbp),		   "_alloc_bindp: alloc sth: %u bindpv_size: %u, req. size: %u\n",		   stp->sth, stp->bindpv_size, size););  if (size > stp->bindpv_size) {    /* allocate MIN_BINDP to avoid a lot of reallocations */    if (size <= MIN_BINDP)      size = MIN_BINDP;    else       size = 2 * size;    if ( 0 == stp->bindpv_size ) {    /* complety empty ? */      TRACE(4, fprintf(_get_trace_fp(dbp),		       "_alloc_bindp: alloc sth: %u to %u elements\n",		       stp->sth, size););      ERRMALLOC(dbp, stp->bindpv, sizeof(OCIBind*) * size,		"_alloc_bindp(bindp)", SQLO_ERRMALLOC);      ERRMALLOC(dbp, stp->indpv, sizeof(short) * size, 		"_alloc_bindp(ind)", SQLO_ERRMALLOC);    } else {      TRACE(4, fprintf(_get_trace_fp(dbp),                       "_alloc_bindpv: realloc sth: %u to %u elements\n",                       stp->sth, size););      ERREALLOC(dbp, stp->bindpv, sizeof(OCIBind*) * size,                "sqlo_realloc_bind(bindpv)",  SQLO_ERRMALLOC );      ERREALLOC(dbp, stp->indpv, sizeof(short) * size,                  "sqlo_realloc_bind(indp)", SQLO_ERRMALLOC );    }    /* init the new elements */    num_new = size - stp->bindpv_size; /* number of elements to be initialized */    assert( num_new > 0 );    memset(&stp->bindpv[ stp->bindpv_size ], 0, num_new * sizeof(OCIBind *));    memset(&stp->indpv[ stp->bindpv_size ],  0, num_new * sizeof(short));    /* set the new size */    stp->bindpv_size = size;  }  /* checks */  assert( stp->bindpv_size >= stp->num_bindpv );  return (dbp->status);}/*-------------------------------------------------------------------------*//** * * Deallocates space for stp->bindpv[] and stp->indpv[]  * Resets stp->bindpv_size and stp->numb_bindp to 0 * * @param stp  I - The statement pointer. *  */static voidDEFUN(_dealloc_bindp, ( stp ),       sqlo_stmt_struct_ptr_t  stp ){  sqlo_db_struct_ptr_t dbp;  assert( stp->dbp != NULL );  dbp = stp->dbp;  TRACE(4, fprintf(_get_trace_fp(dbp),		   "_dealloc_bindp: dealloc sth: %u bindpv_size: %u\n",		   stp->sth, stp->bindpv_size););  if ( stp->bindpv_size > 0 ) {    assert( stp->bindpv != NULL );    assert( stp->indpv != NULL );    FREE( stp->bindpv );	/* bind pointer array */    FREE( stp->indpv );		/* indicator var. pointer array */  }  stp->bindpv_size = 0;  stp->num_bindpv = 0;}/*-------------------------------------------------------------------------*//** * (Re)allocates more space for output variables. * (Re)allocates more space for stp->ocolsv[], stp->outv, * stp->defnpv, stp->ocol_namev_size and stp->ocol_namev. * Sets stp->defnpv_size is set to the new size. * Allocates always in steps of MINUM_DEFNPV, to avoid too much memory free/allocs * * @param stp  I - The statement pointer * @param size I - The requested size. * * @return <ul> * <li>SQLO_SUCCESS on error. * <li>SQLO_ERRMALLOC on failure. * </ul> */static int DEFUN(_alloc_definep, (stp, size),        sqlo_stmt_struct_ptr_t     stp    AND       unsigned int               size ){  register int num_new;   /* number of new elements in the arrays */  sqlo_db_struct_ptr_t dbp;  assert( stp->dbp != NULL );  dbp = stp->dbp;  dbp->status = SQLO_SUCCESS;    if (size > stp->defnpv_size) { /* not enough space? */    /* allocate always a mininum of MIN_DEFNP elements.     * Beyond this lower bound we take 2*size to avoid lots of reallocation     * during sqlo_define_by_pos     */    if (size <= MIN_DEFNP)      size = MIN_DEFNP;    else      size = 2 * size;    /* complety empty ? --> MALLOC, else REALLOC*/    if (0 == stp->defnpv_size ) {              TRACE(4, fprintf(_get_trace_fp(dbp),		       "_alloc_definep: alloc sth: %u for %u columns\n",		       stp->sth, size););      ERRMALLOC(dbp, stp->defnpv, sizeof(OCIDefine *) * size, 		"_alloc_definep(alloc defnpv)", SQLO_ERRMALLOC);      ERRMALLOC(dbp, stp->ocolsv, sizeof(sqlo_col_struct_t) * size, 		"_alloc_definep(alloc ocols)", SQLO_ERRMALLOC);      ERRMALLOC(dbp, stp->outv, sizeof(char *) * size, 		"_alloc_definep(alloc outv)", SQLO_ERRMALLOC);      ERRMALLOC(dbp, stp->outv_size, sizeof(int) * size, 		"_alloc_definep(alloc outv_size)", SQLO_ERRMALLOC);      ERRMALLOC(dbp, stp->oindv, sizeof(ub2) * size, 		"_alloc_definep(alloc oindv)", SQLO_ERRMALLOC);      ERRMALLOC(dbp, stp->rlenv, sizeof(ub2) * size, 		"_alloc_definep(alloc rlenv)", SQLO_ERRMALLOC);      ERRMALLOC(dbp, stp->ocol_namev, sizeof(char *) * size, 		"_alloc_definep(alloc ocol_namev)", SQLO_ERRMALLOC);      ERRMALLOC(dbp, stp->ocol_namev_size, sizeof(int) * size, 		"_alloc_definep(alloc ocol_namev_size)", SQLO_ERRMALLOC);    } else {      TRACE(4, fprintf(_get_trace_fp(dbp),                       "_alloc_definep: realloc sth: %u to %u elements\n",                       stp->sth, size););      ERREALLOC(dbp, stp->defnpv, sizeof(OCIDefine *) * size,                 "_alloc_definep(realloc defnpv)", SQLO_ERRMALLOC );      ERREALLOC(dbp, stp->ocolsv, sizeof(sqlo_col_struct_t) * size,                "_alloc_definep(realloc ocols)",  SQLO_ERRMALLOC);      ERREALLOC(dbp, stp->outv, sizeof(char *) * size,                 "_alloc_definep(realloc outv)", SQLO_ERRMALLOC);      ERREALLOC(dbp, stp->outv_size, sizeof(int) * size,                 "_alloc_definep(realloc outv_size)", SQLO_ERRMALLOC);      ERREALLOC(dbp, stp->oindv, sizeof(ub2) * size,                 "_alloc_definep(realloc oindv)", SQLO_ERRMALLOC);      ERREALLOC(dbp, stp->rlenv, sizeof(ub2) * size,                 "_alloc_definep(realloc rlenv)", SQLO_ERRMALLOC);      ERREALLOC(dbp, stp->ocol_namev, sizeof(char *) * size,                 "_alloc_definep(realloc ocol_namev)", SQLO_ERRMALLOC);      ERREALLOC(dbp, stp->ocol_namev_size, sizeof(int) * size,                 "_alloc_definep(realloc ocol_namev_size)", SQLO_ERRMALLOC);    }    /* init the new elements */    num_new = size - stp->defnpv_size;    assert( num_new > 0 );    memset(&stp->defnpv[ stp->defnpv_size ], 0,  sizeof(OCIDefine *) * num_new);    memset(&stp->ocolsv[ stp->defnpv_size ], 0, sizeof(sqlo_col_struct_t) * num_new);    memset(&stp->outv[ stp->defnpv_size ], 0, sizeof(char*) * num_new);    memset(&stp->outv_size[ stp->defnpv_size ], 0, sizeof(unsigned) * num_new);    memset(&stp->oindv[ stp->defnpv_size ], 0, sizeof(ub2) * num_new);    memset(&stp->rlenv[ stp->defnpv_size ], 0, sizeof(ub2) * num_new);    memset(&stp->ocol_namev_size[ stp->defnpv_size ], 0, sizeof(unsigned) * num_new);    /* set new size */    stp->defnpv_size = size;  }  assert( stp->defnpv_size >= stp->num_defnpv);  return (dbp->status);}/*-------------------------------------------------------------------------*//** * * Deallocates space for stp->bindpv[] and stp->indpv[]  * Resets stp->bindpv_size and stp->numb_bindp to 0 * * @param stp  I - The statement pointer. *  */static voidDEFUN(_dealloc_definep, ( stp ),       sqlo_stmt_struct_ptr_t  stp ){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -