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

📄 sqlora.c

📁 Linux下的操作oracle数据库的连接库
💻 C
📖 第 1 页 / 共 5 页
字号:
static int _open_session_trace_file __P((sqlo_db_struct_ptr_t dbp));static int _close_session_trace_file __P((sqlo_db_struct_ptr_t dbp));static sqlo_stmt_struct_ptr_t _get_stmt_ptr __P((const_sqlo_db_struct_ptr_t dbp));static int _stmt_new __P((sqlo_db_struct_ptr_t dbp, const char * stmt, sqlo_stmt_struct_ptr_t *stpp));static void _stmt_release __P((sqlo_stmt_struct_ptr_t  stp));static void _bindpv_reset __P((sqlo_stmt_struct_ptr_t  stp));static int _stmt_init __P((sqlo_stmt_struct_ptr_t  stp, sqlo_db_struct_ptr_t dbp, const char *stmt));static const char * _get_stmt_type_str __P((int stype));static int _is_query __P((sqlo_stmt_struct_ptr_t stp));static int _is_plsql __P((sqlo_stmt_struct_ptr_t stp));static int _is_prepared __P((sqlo_stmt_struct_ptr_t stp));static int _is_opened __P((sqlo_stmt_struct_ptr_t stp));static const char * _get_data_type_str __P((int dtype));static sqlo_db_struct_ptr_t _db_add __P((void));static void _db_release __P((sqlo_db_struct_ptr_t dbp));static int _define_by_pos __P((sqlo_stmt_struct_ptr_t  stp, unsigned int value_pos,                                int value_type, const void * value_addr,                                unsigned int  value_size, short * ind_addr,                                ub2 * rlen_addr, ub2 * rcode_addr, int is_array));static int _define_by_pos2 __P((sqlo_stmt_struct_ptr_t  stp, unsigned int value_pos,                                 int value_type, const void * value_addr,                                 unsigned int  value_size, short * ind_addr,                                 ub2 * rlen_addr, ub2 * rcode_addr,                                 unsigned int skip_size));static  int _calc_obuf_size __P(( unsigned int *bufsizep, unsigned int data_type,                                  int prec, int scale, unsigned int dbsize));static int _get_blocking_mode __P((sqlo_db_struct_ptr_t dbp, unsigned * blocking));static int _get_errcode __P(( sqlo_db_struct_ptr_t dbp));static int _set_prefetch_rows __P((sqlo_stmt_struct_ptr_t stp, unsigned int nrows));static const char * _get_stmt_string __P((sqlo_stmt_struct_ptr_t stp));static int _get_stmt_state __P((sqlo_stmt_struct_ptr_t stp));static int _alloc_definep __P((sqlo_stmt_struct_ptr_t stp, unsigned int size));static void _dealloc_definep  __P((sqlo_stmt_struct_ptr_t stp));static int _alloc_bindp __P((sqlo_stmt_struct_ptr_t stp, unsigned int size));static void _dealloc_bindp  __P((sqlo_stmt_struct_ptr_t stp));static void _close_all_db_cursors __P((const_sqlo_db_struct_ptr_t dbp));static void _close_all_executing_cursors __P((const_sqlo_db_struct_ptr_t dbp));static FILE * _get_trace_fp __P((const_sqlo_db_struct_ptr_t dbp));static int _prepare __P((sqlo_stmt_struct_ptr_t stp, const char * stmt, ub2 * stmt_type));static sqlo_thread_t _get_thread_id __P((void));static bool_t _thread_id_equal __P(( sqlo_thread_t id1, sqlo_thread_t id2));static sqlo_stmt_struct_ptr_t _sth2stp __P((int sth, const char *func_name ));static int _sqlo_reopen __P(( sqlo_stmt_struct_ptr_t stp, int argc,  const char ** argv));static int _get_ocol_db_data_type __P((sqlo_stmt_struct_ptr_t stp, unsigned int pos, ub2 * dtypep));static int _get_ocol_db_size __P((sqlo_stmt_struct_ptr_t stp, unsigned int pos, ub2 * sizep));static int _get_ocol_db_prec __P((sqlo_stmt_struct_ptr_t stp, unsigned int pos, ub1 * precp));static int _get_ocol_db_scale __P((sqlo_stmt_struct_ptr_t stp, unsigned int pos, ub1 * scalep));static int _get_ocol_db_is_null __P((sqlo_stmt_struct_ptr_t stp, unsigned int pos, ub1 * is_nullp));static int _set_ocol_name __P((sqlo_stmt_struct_ptr_t stp, sqlo_col_struct_t * colp, unsigned int pos));static int _set_all_ocol_names __P((sqlo_stmt_struct_ptr_t stp));static int _find_free_dbv_entry __P((unsigned int * free_idxp));static int _db_alloc __P((unsigned int dbv_idx));static int _stmtv_alloc __P((unsigned int dbv_idx));/* Prototypes of functions not present in oracle header files */int osnsui __P((int * handlep, sqlo_signal_handler_t signal_handler, char * ctx));int osncui __P((int handle));/*--------------------------------------------------------------------------- * END PROTOTYPES *--------------------------------------------------------------------------*/#ifdef HAVE_STRDUP/* Sometimes strdup is  not defined in strict ansi mode, * even if it is in libc  */extern char * strdup __P((const char *s));#else/** * strdup if not available on the target system * @param s  I - The string to duplicate * @return The newly allocated string. */char * DEFUN(strdup, (s), const char * s){  char *n;  n = (char *) MALLOC(sizeof(char) * (strlen(s) + 1) );  TRACE(4, fprintf(_trace_fp,"strdup: Allocated %d bytes\n", (strlen(s) + 1)););  if (n)    strcpy(n, s);  return(n);}#endif/*---------------------------------------------------------------------------  Parameters (Can be changed by environment variables or sqlo_set)  Naming conventions of environment variables:  SQLORA_ || upper(<param_name>)---------------------------------------------------------------------------*/          /* Parameters, sort them by name */static sqlora_param_t g_params[] = {  {"PREFETCH_ROWS", INTEGER,       (VOID *)&_num_prefetch_rows,    NULL},  {"LONGSIZE",      INTEGER,       (VOID *)&_max_long_size,    NULL},  {"TRACE_FILE",    STRING,        _trace_file,          NULL},  {"TRACE_LEVEL",   INTEGER,       &_trace_level,        NULL},  {NULL,            INTEGER,       NULL,                NULL}};/*------------------------------------------------------------------------- * STATIC FUNCTIONS *-----------------------------------------------------------------------*//*-------------------------------------------------------------------------*//** * Initializes a mutex * @returns OCI status. */#if CC_PRAGMA_INLINE#pragma INLINE _mutex_init#endifstatic inline intDEFUN(_mutex_init, (mutex), sqlo_mutex_t * mutex){  int status = SQLO_SUCCESS;#ifdef ENABLE_THREADS#  ifdef ENABLE_PTHREADS     pthread_mutex_init(mutex, NULL);#  elif ENABLE_ORATHREADS     status = OCIThreadMutexInit(_oci_envhp, _oci_errhp, mutex);#  else#    ifdef ENABLE_WINTHREADS       if ( (*mutex = CreateMutex(NULL, FALSE, NULL)) != NULL)	  status = SQLO_SUCCESS;       else	  status = SQLO_ERROR;#    endif#  endif#endif  return status;}/*-------------------------------------------------------------------------*//** * Lock a mutex * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _mutex_lock#endifstatic inline intDEFUN(_mutex_lock, (mutex), sqlo_mutex_t * mutex){#ifdef ENABLE_THREADS#  ifdef ENABLE_PTHREADS     pthread_mutex_lock(mutex);#  elif ENABLE_ORATHREADS     return(OCIThreadMutexAcquire(_oci_envhp, _oci_errhp, *mutex));#  elif ENABLE_WINTHREADS     return (_winmutex_lock(*mutex));#  endif#endif  return OCI_SUCCESS;}/*-------------------------------------------------------------------------*//** * Unlock a mutex. * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _mutex_unlock#endifstatic inline intDEFUN(_mutex_unlock, (mutex), sqlo_mutex_t * mutex){#ifdef ENABLE_THREADS#  ifdef ENABLE_PTHREADS     pthread_mutex_unlock(mutex);#  elif ENABLE_ORATHREADS     return (OCIThreadMutexRelease(_oci_envhp, _oci_errhp, *mutex));#  elif ENABLE_WINTHREADS     return (_winmutex_unlock( *mutex ));#  endif #endif  return(OCI_SUCCESS);}/*-------------------------------------------------------------------------*//** * Inits all mutexes. * @returns OCI status. */#if CC_PRAGMA_INLINE#pragma INLINE _init_mutexes#endifstatic inline intDEFUN_VOID(_init_mutexes){  int status = SQLO_SUCCESS;#ifdef ENABLE_THREADS  status = _mutex_init(&_dbv_mux);  if (OCI_SUCCESS == status )    status = _mutex_init(&_env_mux);#endif  return status;}/*-------------------------------------------------------------------------*//** * Inits _init_mux. * @returns OCI status. */#if CC_PRAGMA_INLINE#pragma INLINE _init_init_mux#endifstatic inline intDEFUN_VOID(_init_init_mux){  int status = SQLO_SUCCESS;#ifdef ENABLE_THREADS  if (_init_mux_initialized)     return status;#  ifdef ENABLE_PTHREADS     pthread_mutex_init(&_init_mux, NULL);#  elif ENABLE_ORATHREADS     status = (OCIThreadMutexInit(_oci_envhp, _oci_errhp, &_init_mux));#  else#    ifdef ENABLE_WINTHREADS       if ((_init_mux = CreateMutex(NULL, FALSE, NULL)) != NULL)         status = SQLO_SUCCESS;       else         status = SQLO_ERROR;#    endif#   endif  if (status == SQLO_SUCCESS)     _init_mux_initialized = 1;#endif  return status;}#ifdef ENABLE_WINTHREADS#define MUTEX_WAIT_TIME 30000 /*30 sec*//*-------------------------------------------------------------------------*//** * Lock a windows mutex * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _winmutex_lock#endifstatic inline intDEFUN(_winmutex_lock, (mp),       sqlo_mutex_t mp){  int stat;  int locked = FALSE;  do {    stat = WaitForSingleObject(mp, MUTEX_WAIT_TIME);    if (stat == WAIT_OBJECT_0)      locked = TRUE;    else if (stat == WAIT_ABANDONED)      ;    else      locked = FALSE;  } while (stat == WAIT_ABANDONED);  return (locked == TRUE) ? OCI_SUCCESS : OCI_ERROR;  return OCI_SUCCESS;}#endif#ifdef ENABLE_WINTHREADS/*-------------------------------------------------------------------------*//** * Unlock a windows mutex * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _winmutex_unlock#endifstatic inline intDEFUN(_winmutex_unlock, (mp),       sqlo_mutex_t mp){  ReleaseMutex(mp);  return OCI_SUCCESS;}#endif/*-------------------------------------------------------------------------*//** * Lock @ref _env_mux * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _env_lock#endifstatic inline intDEFUN_VOID(_env_lock){#ifdef ENABLE_THREADS  return ( _mutex_lock(&_env_mux) );#else  return (OCI_SUCCESS);#endif}/*-------------------------------------------------------------------------*//** * Unlock @ref _env_mux. * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _env_unlock#endifstatic inline intDEFUN_VOID(_env_unlock){#ifdef ENABLE_THREADS  return ( _mutex_unlock(&_env_mux) );#else  return OCI_SUCCESS;#endif}/*-------------------------------------------------------------------------*//** * Lock @ref _dbv * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _dbv_lock#endifstatic inline intDEFUN_VOID(_dbv_lock){#ifdef ENABLE_THREADS  return ( _mutex_lock(&_dbv_mux) );#else  return (OCI_SUCCESS);#endif}/*-------------------------------------------------------------------------*//** * Unlock @ref _dbv. * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _dbv_unlock#endifstatic inline intDEFUN_VOID(_dbv_unlock){#ifdef ENABLE_THREADS  return ( _mutex_unlock(&_dbv_mux) );#else  return (OCI_SUCCESS);#endif}/*-------------------------------------------------------------------------*//** * Lock @ref _init_mux * @return OCI status */#if CC_PRAGMA_INLINE#pragma INLINE _init_lock#endifstatic inline intDEFUN_VOID(_init_lock){

⌨️ 快捷键说明

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