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

📄 otlv4.h

📁 一个跨平台的数据库操作库文件,可以轻松在linux和windows下进行数据库读写以及其他的操作,支持多种数据库,代码包含很多example,初学者很容易上手. OTL 是 Oracle, Odbc
💻 H
📖 第 1 页 / 共 5 页
字号:
// ==============================================================// Oracle, ODBC and DB2/CLI Template Library, Version 4.0.160,// Copyright (C) Sergei Kuchin, 1996,2008// Author: Sergei Kuchin// This library is free software. Permission to use, copy,// modify and redistribute it for any purpose is hereby granted// without fee, provided that the above copyright notice appear// in all copies.// ==============================================================#ifndef __OTL_H__#define __OTL_H__#define OTL_VERSION_NUMBER (0x040010L)#if defined(_MSC_VER)#if (_MSC_VER >= 1400)//#pragma warning (disable:4996)#define OTL_STRCAT_S(dest,dest_sz,src) strcat_s(dest,dest_sz,src)#define OTL_STRCPY_S(dest,dest_sz,src) strcpy_s(dest,dest_sz,src)#define OTL_STRNCPY_S(dest,dest_sz,src,count) strncpy_s(dest,dest_sz,src,count)#else#define OTL_STRCAT_S(dest,dest_sz,src) strcat(dest,src)#define OTL_STRCPY_S(dest,dest_sz,src) strcpy(dest,src)#define OTL_STRNCPY_S(dest,dest_sz,src,count) strncpy(dest,src,count)#endif#else#define OTL_STRCAT_S(dest,dest_sz,src) strcat(dest,src)#define OTL_STRCPY_S(dest,dest_sz,src) strcpy(dest,src)#define OTL_STRNCPY_S(dest,dest_sz,src,count) strncpy(dest,src,count)#endif#include <string.h>#include <ctype.h>#include <stdlib.h>#include <stdio.h>//======================= CONFIGURATION #DEFINEs ===========================// Uncomment the following line in order to include the OTL for ODBC://#define OTL_ODBC// Uncomment the following line in order to include the OTL for// MySQL/MyODBC for MyODBC 2.5 (pretty old). Otherwise, use OTL_ODBC//#define OTL_ODBC_MYSQL// Uncomment the following line in order to include the OTL for DB2 CLI://#define OTL_DB2_CLI// Uncomment the following line in order to include the OTL for// Oracle 7: //#define OTL_ORA7// Uncomment the following line in order to include the OTL for// Oracle 8://#define OTL_ORA8// Uncomment the following line in order to include the OTL for// Oracle 8i://#define OTL_ORA8I// Uncomment the following line in order to include the OTL for// Oracle 9i://#define OTL_ORA9I// Uncomment the following line in order to include the OTL for// Oracle 10g Release 1://#define OTL_ORA10G// Uncomment the following line in order to include the OTL for// Oracle 10g Release 2://#define OTL_ORA10G_R2// The macro definitions may be also turned on via C++ compiler command line// option, e.g.: -DOTL_ODBC, -DOTL_ORA7, -DOTL_ORA8, -DOTL_ORA8I, -DOTL_ODBC_UNIX// -DOTL_ODBC_MYSQL, -DOTL_DB2_CLI#if defined(OTL_ORA11G)#define OTL_ORA10G_R2#endif#if defined(OTL_STREAM_LEGACY_BUFFER_SIZE_TYPE)typedef short int otl_stream_buffer_size_type;#elsetypedef int otl_stream_buffer_size_type;#endif#if defined(OTL_ODBC_MSSQL_2005)#define OTL_ODBC#endif#if defined(OTL_IODBC_BSD)#define OTL_ODBC#define OTL_ODBC_UNIX#endif#if defined(OTL_ODBC_TIMESTEN_WIN)#define OTL_ODBC_TIMESTEN#define OTL_ODBC#define OTL_ODBC_SQL_EXTENDED_FETCH_ON#define ODBCVER 0x0250#include <timesten.h>#endif#if defined(OTL_ODBC_TIMESTEN_UNIX)#define OTL_ODBC_TIMESTEN#define OTL_ODBC#define OTL_ODBC_UNIX#define OTL_ODBC_SQL_EXTENDED_FETCH_ON#include <timesten.h>#endif#if defined(OTL_ODBC_POSTGRESQL)#define OTL_ODBC#endif// Comment out this #define when using pre-ANSI C++ compiler#if !defined(OTL_ODBC_zOS) && !defined (OTL_ANSI_CPP)#define OTL_ANSI_CPP#endif#if defined(OTL_ODBC_zOS)#define OTL_ODBC_UNIX#define OTL_ODBC_SQL_EXTENDED_FETCH_ON#endif#if defined(OTL_ORA8I)#define OTL_ORA8#define OTL_ORA8_8I_REFCUR#define OTL_ORA8_8I_DESC_COLUMN_SCALE#endif#if defined(OTL_ORA10G)||defined(OTL_ORA10G_R2)#define  OTL_ORA9I#define OTL_ORA_NATIVE_TYPES#endif#if defined(OTL_ORA9I)#define OTL_ORA8#define OTL_ORA8_8I_REFCUR#define OTL_ORA8_8I_DESC_COLUMN_SCALE#endif#if defined(OTL_ODBC_MYSQL)#define OTL_ODBC#endif#if defined(OTL_ODBC_XTG_IBASE6)#define OTL_ODBC#endif#define OTL_VALUE_TEMPLATE//#define OTL_ODBC_SQL_EXTENDED_FETCH_ON#if defined(OTL_ODBC_UNIX) && !defined(OTL_ODBC)#define OTL_ODBC#endif#if defined(OTL_BIND_VAR_STRICT_TYPE_CHECKING_ON)#define OTL_CHECK_BIND_VARS                     \  if(strcmp(type_arr,"INT")==0||                \     strcmp(type_arr,"UNSIGNED")==0||           \     strcmp(type_arr,"SHORT")==0||              \     strcmp(type_arr,"LONG")==0||               \     strcmp(type_arr,"FLOAT")==0||              \     strcmp(type_arr,"DOUBLE")==0||             \     strcmp(type_arr,"TIMESTAMP")==0||          \     strcmp(type_arr,"TZ_TIMESTAMP")==0||       \     strcmp(type_arr,"LTZ_TIMESTAMP")==0||      \     strcmp(type_arr,"BIGINT")==0||             \     strcmp(type_arr,"CHAR")==0||               \     strcmp(type_arr,"CHARZ")==0||              \     strcmp(type_arr,"DB2DATE")==0||            \     strcmp(type_arr,"DB2TIME")==0||            \     strcmp(type_arr,"VARCHAR_LONG")==0||       \     strcmp(type_arr,"RAW_LONG")==0||           \     strcmp(type_arr,"RAW")==0||                \     strcmp(type_arr,"CLOB")==0||               \     strcmp(type_arr,"BLOB")==0||               \     strcmp(type_arr,"NCHAR")==0||              \     strcmp(type_arr,"NCLOB")==0||              \     strcmp(type_arr,"REFCUR")==0)              \    ;                                           \  else                                          \    return 0;#else#define OTL_CHECK_BIND_VARS#endif// ------------------- Namespace generation ------------------------#if defined(OTL_EXPLICIT_NAMESPACES)#if defined(OTL_DB2_CLI)#define OTL_ODBC_NAMESPACE_BEGIN namespace db2 {#define OTL_ODBC_NAMESPACE_PREFIX db2::#define OTL_ODBC_NAMESPACE_END }#else#define OTL_ODBC_NAMESPACE_BEGIN namespace odbc {#define OTL_ODBC_NAMESPACE_PREFIX odbc::#define OTL_ODBC_NAMESPACE_END }#endif#define OTL_ORA7_NAMESPACE_BEGIN namespace oracle {#define OTL_ORA7_NAMESPACE_PREFIX oracle::#define OTL_ORA7_NAMESPACE_END }#define OTL_ORA8_NAMESPACE_BEGIN namespace oracle {#define OTL_ORA8_NAMESPACE_PREFIX oracle::#define OTL_ORA8_NAMESPACE_END }#else// Only one OTL is being intantiated#if defined(OTL_ODBC)&&!defined(OTL_ORA8)&& \    !defined(OTL_ORA7)&&!defined(OTL_DB2_CLI) \ || !defined(OTL_ODBC)&&defined(OTL_ORA8)&& \    !defined(OTL_ORA7)&&!defined(OTL_DB2_CLI) \ || !defined(OTL_ODBC)&&!defined(OTL_ORA8)&& \    defined(OTL_ORA7)&&!defined(OTL_DB2_CLI) \ || !defined(OTL_ODBC)&&!defined(OTL_ORA8)&& \    !defined(OTL_ORA7)&&defined(OTL_DB2_CLI)#define OTL_ODBC_NAMESPACE_BEGIN#define OTL_ODBC_NAMESPACE_PREFIX#define OTL_ODBC_NAMESPACE_END#define OTL_ORA7_NAMESPACE_BEGIN#define OTL_ORA7_NAMESPACE_PREFIX#define OTL_ORA7_NAMESPACE_END#define OTL_ORA8_NAMESPACE_BEGIN#define OTL_ORA8_NAMESPACE_PREFIX#define OTL_ORA8_NAMESPACE_END#endif// ================ Combinations of two OTLs =========================#if defined(OTL_ODBC) && defined(OTL_ORA7) && \    !defined(OTL_ORA8) && !defined(OTL_DB2_CLI)#define OTL_ODBC_NAMESPACE_BEGIN namespace odbc{#define OTL_ODBC_NAMESPACE_PREFIX odbc::#define OTL_ODBC_NAMESPACE_END }#define OTL_ORA7_NAMESPACE_BEGIN namespace oracle {#define OTL_ORA7_NAMESPACE_PREFIX oracle::#define OTL_ORA7_NAMESPACE_END }#define OTL_ORA8_NAMESPACE_BEGIN#define OTL_ORA8_NAMESPACE_PREFIX#define OTL_ORA8_NAMESPACE_END#endif#if defined(OTL_ODBC) && !defined(OTL_ORA7) && \    defined(OTL_ORA8) && !defined(OTL_DB2_CLI)#define OTL_ODBC_NAMESPACE_BEGIN namespace odbc{#define OTL_ODBC_NAMESPACE_PREFIX odbc::#define OTL_ODBC_NAMESPACE_END }#define OTL_ORA8_NAMESPACE_BEGIN namespace oracle {#define OTL_ORA8_NAMESPACE_PREFIX oracle::#define OTL_ORA8_NAMESPACE_END }#define OTL_ORA7_NAMESPACE_BEGIN#define OTL_ORA7_NAMESPACE_PREFIX#define OTL_ORA7_NAMESPACE_END#endif#if !defined(OTL_ODBC) && defined(OTL_ORA7) && \    !defined(OTL_ORA8) && defined(OTL_DB2_CLI)#define OTL_ORA7_NAMESPACE_BEGIN namespace oracle {#define OTL_ORA7_NAMESPACE_PREFIX oracle::#define OTL_ORA7_NAMESPACE_END }#define OTL_ORA8_NAMESPACE_BEGIN#define OTL_ORA8_NAMESPACE_PREFIX#define OTL_ORA8_NAMESPACE_END#define OTL_ODBC_NAMESPACE_BEGIN namespace db2 {#define OTL_ODBC_NAMESPACE_PREFIX db2::#define OTL_ODBC_NAMESPACE_END }#endif#if !defined(OTL_ODBC) && !defined(OTL_ORA7) && \    defined(OTL_ORA8) && defined(OTL_DB2_CLI)#define OTL_ORA8_NAMESPACE_BEGIN namespace oracle {#define OTL_ORA8_NAMESPACE_PREFIX oracle::#define OTL_ORA8_NAMESPACE_END }#define OTL_ORA7_NAMESPACE_BEGIN#define OTL_ORA7_NAMESPACE_PREFIX#define OTL_ORA7_NAMESPACE_END#define OTL_ODBC_NAMESPACE_BEGIN namespace db2 {#define OTL_ODBC_NAMESPACE_PREFIX db2::#define OTL_ODBC_NAMESPACE_END }#endif#endif// -------------------- End of namespace generation -------------------// --------------------- Invalid combinations --------------------------#if defined(OTL_ORA_UTF8) && !defined(OTL_ORA10G) && \    !defined(OTL_ORA_10G_R2) && !defined(OTL_ORA9I)#error Invalid combination: OTL_ORA_UTF8 can only be used with OTL_ORA9I or higher#endif#if defined(OTL_ORA_UTF8) && defined(OTL_UNICODE)#error Invalid combination: OTL_ORA_UTF8 and OTL_UNICODE are mutually exclusive#endif#if defined(OTL_ODBC) && defined(OTL_DB2_CLI)#error Invalid combination: OTL_ODBC && OTL_DB2_CLI together#endif#if defined(OTL_ORA7) && defined(OTL_ORA8)#error Invalid combination: OTL_ORA7 && OTL_ORA8(I) together#endif#if (defined(OTL_ORA7) || defined(OTL_ORA8) ||          \     defined(OTL_ORA8I) || defined(OTL_ORA9I) ) &&      \     defined(OTL_BIGINT) &&                             \     (defined(OTL_ODBC) || defined(OTL_DB2_CLI)) #error OTL_BIGINT is not supported when OTL_ORAXX and OTL_ODBC \(or OTL_DB2_CLI) are defined together#endif#if defined (OTL_ORA7) && defined(OTL_ORA8)#error Invalid combination: OTL_ORA7 && OTL_ORA8(I) together#endif#if defined(OTL_ORA_OCI_ENV_CREATE) && \    (!defined(OTL_ORA8I) && !defined(OTL_ORA9I) && \     !defined(OTL_ORA10G) && !defined(OTL_ORA10G_R2))#error OTL_ORA_OCI_ENV_CREATE can be only defined when OTL_ORA8I, OTL_ORA9I, OTL_ORA10G, or OTL_ORA10G_R2 is defined#endif// --------------------------------------------------------------------#if defined(OTL_TRACE_LEVEL)#if !defined(OTL_TRACE_LINE_PREFIX)#define OTL_TRACE_LINE_PREFIX "OTL TRACE ==> "#endif#if defined(OTL_UNICODE_CHAR_TYPE) && !defined(OTL_UNICODE)#error OTL_UNICODE needs to be defined if OTL_UNICODE_CHAR_TYPE is defined#endif#if defined(OTL_UNICODE_STRING_TYPE) && !defined(OTL_UNICODE_CHAR_TYPE)#error OTL_UNICODE_CHAR_TYPE needs to be defined if OTL_UNICODE_STRING_TYPE is defined#endif#if defined(OTL_UNICODE_STRING_TYPE) && !defined(OTL_UNICODE_CHAR_TYPE)#error OTL_UNICODE_CHAR_TYPE needs to be defined if OTL_UNICODE_STRING_TYPE is defined#endif#if defined(OTL_UNICODE_STRING_TYPE) && !defined(OTL_UNICODE)#error OTL_UNICODE needs to be defined if OTL_UNICODE_STRING_TYPE is defined#endif#if defined(OTL_UNICODE_EXCEPTION_AND_RLOGON) && !defined(OTL_UNICODE_CHAR_TYPE)#error OTL_UNICODE_CHAR_TYPE needs to be defined if OTL_UNICODE_EXCEPTION_AND_RLOGON is defined#endif#if !defined(OTL_TRACE_LINE_SUFFIX)#if defined(OTL_UNICODE)#define OTL_TRACE_LINE_SUFFIX L"\n"#else#define OTL_TRACE_LINE_SUFFIX "\n"#endif#endif#if !defined(OTL_TRACE_STREAM_OPEN)#define OTL_TRACE_STREAM_OPEN                   \  if(OTL_TRACE_LEVEL & 0x4){                    \    OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;    \    OTL_TRACE_STREAM<<"otl_stream(this=";       \    OTL_TRACE_STREAM<<OTL_RCAST(void*,this);    \    OTL_TRACE_STREAM<<")::open(buffer_size=";   \    OTL_TRACE_STREAM<<arr_size;                 \    OTL_TRACE_STREAM<<", sqlstm=";              \    OTL_TRACE_STREAM<<sqlstm;                   \    OTL_TRACE_STREAM<<", connect=";             \    OTL_TRACE_STREAM<<OTL_RCAST(void*,&db);     \    OTL_TRACE_STREAM<<", implicit_select=";     \    OTL_TRACE_STREAM<<implicit_select;          \    if(sqlstm_label){                           \      OTL_TRACE_STREAM<<", label=";             \      OTL_TRACE_STREAM<<sqlstm_label;           \    }                                           \    OTL_TRACE_STREAM<<");";                     \    OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;    \  }#endif#if !defined(OTL_TRACE_STREAM_OPEN2)#define OTL_TRACE_STREAM_OPEN2                          \  if(OTL_TRACE_LEVEL & 0x4){                            \    OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;            \    OTL_TRACE_STREAM<<"otl_stream(this=";               \    OTL_TRACE_STREAM<<OTL_RCAST(void*,this);            \    OTL_TRACE_STREAM<<")::open(buffer_size=";           \    OTL_TRACE_STREAM<<arr_size;                         \    OTL_TRACE_STREAM<<", sqlstm=";                      \    OTL_TRACE_STREAM<<sqlstm;                           \    OTL_TRACE_STREAM<<", connect=";                     \    OTL_TRACE_STREAM<<OTL_RCAST(void*,&db);             \    if(ref_cur_placeholder){                            \      OTL_TRACE_STREAM<<", ref_cur_placeholder=";       \      OTL_TRACE_STREAM<<ref_cur_placeholder;            \    }                                                   \    if(sqlstm_label){                                   \      OTL_TRACE_STREAM<<", label=";                     \      OTL_TRACE_STREAM<<sqlstm_label;                   \    }                                                   \    OTL_TRACE_STREAM<<");";                             \    OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;            \  }#endif#if !defined(OTL_TRACE_DIRECT_EXEC)#define OTL_TRACE_DIRECT_EXEC                             \  if(OTL_TRACE_LEVEL & 0x2){                              \    OTL_TRACE_STREAM<<OTL_TRACE_LINE_PREFIX;              \    OTL_TRACE_STREAM<<"otl_cursor::direct_exec(connect="; \    OTL_TRACE_STREAM<<OTL_RCAST(void*,&connect);          \    OTL_TRACE_STREAM<<",sqlstm=\"";                       \    OTL_TRACE_STREAM<<sqlstm;                             \    OTL_TRACE_STREAM<<"\",exception_enabled=";            \    OTL_TRACE_STREAM<<exception_enabled;                  \    OTL_TRACE_STREAM<<");";                               \    OTL_TRACE_STREAM<<OTL_TRACE_LINE_SUFFIX;              \  }

⌨️ 快捷键说明

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