multiple-value stmt.exec in execsingleaction-value context怎么办

Linux下使用C/C++访问数据库 - MySQL篇
Linux下使用C/C++访问数据库 - MySQL篇
  写一套OA系统,为了方便进行数据库操作,特意抽出一周的时间来研究C/C++访问各种数据库的方法,并打算封装一套数据库操作类,现在奉上最简单的一部分:在Linux下访问MySQL数据库。
  本文中使用的MySQL API代码为C语言,如果各位对C++有兴趣,可以考虑使用mysql++。
  一、配置开发环境首先需要编译、安装MySQL,安装完成后,将MySQL目录中的lib目录添加到环境变量中。新建C/C++工程,把$MYSQL_ROOT/include添加到编译环境的包含路径下面。在编译选项中,增加$MYSQL_ROOT/lib目录。在Link选项中增加-lmysqlclient(已经把lib目录增加到系统环境变量中),或者直接引用libmysqlclient.so文件。
  二、程序代码不多说了,直接上代码,注释都很详细。/*&&& * MySQLManager.h&&& *&&& *&&& Created on: Feb 18, 2009&&& *&&&&&&&&&&& Author: Steven Wee&&& */&&&
  #ifndef MYSQLMANAGER_H_&&& #define MYSQLMANAGER_H_&&&
  #include "../Common/CheckStringTools.h"&&&
  #include &mysql.h&&&&
  #include &string&&&& #include &iostream&&&& #include &vector&&&&
  #include &string.h&&&&
  class MySQLManager&&& {&&& public:&&& &&&&&&& /*&&& &&&&&&&& * Init MySQL&&& &&&&&&&& * @param hosts:&&&&&&&& Host IP address&&& &&&&&&&& * @param userName:&&&&&&& Login UserName&&& &&&&&&&& * @param password:&&&&&&& Login Password&&& &&&&&&&& * @param dbName:&&&&&&& Database Name&&& &&&&&&&& * @param port:&&&&&&&&&&&&&&& Host listen port number&&& &&&&&&&& */&&& &&&&&&& MySQLManager(std::string hosts, std::string userName, std::string password, std::string dbName, unsigned int port);&&& &&&&&&& ~MySQLManager();&&& &&&&&&& void initConnection();&&& &&&&&&& /*&&& &&&&&&&& * Making query from database&&& &&&&&&&& * @param mysql:&&&&&&& MySQL Object&&& &&&&&&&& * @param sql:&&&&&&&&&&&&&&& Running SQL command&&& &&&&&&&& */&&& &&&&&&& bool runSQLCommand(std::string sql);&&& &&&&&&& /**&&& &&&&&&&& * Destroy MySQL object&&& &&&&&&&& * @param mysql&&&&&&&&&&&&&&& MySQL object&&& &&&&&&&& */&&& &&&&&&& void destroyConnection();&&& &&&&&&& bool getConnectionStatus();&&& &&&&&&& vector& vector&string& & getResult();&&& protected:&&& &&&&&&& void setUserName(std::string userName);&&& &&&&&&& void setHosts(std::string hosts);&&& &&&&&&& void setPassword(std::string password);&&& &&&&&&& void setDBName(std::string dbName);&&& &&&&&&& void setPort(unsigned int port);&&& private:&&& &&&&&&& bool IsC&&& &&&&&&& vector& vector&string& & resultL&&& &&&&&&& MYSQL mySQLC&&& &&&&&&& unsigned int DEFAULTPORT;&&& &&&&&&& char * HOSTS;&&& &&&&&&& char * USERNAME;&&& &&&&&&& char * PASSWORD;&&& &&&&&&& char * DBNAME;&&& };&&&
  #endif /* MYSQLMANAGER_H_ */
  /*&&& * MySQLManager.cpp&&& *&&& *&&& Created on: Feb 18, 2009&&& *&&&&&&&&&&& Author: Steven Wee&&& */&&& #include "MySQLManager.h"&&&
  MySQLManager::MySQLManager(string hosts, string userName, string password, string dbName, unsigned int port)&&& {&&& &&&&&&& IsConnected =&&& &&&&&&& this -&setHosts(hosts);&&&&&&&&&&& //&&& 设置主机IP地址&&& &&&&&&& this -&setUserName(userName);&&&&&&&&&&& //&&& 设置登录用户名&&& &&&&&&& this -&setPassword(password);&&&&&&&&&&& //&&& 设置登录密码&&& &&&&&&& this -&setDBName(dbName);&&&&&&&&&&& //&&& 设置数据库名&&& &&&&&&& this -&setPort(port);&&&&&&&&&&& //&&& 设置端口号&&& }&&&
  MySQLManager::~MySQLManager()&&& {&&& &&&&&&& this -&destroyConnection();&&& }&&&
  void MySQLManager::setDBName(string dbName)&&& {&&& &&&&&&& if ( dbName.empty() )&&& &&&&&&& {//&&&&&&& 用户没有指定数据库名&&& &&&&&&&&&&&&&&& std::cout && "DBName is null! Used default value: mysql" && std::&&& &&&&&&&&&&&&&&& this -&DBNAME = new char[5];&&& &&&&&&&&&&&&&&& strcpy(this -&DBNAME, "mysql");&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&DBNAME = new char[dbName.length()];&&& &&&&&&&&&&&&&&& strcpy(this -&DBNAME, dbName.c_str());&&& &&&&&&& }&&& }&&&
  void MySQLManager::setHosts(string hosts)&&& {&&& &&&&&&& if ( hosts.empty() )&&& &&&&&&& {//&&& 用户没有指定数据库IP地址&&& &&&&&&&&&&&&&&& std::cout && "Hosts is null! Used default value: localhost" && std::&&& &&&&&&&&&&&&&&& this -&HOSTS = new char[9];&&& &&&&&&&&&&&&&&& strcpy(this -&HOSTS, "localhost");&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&HOSTS = new char[hosts.length()];&&& &&&&&&&&&&&&&&& strcpy(this -&HOSTS, hosts.c_str());&&& &&&&&&& }&&& }&&&
  void MySQLManager::setPassword(string password)&&& {//&&& 用户没有指定密码&&& &&&&&&& if ( password.empty() )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Password is null! Used default value: " && std::&&& &&&&&&&&&&&&&&& this -&PASSWORD = new char[1];&&& &&&&&&&&&&&&&&& strcpy(this -&PASSWORD, "");&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&PASSWORD = new char[password.length()];&&& &&&&&&&&&&&&&&& strcpy(this -&PASSWORD, password.c_str());&&& &&&&&&& }&&& }&&&
  void MySQLManager::setPort(unsigned int port)&&& {//&&& 用户没有指定端口号,使用默认端口号&&& &&&&&&& if ( port )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Port number is null! Used default value: 0" && std::&&& &&&&&&&&&&&&&&& this -&DEFAULTPORT = 0;&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&DEFAULTPORT =&&& &&&&&&& }&&& }&&&
  void MySQLManager::setUserName(string userName)&&& {//&&& 用户没有指定登录用户名&&& &&&&&&& if ( userName.empty() )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "UserName is null! Used default value: root" && std::&&& &&&&&&&&&&&&&&& this -&USERNAME = new char[4];&&& &&&&&&&&&&&&&&& strcpy(this -&USERNAME, "root");&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&USERNAME = new char[userName.length()];&&& &&&&&&&&&&&&&&& strcpy(this -&USERNAME, userName.c_str());&&& &&&&&&& }&&& }&&&
  void MySQLManager::initConnection()&&& {&&& &&&&&&& if ( IsConnected )&&& &&&&&&& {//&&& 已经连接到服务器&&& &&&&&&&&&&&&&&& std::cout && "Is connected to server!" &&std::&&& &&&&&&&&&&&&&&&&&& &&&&&&& }&&& &&&&&&& mysql_init(&mySQLClient);//&&& 初始化相关对象&&& &&&&&&& if ( !mysql_real_connect( &mySQLClient, HOSTS, USERNAME, PASSWORD, DBNAME, DEFAULTPORT, NULL, 0) )&&& &&&&&&& {//&&& 连接到服务器&&& &&&&&&&&&&&&&&& std::cout && "Error connection to database: %s\n" && mysql_error(&mySQLClient) && std::&&& &&&&&&& }&&& &&&&&&& IsConnected =//&&& 修改连接标识&&& }&&&
  bool MySQLManager::runSQLCommand(string sql)&&& {&&& &&&&&&& if ( !IsConnected )&&& &&&&&&& {//&&& 没有连接到服务器&&& &&&&&&&&&&&&&&& std::cout && "Not connect to database!" && std::&&& &&&&&&&&&&&&&&&&&& &&&&&&& }&&& &&&&&&& if ( sql.empty() )&&& &&&&&&& {//&&& SQL语句为空&&& &&&&&&&&&&&&&&& std::cout && "SQL is null!" && std::&&& &&&&&&&&&&&&&&&&&& &&&&&&& }&&&
  MYSQL_RES *&&& &&&&&&& MYSQL_ROW&&&
  unsigned int i,j = 0;&&&
  StringTools stringT&&& &&&&&&& sql = stringTools.filterString(sql);&&&
  i = mysql_real_query(&mySQLClient,sql.c_str(),(unsigned int)strlen(sql.c_str()));//&&& 执行查询&&& &&&&&&& if ( i )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Error query from database: %s\n" && mysql_error(&mySQLClient) && std::&&& &&&&&&&&&&&&&&&&&& &&&&&&& }&&& &&&&&&& res = mysql_store_result(&mySQLClient);&&& &&&&&&& vector&string& objectV&&& &&&&&&& while( (row = mysql_fetch_row(res)) )&&& &&&&&&& {//&&& 遍历结果集&&& &&&&&&&&&&&&&&& objectValue.clear();&&& &&&&&&&&&&&&&&& for ( j = 0 ; j & mysql_num_fields(res) ; j++ )&&& &&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&& objectValue.push_back(row[j]);&&& &&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&& this -&resultList.push_back(objectValue);&&& &&&&&&& }&&& &&&&&&& mysql_free_result(res);&&&&&&&& //free result after you get the result&&&
  &&& }&&&
  vector& vector&string& & MySQLManager::getResult()&&& {&&& &&&&&&& return resultL&&& }&&&
  void MySQLManager::destroyConnection()&&& {&&& &&&&&&& mysql_close(&mySQLClient);&&& &&&&&&& this -&IsConnected =&&& }&&&
  bool MySQLManager::getConnectionStatus()&&& {&&& &&&&&&& return IsC&&& }
  三、修改建议
  本人在以后的完善中,打算把runSQLCommand(char * sql)函数分解成两个或者三个函数,分别执行select和insert等语句。
  在程序中,我并没有强制要求参数必须为const,可能会出现一些安全问题。本文仅起抛砖引玉的作用,希望有高手可以指点我程序中的问题。  在Linux下连接MSSQL是一件很痛苦的事,因为微软同志没有提供任何接口给开发人员,大约他们认为要用MSSQL的,只可能是windows的操作系统。还好,MSSQL是从Sybase衍生出来的,有一些哥们做了一些Sybase的Linux下的连接库,这些连接库同时也能支持MSSQL,FreeTDS就是这样的一个东东。
  这篇文章的受用读者,我想是那些希望在Linux或Unix下编写C或C++程序来连接MSSQL2000的兄弟们,因为我就是这样的。同时,那些写PHP的哥们也可以参考一下,当然如果你是用PHP的,你恐怕还要知道APACHE以及PHP脚本的安装,或者关于PHP自定义Module的开发,可以参考我以前写的一篇Blog(PHP5自定义Module开发)。
  下面开始我们的探索之旅:
  一、相关软件首先我们需要FreeTDS的安装包,相关文件下载在的1号FTP服务器里,下载地址:
  FTP地址:ftp://
  用户名:
  密码:
  在 2011年\4月\Linux下使用C/C++访问数据库
  下载方法见
  现在的最新版是0.82其次就是大家需要自己搭建C++的开发环境了。
  二、软件安装、配置# tar zxvf freetds-stable.tgz(解压)# ./configure --prefix=/usr/local/freetds \(指定FreeTDS安装路径) &&&& --with-tdsver=8.0 --enable-msdblib (设置TDS版本,支持SQL Server 2000)# make # make install 将freetds的库文件所在路径配置到LD_LIBRARY_PATH参数中: $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/freetds/lib/: 这么作的目的是为了避免加载FreeTds库文件加载不上的情况。三、程序开发不多说了,还是直接上代码:/*&&& * SyBaseManager.h&&& *&&& *&&& Created .: Feb 18, 2009&&& *&&&&&&&&&&& Author: Steven Wee&&& */&&&
  #ifndef SYBASEMANAGER_H_&&& #define SYBASEMANAGER_H_&&&
  #include "../Common/CheckStringTools.h"&&&
  #include &string&&&& #include &vector&&&& #include &iostream&&&& #include &assert.h&&&& #include &errno.h&&&& #include &stdlib.h&&&& #include &string.h&&&&
  #include &sybfront.h&&&& #include &sybdb.h&&&&
  class SybaseManager&&& {&&& public:&&& &&&&&&& SybaseManager(std::string hosts, std::string userName, std::string password, std::string dbName, unsigned int port);&&& &&&&&&& ~SybaseManager();&&& &&&&&&& /*&&& &&&&&&&& * Init SQL Server&&& &&&&&&&& * @param hosts:&&&&&&&& Host IP address&&& &&&&&&&& * @param userName:&&&&&&& Login UserName&&& &&&&&&&& * @param password:&&&&&&& Login Password&&& &&&&&&&& * @param dbName:&&&&&&& Database Name&&& &&&&&&&& * @param port:&&&&&&&&&&&&&&& Host listen port number&&& &&&&&&&& */&&& &&&&&&& void initConnection();&&& &&&&&&& /*&&& &&&&&&&& * Making query from database&&& &&&&&&&& * @param mysql:&&&&&&& MySQL Object&&& &&&&&&&& * @param sql:&&&&&&&&&&&&&&& Running SQL command&&& &&&&&&&& */&&& &&&&&&& bool runSQLCommand(std::string sql);&&& &&&&&&& /**&&& &&&&&&&& * Destroy MySQL object&&& &&&&&&&& * @param mysql&&&&&&&&&&&&&&& MySQL object&&& &&&&&&&& */&&& &&&&&&& void destroyConnection();&&& &&&&&&& bool getConnectionStatus();&&& &&&&&&& vector&vector&string& & getResult();&&& protected:&&& &&&&&&& void setUserName(std::string userName);&&& &&&&&&& void setHosts(std::string hosts);&&& &&&&&&& void setPassword(std::string password);&&& &&&&&&& void setDBName(std::string dbName);&&& &&&&&&& void setPort(unsigned int port);&&& private:&&& &&&&&&& bool IsC&&& &&&&&&& DBPROCESS *dbP&&& &&&&&&& vector& vector&string& & resultL&&& &&&&&&& unsigned int DEFAULTPORT;&&& &&&&&&& char * HOSTS;&&& &&&&&&& char * USERNAME;&&& &&&&&&& char * PASSWORD;&&& &&&&&&& char * DBNAME;&&& };&&&
  #endif /* SYBASEMANAGER_H_ */
  /*&&& * SyBaseManager.cpp&&& *&&& *&&& Created .: Feb 18, 2009&&& *&&&&&&&&&&& Author: Steven Wee&&& */&&& #include "SybaseManager.h"&&&
  SybaseManager::SybaseManager(std::string hosts, std::string userName, std::string password, std::string dbName, unsigned int port)&&& {&&& &&&&&&& IsConnected =&&& &&&&&&& this -&setHosts(hosts);&&& &&&&&&& this -&setUserName(userName);&&& &&&&&&& this -&setPassword(password);&&& &&&&&&& this -&setDBName(dbName);&&& &&&&&&& this -&setPort(port);&&& }&&&
  SybaseManager::~SybaseManager()&&& {&&& &&&&&&& destroyConnection();&&& }&&&
  void SybaseManager::setDBName(string dbName)&&& {&&& &&&&&&& if ( dbName.empty() )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "DBName is null! Used default value: master" && std::&&& &&&&&&&&&&&&&&& this -&DBNAME = new char[5];&&& &&&&&&&&&&&&&&& strcpy(this -&DBNAME, "master");&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&DBNAME = new char[dbName.length()];&&& &&&&&&&&&&&&&&& strcpy(this -&DBNAME, dbName.c_str());&&& &&&&&&& }&&& }&&&
  void SybaseManager::setHosts(string hosts)&&& {&&& &&&&&&& if ( hosts.empty() )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Hosts is null! Used default value: localhost" && std::&&& &&&&&&&&&&&&&&& this -&HOSTS = new char[9];&&& &&&&&&&&&&&&&&& strcpy(this -&HOSTS, "localhost");&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&HOSTS = new char[hosts.length()];&&& &&&&&&&&&&&&&&& strcpy(this -&HOSTS, hosts.c_str());&&& &&&&&&& }&&& }&&&
  void SybaseManager::setPassword(string password)&&& {&&& &&&&&&& if ( password.empty() )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Password is null! Used default value: " && std::&&& &&&&&&&&&&&&&&& this -&PASSWORD = new char[1];&&& &&&&&&&&&&&&&&& strcpy(this -&PASSWORD, "");&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&PASSWORD = new char[password.length()];&&& &&&&&&&&&&&&&&& strcpy(this -&PASSWORD, password.c_str());&&& &&&&&&& }&&& }&&&
  void SybaseManager::setPort(unsigned int port)&&& {&&& &&&&&&& if ( port )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Port number is null! Used default value: 0" && std::&&& &&&&&&&&&&&&&&& this -&DEFAULTPORT = 0;&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&DEFAULTPORT =&&& &&&&&&& }&&& }&&&
  void SybaseManager::setUserName(string userName)&&& {&&& &&&&&&& if ( userName.empty() )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "UserName is null! Used default value: sa" && std::&&& &&&&&&&&&&&&&&& this -&USERNAME = new char[4];&&& &&&&&&&&&&&&&&& strcpy(this -&USERNAME, "sa");&&& &&&&&&& }&&& &&&&&&& else&&& &&&&&&& {&&& &&&&&&&&&&&&&&& this -&USERNAME = new char[userName.length()];&&& &&&&&&&&&&&&&&& strcpy(this -&USERNAME, userName.c_str());&&& &&&&&&& }&&& }&&&
  void SybaseManager::initConnection()&&& {&&& &&&&&&& string Charset = "UTF-8";&&& &&&&&&& dbinit();&&& &&&&&&& LOGINREC *loginREC = dblogin();&&& &&&&&&& DBSETLUSER(loginREC, this -&USERNAME);&&& &&&&&&& DBSETLPWD(loginREC, this -&PASSWORD);&&& &&&&&&& DBSETLCHARSET(loginREC, Charset.c_str());&&& &&&&&&& dbProcess = dbopen(loginREC, this -&HOSTS);&&& &&&&&&& if ( dbProcess == FAIL )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Connect to SQL Server failed!" && std::&&& &&&&&&& }&&& &&&&&&& if ( dbuse( dbProcess, this -&DBNAME ) == FAIL )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Use table failed!" && std::&&& &&&&&&& }&&& }&&&
  bool SybaseManager::runSQLCommand( string sql )&&& {&&& &&&&&&& dbcmd(dbProcess, sql.c_str());&&& &&&&&&& if ( dbsqlexec(dbProcess) == FAIL )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& std::cout && "Query from database failed!" && std::&&& &&&&&&& }&&& &&&&&&& DBINT result_&&& &&&&&&& vector&string& objectV&&& &&&&&&& StringTools stringT&&&
  sql = stringTools.filterString(sql);&&&
  while ( (result_code = dbresults(dbProcess)) != NO_MORE_RESULTS )&&& &&&&&&& {&&& &&&&&&&&&&&&&&& struct Column&&& &&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&& char* colN&&& &&&&&&&&&&&&&&&&&&&&&&& char* colB&&& &&&&&&&&&&&&&&&&&&&&&&& int colType, colSize, colS&&& &&&&&&&&&&&&&&& } *columns, *pC&&& &&&&&&&&&&&&&&& int nC&&& &&&&&&&&&&&&&&& int rowNo;&&& &&&&&&&&&&&&&&& if ( result_code == SUCCEED )&&& &&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&& nColumns = dbnumcols(dbProcess);&&& &&&&&&&&&&&&&&&&&&&&&&& if ( (columns = (Column*)calloc(nColumns, sizeof(struct Column))) == NULL )&&& &&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& std::cout && "Error at bind data" && std::&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&&&&&&&&&& for ( pCol = pCol - columns & nC pCol++ )&&& &&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& int colNo = pCol - columns + 1;&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& pCol -&colName = dbcolname(dbProcess, colNo);&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& pCol -&colType = dbcoltype(dbProcess, colNo);&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& pCol -&colSize = dbcollen(dbProcess, colNo);&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& if ( SYBCHAR != pCol -&colType )&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& pCol -&colSize = dbwillconvert(pCol -&colType, SYBCHAR);&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&
  if ( (pCol -&colBuffer = (char*)calloc(1, pCol -&colSize + 1)) == NULL )&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& std::cout && "Check column buffer error!" && std::&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&
  if ( dbbind(dbProcess, colNo, STRINGBIND, pCol -&colSize + 1, (BYTE*)pCol -&colBuffer) == FAIL )&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& std::cout && "Running dbbind() error!" && std::&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&&
  if ( dbnullbind(dbProcess, colNo, &pCol -&colStatus) == FAIL )&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& std::cout && "Running dbnullbind() error!" && std::&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&&&&&&&&&& }&&&
  while ( (rowNo = dbnextrow(dbProcess)) != NO_MORE_ROWS )&&& &&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& objectValue.clear();&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& switch ( rowNo )&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& case REG_ROW:&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& for ( pCol = pCol - columns & nC pCol++ )&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& const char* columnBuffer = pCol -&colStatus == -1 ? "NULL" : pCol -&colB&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& objectValue.push_back(stringTools.Trim(columnBuffer));&&&&&&& //&&&&&&& std::cout && columnBuffer && std::&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& case BUF_FULL:&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& assert( rowNo != BUF_FULL );&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& case FAIL:&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& std::cout && "Get result error!" && std::&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& default:&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& std::cout && "Get result ignore, row number:" && rowNo && std::&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& this -&resultList.push_back(objectValue);&&& &&&&&&&&&&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&&&&&&&&&& for ( pCol = pCol - columns & nC pCol++ )&&& &&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& free( pCol -&colBuffer );&&& &&&&&&&&&&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&&&&&&&&&& free( columns );&&& &&&&&&&&&&&&&&&&&&&&&&& /*&&& &&&&&&&&&&&&&&&&&&&&&&& if ( DBCOUNT(dbProcess) & -1 )&&& &&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& std::cout && "Affected rows:" && DBCOUNT(dbProcess) && std::&&& &&&&&&&&&&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&&&&&&&&&& */&&& &&&&&&&&&&&&&&&&&&&&&&& if ( dbhasretstat(dbProcess) == TRUE )&&& &&&&&&&&&&&&&&&&&&&&&&& {&&& &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& std::cout && "Procedure returned " && dbhasretstat(dbProcess) && std::&&& &&&&&&&&&&&&&&&&&&&&&&& }&&& &&&&&&&&&&&&&&& }&&& &&&&&&& }&&& &&&&&&&&&& }&&&
  void SybaseManager::destroyConnection()&&& {&&& &&&&&&& dbclose(dbProcess);&&& }&&&
  bool SybaseManager::getConnectionStatus()&&& {&&& &&&&&&& return IsC&&& }&&&
  vector& vector&string& & SybaseManager::getResult()&&& {&&& &&&&&&& return this -&resultL&&& }
  四、修改建议本人在以后的完善中,打算把runSQLCommand(char * sql)函数分解成两个或者三个函数,分别执行select和insert等语句。
  在程序中,我并没有强制要求参数必须为const,可能会出现一些安全问题。本文仅起抛砖引玉的作用,希望有高手可以指点我程序中的问题。  一、什么是OCI?开发基于Oracle数据库的应用程序,我们可以选择多种工具,不仅可以用一般的数据库开发技术,诸如ADO(ActiveX Data Objects)、ODBC(Open DataBase Connectivity)等等,同时,也可以用Oracle公司提供的专门的开发工具,诸如Pro C_C++,OCI(Oracle Call Intedace)等等。比较这几种方式,前者因为是通用技术,开发起来比较容易,但是有一个致命的弱点就是诸如ADO之类的通用技术的速度太慢,如果我们要开发管理海量数据的数据库,比如影像数据库,那么,这种速度我们是不能忍受的。而OCI虽然开发起来难度大一些,但是它的速度极快,而且是一种底层接口,几乎可以操纵Oracle数据库的任何对象。
  二、OCI简介OCI(Oracle Call Intedace,即0racle调用层接口)是Oracle公司提供的由头文件和库函数等组成的一个访问Oracle数据库的应用程序编程接口(application programming interface& API),它允许开发人员在第三代编程语言(包括C, C++, COBOL 与 FORTRAN)中通过SQL(Structure Query Language)来操纵Oracle数据库,而且OCI在一定程度上支持第三代编程语言(诸如C, C++, COBOL 与 FORTRAN)的数据类型、语法等等。OCI的显著特点是全面支持Oracle的面向对象技术,同时OCI还具有如下的一些特点: 1)非常有利于应用程序的设计; 2)高度控制应用程序的执行; 3)允许开发人员应用已熟悉的第三代程序设计语言来应用OCI; 4)支持动态SQL; 5)几乎所有的Oracle的开发工具都支持OCI; 6)通过回调技术(callbacks)来实现动态绑定与定义; 7)通过OCI的描述函数可以获取Oracle数据库的各种参数; 8)增强了数组在DML(data manipulation language)语言中的应用; OCI接口支持Windows NT和Windows 95/98/2000/XP操作系统,它所支持的C语言编译器包括Borland C++和MiroSoft VisualC++等。在使用0CI开发Oralce数据库应用程序之前,应首先安装这些操作系统和C语言编译工具。在选择安装OCI开发工具包后,Oracle安装程序将0CI文件拷贝到oracle主目录内的以下子目录中: ..BIN\:执行文件和帮助文件: ..\OCIINCLUDE头文件;
  三、开发前的注意事项首先,为了防止某些动态链接库出问题,建议在安装了Oracle客户端的机器上进行开发、运行。其次,使用OCI开发的程序,需要使用Oracle客户端的tnsnames.ora这个配置文件,所以在开发前需要使用netca来配置好相关内容。第三,Linux下的系统环境变量需要设置好。需要设置的环境变量包括ORACLE_HOME、ORACLE_SID、TNS_ADMIN,其中TNS_ADMIN指定到tnsnames.ora所在的文件夹。
  四、程序开发:还是直接用代码说话吧/* * Common.h * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */
  #ifndef COMMON_H_ #define COMMON_H_
  #include &unistd.h& #include &oci.h& #include &ctype.h&
  #include &string& #include &iostream& #include &vector&
  #include &string.h&
  #endif /* COMMON_H_ */
  /* * Exception.h * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */
  #ifndef EXCEPTION_H_ #define EXCEPTION_H_
  class Exception { public: & Exception(int errno); & virtual char * GetErrMsg() = 0; & virtual char * GetErrFunc() = 0; & virtual int GetErrNo() = 0; protected: & int m_iErrNo; & char m_sErrBuff[512]; & char m_sErrFunc[128]; };
  #endif /* EXCEPTION_H_ */
  /* * Exception.cpp * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */ #include "Exception.h"
  Exception::Exception(int errno) { & this -&m_iErrNo = & this -&m_sErrBuff[0] = 0; & this -&m_sErrFunc[0] = 0; }
  /* * OCIException.h * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */
  #ifndef OCIEXCEPTION_H_ #define OCIEXCEPTION_H_
  #include "Common.h" #include "Exception.h"
  class OCIException : public Exception { public: & OCIException(sb4 errno); & OCIException(sb4 errno, char * errfunc); & OCIException(sb4 errno, dvoid * erroci); & OCIException(sb4 errno, dvoid * erroci, char * errfunc);
  char * GetErrMsg(); & char * GetErrFunc(); & int GetErrNo(); private: & void CheckError(sb4 errno); & void CheckError(sb4 errno, dvoid * erroci); };
  #endif /* OCIEXCEPTION_H_ */
  /* * OCIException.cpp * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */ #include "OCIException.h"
  void OCIException::CheckError(sb4 errno) { & text errBuff[512]; & switch ( errno ) & { & case OCI_SUCCESS: &&& & case OCI_SUCCESS_WITH_INFO: &&& sprintf( this -&m_sErrBuff, "OCI_SUCCESS_WITH_INFO" ); &&& & case OCI_NEED_DATA: &&& sprintf( this -&m_sErrBuff, "OCI_NEED_DATA" ); &&& & case OCI_NO_DATA: &&& sprintf( this -&m_sErrBuff, "OCI_NO_DATA" ); &&& & case OCI_ERROR: &&& sprintf( this -&m_sErrBuff, "OCI_ERROR" ); &&& & case OCI_INVALID_HANDLE: &&& sprintf( this -&m_sErrBuff, "OCI_INVALID_HANDLE" ); &&& & case OCI_STILL_EXECUTING: &&& sprintf( this -&m_sErrBuff, "OCI_STILL_EXCUTING" ); &&& & case OCI_CONTINUE: &&& sprintf( this -&m_sErrBuff, "OCI_CONTINUE" ); &&& & default: &&& & } }
  void OCIException::CheckError(sb4 errno, dvoid * erroci) { & text errBuff[512]; & switch ( errno ) & { & case OCI_SUCCESS: &&& & case OCI_SUCCESS_WITH_INFO: &&& sprintf( this -&m_sErrBuff, "OCI_SUCCESS_WITH_INFO" ); &&& & case OCI_NEED_DATA: &&& sprintf( this -&m_sErrBuff, "OCI_NEED_DATA" ); &&& & case OCI_NO_DATA: &&& sprintf( this -&m_sErrBuff, "OCI_NO_DATA" ); &&& & case OCI_ERROR: &&& OCIErrorGet( (dvoid*)erroci, (ub4)1, (text*)NULL, &this -&m_iErrNo, errBuff, (ub4)sizeof(errBuff), OCI_HTYPE_ERROR); &&& sprintf( this -&m_sErrBuff, "%.*s", strlen((char*) errBuff) - 1, errBuff); &&& & case OCI_INVALID_HANDLE: &&& sprintf( this -&m_sErrBuff, "OCI_INVALID_HANDLE" ); &&& & case OCI_STILL_EXECUTING: &&& sprintf( this -&m_sErrBuff, "OCI_STILL_EXCUTING" ); &&& & case OCI_CONTINUE: &&& sprintf( this -&m_sErrBuff, "OCI_CONTINUE" ); &&& & default: &&& & } }
  OCIException::OCIException(sb4 errno) : Exception( (int)errno ) { & this -&CheckError(errno); }
  OCIException::OCIException(sb4 errno, char * errfunc) : Exception( (int)errno ) { & strcpy( this -&m_sErrBuff, errfunc); & this -&CheckError(errno); }
  OCIException::OCIException(sb4 errno, dvoid * erroci) : Exception( (int)errno ) { & this -&CheckError(errno, erroci); }
  OCIException::OCIException(sb4 errno, dvoid * erroci, char * errfunc) : Exception( (int)errno ) { & strcpy( this -&m_sErrBuff, errfunc); & this -&CheckError(errno, erroci); }
  char * OCIException::GetErrMsg() { & return this -&m_sErrB }
  char * OCIException::GetErrFunc() { & return this -&m_sErrF }
  int OCIException::GetErrNo() { & return this -&m_iErrNo; }
  /* * OCIError.h * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */
  #ifndef OCIERROR_H_ #define OCIERROR_H_
  #include "Common.h"
  class OCIError { public: & static void PrintError(int errno); & static void PrintError(int errno, char * errfunc); private: & static void CheckError(); & static int m_iErrNo; & static char m_sErrBuff[512]; & static char m_sErrFunc[128]; };
  #endif /* OCIERROR_H_ */
  /* * OCIError.cpp * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */ #include "OCIError.h"
  int OCIError::m_iErrNo = 0; char OCIError::m_sErrBuff[512] = {0}; char OCIError::m_sErrFunc[128] = {0};
  void OCIError::CheckError() { & switch ( OCIError::m_iErrNo ) & { & case OCI_SUCCESS: &&& & case OCI_SUCCESS_WITH_INFO: &&& sprintf( OCIError::m_sErrBuff, "OCI_SUCCESS_WITH_INFO" ); &&& & case OCI_NEED_DATA: &&& sprintf( OCIError::m_sErrBuff, "OCI_NEED_DATA" ); &&& & case OCI_NO_DATA: &&& sprintf( OCIError::m_sErrBuff, "OCI_NO_DATA" ); &&& & case OCI_ERROR: &&& sprintf( OCIError::m_sErrBuff, "OCI_ERROR" ); &&& & case OCI_INVALID_HANDLE: &&& sprintf( OCIError::m_sErrBuff, "OCI_INVALID_HANDLE" ); &&& & case OCI_STILL_EXECUTING: &&& sprintf( OCIError::m_sErrBuff, "OCI_STILL_EXCUTING" ); &&& & case OCI_CONTINUE: &&& sprintf( OCIError::m_sErrBuff, "OCI_CONTINUE" ); &&& & default: &&& & } }
  void OCIError::PrintError(int errno) { & OCIError::m_iErrNo = & OCIError::CheckError(); & std::cout && OCIError::m_sErrBuff && std:: }
  void OCIError::PrintError(int errno, char * errfunc ) { & OCIError::m_iErrNo = & strcpy(OCIError::m_sErrFunc, errfunc); & OCIError::CheckError(); & std::cout && OCIError::m_sErrFunc && OCIError::m_sErrBuff && std:: }
  /* * OCIDB.h * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */
  #ifndef OCIDB_H_ #define OCIDB_H_
  #include "Common.h" #include "../Common/CheckStringTools.h"
  #define MAX_VAR_LEN 10 #define MAX_BUFFER_SIZE 32767
  typedef struct { & ub2&&& VarT & char *& VarN & int&&& VarL & union { &&& char * ValueC &&& float * ValueF &&& int * ValueI &&& OCILobLocator *lobL & }; } TBindV
  typedef struct{ & char VarName[MAX_VAR_LEN]; & unsigned char VarT & unsigned char VarS & unsigned char VarP & unsigned char VarS & unsigned char VarIsN & union { &&& char * ValueC &&& float * ValueF &&& int * ValueI &&& OCILobLocator *lobL & }; } TSelectV
  #define MAX_BINDVAR_COUNT 10 #define MAX_SELECTVAR_COUNT 10
  #define TYPE_INT 0 #define TYPE_FLOAT 1 #define TYPE_STRING 2 #define TYPE_BLOB 3
  class OCIDB { private: & dvoid * & OCIEnv * m_pOCIE & OCIError * m_pOCIE
  OCISvcCtx * m_pOCISvcC & OCIServer * m_pOCIS & OCISession * m_pOCIS
  OCIStmt * m_pOCIS & OCIBind * m_pOCIB & OCIDefine * m_pOCID & OCIParam * m_pOCIP
  TBindVar m_BindVars[MAX_BINDVAR_COUNT]; & TSelectVar m_SelectVars[MAX_SELECTVAR_COUNT];
  int m_iBindVarsC & int m_iSelectVarsC
  char m_SUSEr[10]; & char m_sPwd[10]; & char m_sDBName[10];
  int UserFetch(); & int UserGetInt(int index); & int UserGetInt(char * name); & char * UserGetString(int index); & char * UserGetString(char * name); & char * UserGetBlob(int index); & char * UserGetBlob(char * name); & float UserGetFloat(int index); & float UserGetFloat(char * name); & void inline StrUpper(char *str); & bool inline StrCmp(const char *ori, const char *des); & vector& vector&string& & resultL protected: & char * getBlobValue(); public: & OCIDB(); & ~OCIDB();
  /* Single User, Single Connection */ & int Single_Conn(); & void Single_Disc();
  /* Multiple Sessions or Connections */ & int Multiple_Conn(); & void Multiple_Disc();
  /* Execute SQL with none query */ & int ExcuteSQL(char * sql);
  /* Execute SQL with bind vars */ & void BindInitVars(); & void BindClearVars(); & void BindAddVar(char * name, char * value); & void BindAddVar(char * name, int * value); & int BindSQL(char * sql);
  /* Prepare SQL*/ & int UserPrepare(char * sql); & int UserFree(); & int UserBind(char * name, char * value); & int UserBind(char * name, int value); & int UserExecute(); & int UserCommit(); & int UserRollback();
  int UserSelect(char * sql); & int UserSelectFree();
  vector& vector&string& & getResult(); };
  #endif /* OCIDB_H_ */
  /* * OCIDB.cpp * *&&& Created .: Mar 1, 2009 *&&&&&&&&&&& Author: Steven Wee */ #include "OCIDB.h" #include "OCIException.h" #include "OCIError.h"
  OCIDB::OCIDB() { & strcpy(this -&m_sUser, "webtest"); & strcpy(this -&m_sPwd, "ns0528AO"); & strcpy(this -&m_sDBName, "NSTEST");
  this -&BindInitVars(); }
  OCIDB::~OCIDB() {
  int OCIDB::Single_Conn() { & try & { &&& &&& /* &&&& * OCIEnvCreate(&envhp, mode, (const dvoid *)0, 0, 0, 0, (size_t)0, (dvoid **)0 ); &&&& */ &&& errno = OCIEnvCreate( &this -&m_pOCIEnv, OCI_OBJECT, (dvoid *)0, (dvoid *(*)(dvoid *, size_t))0, (dvoid *(*)(dvoid *, dvoid *, size_t))0, (void (*)(dvoid *, dvoid *))0, (size_t)0, (dvoid **)0); &&& if(errno) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Single_Conn OCIEnvCreate"); &&& }
  /* Create Error Handle */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCIError, OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0); &&& if(errno) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Single_Conn OCIHandleAlloc"); &&& }
  /* Login */ &&& errno = OCILogon(this -&m_pOCIEnv, this -&m_pOCIError, &this -&m_pOCISvcCtx, (const OraText*)this -&m_sUser, &&&&&&& strlen(this -&m_sUser), (const OraText*)this -&m_sPwd, strlen(this -&m_sPwd), (const OraText*)this -&m_sDBName, &&&&&&& strlen(this -&m_sDBName)); &&& if(errno) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::Single_Conn OCILogin2"); &&& }
  return 0; & } & catch ( OCIException &ex) & { &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  void OCIDB::Single_Disc() { & & /* Log off */ & errno = OCILogoff(m_pOCISvcCtx, this -&m_pOCIError); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Single_Disc OCILogoff"); & }
  /* Free errno */ & errno = OCIHandleFree((dvoid *)this -&m_pOCIError, (ub4)OCI_HTYPE_ERROR); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Single_Disc OCIHandleFree"); & }
  /* Free Env Handle */ & errno = OCIHandleFree((dvoid *)this -&m_pOCIEnv, (ub4)OCI_HTYPE_ENV); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Single_Disc OCIHandleFree"); & } }
  int OCIDB::Multiple_Conn() { & try & { &&&
  errno = OCIInitialize( (ub4)OCI_DEFAULT, (dvoid *)0, (dvoid *(*)(dvoid *, size_t))0, (dvoid *(*)(dvoid *, dvoid *, size_t))0, (void (*)(dvoid *, dvoid *))0 ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIInitialize"); &&& } &&& errno = OCIEnvInit( (OCIEnv **)&this -&m_pOCIEnv, OCI_DEFAULT, (size_t)0, (dvoid **)0); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIEnvInit"); &&& }
  /* Allocate Error Handle */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCIError, OCI_HTYPE_ERROR, (size_t)0, (dvoid **)0); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIHandleAlloc Error"); &&& }
  /* Allocate Server Context Handle */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCISvcCtx, OCI_HTYPE_SVCCTX, (size_t)0, (dvoid **)0); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIHandleAlloc SvcCtx"); &&& }
  /* Allocate Server Handle */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCIServer, OCI_HTYPE_SERVER, (size_t)0, (dvoid **)0); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIHandleAlloc Server"); &&& }
  /* Set Server into ServerContext */ &&& errno = OCIAttrSet( (dvoid *)this -&m_pOCISvcCtx, OCI_HTYPE_SVCCTX, (dvoid *)this -&m_pOCIServer, 0, OCI_ATTR_SERVER, (OCIError *)this -&m_pOCIError); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIAttrSet Server"); &&& }
  /* Attach Server */ &&& errno = OCIServerAttach(this -&m_pOCIServer, this -&m_pOCIError, (text *)this -&m_sDBName, strlen(this -&m_sDBName), OCI_DEFAULT); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIServerAttach"); &&& }
  /* Allocate Session Handle */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCISession, (ub4)OCI_HTYPE_SESSION, (size_t)0, (dvoid **)0); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIHandleAlloc Session"); &&& }
  /* Set Session into ServerContext */ &&& errno = OCIAttrSet( (dvoid *)this -&m_pOCISvcCtx, (ub4)OCI_HTYPE_SVCCTX, (dvoid *)this -&m_pOCISession, (ub4)0, (ub4)OCI_ATTR_SESSION, (OCIError *)this -&m_pOCIError); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIAttrSet Session"); &&& }
  /* Set Session UserName */ &&& errno = OCIAttrSet( (dvoid *)this -&m_pOCISession, OCI_HTYPE_SESSION, (dvoid *)this -&m_sUser, strlen(this -&m_sUser), OCI_ATTR_USERNAME, (OCIError *)this -&m_pOCIError); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIAttrSet UserName"); &&& }
  /* Set Session Password */ &&& errno = OCIAttrSet( (dvoid *)this -&m_pOCISession, OCI_HTYPE_SESSION, (dvoid *)this -&m_sPwd, (ub4)strlen(this -&m_sPwd), (ub4)OCI_ATTR_PASSWORD, (OCIError *)this -&m_pOCIError); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::Multiple_Conn OCIAttrSet Password"); &&& }
  /* Session Begin */ &&& errno = OCISessionBegin(this -&m_pOCISvcCtx, this -&m_pOCIError, this -&m_pOCISession, OCI_CRED_RDBMS, OCI_DEFAULT); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::Multiple_Conn OCISessionBegin"); &&& } &&& return 0; & } & catch (OCIException &ex) & { &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  void OCIDB::Multiple_Disc() { &
  /* End Session */ & errno = OCISessionEnd(this -&m_pOCISvcCtx, this -&m_pOCIError, this -&m_pOCISession, (ub4)OCI_DEFAULT); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Multiple_Disc OCISessionEnd"); & }
  /* Free Session */ & errno = OCIHandleFree( (dvoid *)this -&m_pOCISession, (ub4)OCI_HTYPE_SESSION ); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Multiple_Disc OCIHandleFree Session"); & }
  /* Detach Server */ & errno = OCIServerDetach(this -&m_pOCIServer, this -&m_pOCIError, OCI_DEFAULT); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Multiple_Disc OCIServerDetach"); & }
  /* Free Server */ & errno = OCIHandleFree( (dvoid *)this -&m_pOCIServer, (ub4)OCI_HTYPE_SERVER ); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Multiple_Disc OCIHandleFree Server"); & }
  /* Free ServerContext */ & errno = OCIHandleFree( (dvoid *)this -&m_pOCISvcCtx, (ub4)OCI_HTYPE_SVCCTX ); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Multiple_Disc OCIHandleFree ServerContext"); & }
  /* Free Error */ & errno = OCIHandleFree( (dvoid *)this -&m_pOCIError, (ub4)OCI_HTYPE_ERROR ); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Multiple_Disc OCIHandleFree Error"); & }
  /* Free Env */ & errno = OCIHandleFree( (dvoid *)this -&m_pOCIEnv, (ub4)OCI_HTYPE_ENV ); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::Multiple_Disc OCIHandleFree Env"); & } }
  int OCIDB::ExcuteSQL(char * sql) { & & try & { &&& /* Allocate Stmt */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCIStmt, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::ExcuteSQL OCIHandleAlloc"); &&& }
  errno = OCIStmtPrepare(this -&m_pOCIStmt, this -&m_pOCIError, (const OraText *)sql, (ub4)strlen(sql), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::ExcuteSQL OCIStmtPrepare"); &&& }
  errno = OCIStmtExecute(this -&m_pOCISvcCtx, this -&m_pOCIStmt, this -&m_pOCIError, (ub4)1, (ub4)0, (const OCISnapshot *)NULL, (OCISnapshot *)NULL, OCI_DEFAULT); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::ExcuteSQL OCIStmtExecute"); &&& }
  errno = OCITransCommit( this -&m_pOCISvcCtx, this -&m_pOCIError, 0); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::ExcuteSQL OCITransCommit"); &&& }
  errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT ); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::ExcuteSQL OCIHandleFree"); &&& } &&& return 0; & } & catch (OCIException &ex) & { &&& /* Rollback */ &&& errno = OCITransRollback( this -&m_pOCISvcCtx, this -&m_pOCIError, 0); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::ExcuteSQL OCITransRollback"); &&& } &&& /* Free Stmt */ &&& errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::ExcuteSQL OCIHandleFree"); &&& } &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  void OCIDB::BindInitVars() { & & for( i = 0 ; i & MAX_BINDVAR_COUNT - 1 ; i++ ) & { &&& this -&m_BindVars[i].VarType = 0; &&& this -&m_BindVars[i].VarName = 0; &&& this -&m_BindVars[i].VarLen = 0; &&& this -&m_BindVars[i].ValueChar = 0; & } & this -&m_iBindVarsCount = 0; }
  void OCIDB::BindClearVars() { & & for( i = 0 ; i & m_iBindVarsCount - 1 ; i++ ) & { &&& delete [] this -&m_BindVars[i].VarN &&& if ( this -&m_BindVars[i].VarType == SQLT_STR ) &&&&& delete [] this -&m_BindVars[i].ValueC &&& if ( this -&m_BindVars[i].VarType == SQLT_INT ) &&&&& delete [] this -&m_BindVars[i].ValueI
  this -&m_BindVars[i].VarType = 0; &&& this -&m_BindVars[i].VarName = 0; &&& this -&m_BindVars[i].VarLen = 0; &&& this -&m_BindVars[i].ValueChar = 0; & } & this -&m_iBindVarsCount = 0; }
  void OCIDB::BindAddVar(char * name, char * value) { & if ( this -&m_iBindVarsCount &= MAX_BINDVAR_COUNT ) &&& & this -&m_BindVars[this -&m_iBindVarsCount].VarType = SQLT_STR; & this -&m_BindVars[this -&m_iBindVarsCount].VarName = new char[strlen(name) + 1]; & strcpy( this -&m_BindVars[this -&m_iBindVarsCount].VarName, name);
  this -&m_BindVars[this -&m_iBindVarsCount].ValueChar = new char[strlen(value) + 1]; & strcpy( this -&m_BindVars[this -&m_iBindVarsCount].ValueChar, value); & this -&m_BindVars[this -&m_iBindVarsCount].VarLen = strlen(value) + 1;
  this -&m_iBindVarsCount++; }
  void OCIDB::BindAddVar(char * name, int * value) { & if ( this -&m_iBindVarsCount &= MAX_BINDVAR_COUNT ) &&& & this -&m_BindVars[this -&m_iBindVarsCount].VarType = SQLT_INT; & this -&m_BindVars[this -&m_iBindVarsCount].VarName = new char[strlen(name) + 1]; & strcpy( this -&m_BindVars[this -&m_iBindVarsCount].VarName, name);
  this -&m_BindVars[this -&m_iBindVarsCount].ValueInt = & this -&m_BindVars[this -&m_iBindVarsCount].ValueInt = & this -&m_BindVars[this -&m_iBindVarsCount].VarLen = sizeof(int);
  this -&m_iBindVarsCount++; }
  int OCIDB::BindSQL(char * sql) { & if( this -&m_iBindVarsCount == 0 ) &&& return -1; & & try & { &&& /* Allocate Stmt */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCIStmt, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::BindSQL OCIHandleAlloc Stmt"); &&& } &&& /* Prepare Stmt */ &&& errno = OCIStmtPrepare( this -&m_pOCIStmt, this -&m_pOCIError, (const OraText *)sql, (ub4)strlen(sql), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::BindSQL OCIStmtPrepare"); &&& } &&& /* Bind Vars */ &&& &&& for ( i = 0 ; i & m_iBindVarsCount - 1 ; i++ ) &&& { &&&&& /* Bind By Name */ &&&&& errno = OCIBindByName( this -&m_pOCIStmt, &this -&m_pOCIBind, this -&m_pOCIError, (text *)this -&m_BindVars[i].VarName, -1, &&&&&&&&& (dvoid *)this -&m_BindVars[i].ValueChar, this -&m_BindVars[i].VarLen, this -&m_BindVars[i].VarType, (dvoid *)0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, OCI_DEFAULT);
  if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::BindSQL OCIBindByName"); &&&&& } &&&&& /* &&&&& errno = OCIBindByPos( this -&m_pOCIStmt, &this -&m_pOCIBind, this -&m_pOCIError, i + 1, (dvoid *)this -&m_BindVars[i].ValueChar, &&&&&&&&& this -&m_BindVars[i].VarLen, this -&m_BindVars[i].VarType, (dvoid *)0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, OCI_DEFAULT);
  if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::BindSQL OCIBindByPos"); &&&&& } &&&&& */ &&& } &&& /* Execute SQL */ &&& errno = OCIStmtExecute( this -&m_pOCISvcCtx, this -&m_pOCIStmt, this -&m_pOCIError, (ub4)1, (ub4)0, (const OCISnapshot *)NULL, (OCISnapshot *)NULL, OCI_DEFAULT); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::BindSQL OCIStmtExecute"); &&& } &&& /*& Commit */ &&& errno = OCITransCommit( this -&m_pOCISvcCtx, this -&m_pOCIError, 0); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::BindSQL OCITransCommit"); &&& } &&& /* Free Stmt */ &&& errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::BindSQL OCIHandleFree"); &&& } &&& /* Clear Vars */ &&& this -&BindClearVars(); &&& return 0; & } & catch ( OCIException &ex ) & { &&& /* Rollback */ &&& errno = OCITransRollback( this -&m_pOCISvcCtx, this -&m_pOCIError, 0); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::BindSQL OCITransRollback"); &&& } &&& /* Free Stmt */ &&& errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::BindSQL OCIHandleFree"); &&& } &&& this -&BindClearVars(); &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  int OCIDB::UserPrepare(char * sql) { & & try & { &&& /* Allocate Stmt */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCIStmt, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0 ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::UserPrepare OCIHandleAlloc"); &&& } &&& /* Prepare Stmt */ &&& errno = OCIStmtPrepare( this -&m_pOCIStmt, this -&m_pOCIError, (const OraText *)sql, (ub4)strlen(sql), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, (char *)"OCIDB::UserPrepare OCIStmtPrepare"); &&& } &&& return 0; & } & catch ( OCIException &ex ) & { &&& /* Free Stmt */ &&& errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT ); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::UserPrepare Ex OCIHandleFree"); &&& } &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  int OCIDB::UserFree() { & & /* Free Stmt */ & errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT ); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::UserFree OCIHandleFree"); &&& return -1; & } & return 0; }
  int OCIDB::UserBind(char * name, char * value) { & & try & { &&& errno = OCIBindByName( this -&m_pOCIStmt, &this -&m_pOCIBind, this -&m_pOCIError, (text *)name, -1, &&&&&&& (dvoid *)value, strlen(value) + 1, SQLT_STR, (dvoid *)0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, OCI_DEFAULT ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserBind OCIBindByName"); &&& } &&& return 0; & } & catch ( OCIException &ex ) & { &&& /* Free Stmt */ &&& errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT ); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::UserBind Ex OCIHandleFree"); &&& } &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  int OCIDB::UserBind(char * name, int value) { & & try & { &&& int val = &&& errno = OCIBindByName( this -&m_pOCIStmt, &this -&m_pOCIBind, this -&m_pOCIError, (text *)name, -1, &&&&&&& (dvoid *)&val, sizeof(int), SQLT_INT, (dvoid *)0, (ub2 *)0, (ub2 *)0, (ub4)0, (ub4 *)0, OCI_DEFAULT ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserBind OCIBindByName"); &&& } &&& return 0; & } & catch ( OCIException &ex ) & { &&& /* Free Stmt */ &&& errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT ); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::UserBind Ex OCIHandleFree"); &&& } &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  int OCIDB::UserExecute() { & & try & { &&& errno = OCIStmtExecute( this -&m_pOCISvcCtx, this -&m_pOCIStmt, this -&m_pOCIError, (ub4)1, (ub4)0, &&&&&&& (const OCISnapshot *)NULL, (OCISnapshot *)NULL, OCI_DEFAULT ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserExecute OCIBindByName"); &&& } &&& return 0; & } & catch ( OCIException &ex ) & { &&& /* Free Stmt */ &&& errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT ); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::UserExecute Ex OCIHandleFree"); &&& } &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  int OCIDB::UserCommit() { & & errno = OCITransCommit( this -&m_pOCISvcCtx, this -&m_pOCIError, 0); & if ( errno ) & { &&& OCIError::PrintError(errno, (char *)"OCIDB::UserCommit OCITransCommit"); &&& return -1; & } & return 0; }
  int OCIDB::UserSelect(char * sql) { & & try & { &&& /* Allocate Stmt */ &&& errno = OCIHandleAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_pOCIStmt, OCI_HTYPE_STMT, (size_t)0, (dvoid **)0 ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIHandleAlloc"); &&& } &&& /* Prepare Stmt */ &&& errno = OCIStmtPrepare( this -&m_pOCIStmt, this -&m_pOCIError, (const OraText *)sql, (ub4)strlen(sql), (ub4)OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIStmtPrepare"); &&& } &&& /* Execute Stmt */ &&& errno = OCIStmtExecute( this -&m_pOCISvcCtx, this -&m_pOCIStmt, this -&m_pOCIError, (ub4)0, (ub4)0, (OCISnapshot *)NULL, (OCISnapshot *)NULL, OCI_DEFAULT ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIStmtExecute"); &&& }
  errno = OCIAttrGet( this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT, (dvoid *)&this -&m_iSelectVarsCount, (ub4 *)0, (ub4)OCI_ATTR_PARAM_COUNT, this -&m_pOCIError ); &&& if ( errno ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIAttrGet"); &&& } &&& int iL &&& char * sN &&& ub2 iSize, iPrecision, iT &&& ub1 iScale, iIsN
   &&& for ( i = 0 ; i & this -&m_iSelectVarsC i++ ) &&& { &&&&& sName = 0; &&&&& errno = OCIParamGet( this -&m_pOCIStmt, OCI_HTYPE_STMT, this -&m_pOCIError, (dvoid **)&this -&m_pOCIParam, i+ 1 ); &&&&& if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIParamGet"); &&&&& } &&&&& //& Column Name &&&&& errno = OCIAttrGet( (dvoid *)this -&m_pOCIParam, OCI_DTYPE_PARAM, (dvoid **)&sName, (ub4 *)&iLen, OCI_ATTR_NAME, this -&m_pOCIError ); &&&&& if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIAttrGet Column Name"); &&&&& } &&&&& strncpy( this -&m_SelectVars[i].VarName, sName, iLen ); &&&&& this -&m_SelectVars[i].VarName[iLen] = 0; &&&&& //& Data S &&&&& errno = OCIAttrGet( (dvoid *)this -&m_pOCIParam, OCI_DTYPE_PARAM, (dvoid *)&iSize, (ub4 *)0, OCI_ATTR_DATA_SIZE, this -&m_pOCIError ); &&&&& if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIAttrGet Data Size"); &&&&& } &&&&& this -&m_SelectVars[i].VarSize = iS &&&&& //& Data Precision &&&&& errno = OCIAttrGet( (dvoid *)this -&m_pOCIParam, OCI_DTYPE_PARAM, (dvoid *)&iPrecision, (ub4 *)0, OCI_ATTR_PRECISION, this -&m_pOCIError ); &&&&& if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIAttrGet Data Precision"); &&&&& } &&&&& this -&m_SelectVars[i].VarPrecision = iP &&&&& //& Data Scale &&&&& errno = OCIAttrGet( (dvoid *)this -&m_pOCIParam, OCI_DTYPE_PARAM, (dvoid *)&iScale, (ub4 *)0, OCI_ATTR_SCALE, this -&m_pOCIError ); &&&&& if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIAttrGet Data Scale"); &&&&& } &&&&& this -&m_SelectVars[i].VarScale = iS &&&&& //& Data Is Null &&&&& errno = OCIAttrGet( (dvoid *)this -&m_pOCIParam, OCI_DTYPE_PARAM, (dvoid *)&iIsNull, (ub4 *)0, OCI_ATTR_IS_NULL, this -&m_pOCIError ); &&&&& if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIAttrGet Data Is Null"); &&&&& } &&&&& this -&m_SelectVars[i].VarIsNull = iIsN &&&&& //& Data Type &&&&& errno = OCIAttrGet( (dvoid *)this -&m_pOCIParam, OCI_DTYPE_PARAM, (dvoid *)&iType, (ub4 *)0, OCI_ATTR_DATA_TYPE, this -&m_pOCIError ); &&&&& if ( errno ) &&&&& { &&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIAttrGet Data Type"); &&&&& } &&&&& this -&m_SelectVars[i].VarType = iT
  switch ( this -&m_SelectVars[i].VarType ) &&&&& { &&&&& case SQLT_NUM: &&&&&&& if ( this -&m_SelectVars[i].VarScale == 0 ) &&&&&&& { &&&&&&&&& this -&m_SelectVars[i].ValueInt = &&&&&&&&& this -&m_SelectVars[i].VarType = TYPE_INT; &&&&&&&&& errno = OCIDefineByPos( this -&m_pOCIStmt, &this -&m_pOCIDefine, this -&m_pOCIError, i + 1, &&&&&&&&&&&&& (dvoid *)this -&m_SelectVars[i].ValueInt,& sizeof(int), SQLT_INT, this -&indp, (ub2 *)0, (ub2 *)0, OCI_DEFAULT ); &&&&&&&&& if ( errno ) &&&&&&&&& { &&&&&&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIDefineByPos"); &&&&&&&&& } &&&&&&& } &&&&&&& else &&&&&&& { &&&&&&&&& this -&m_SelectVars[i].ValueFloat = &&&&&&&&& this -&m_SelectVars[i].VarType = TYPE_FLOAT; &&&&&&&&& errno = OCIDefineByPos( this -&m_pOCIStmt, &this -&m_pOCIDefine, this -&m_pOCIError, i + 1, &&&&&&&&&&&&& (dvoid *)this -&m_SelectVars[i].ValueFloat,& sizeof(float), SQLT_FLT, this -&indp, (ub2 *)0, (ub2 *)0, OCI_DEFAULT ); &&&&&&&&& if ( errno ) &&&&&&&&& { &&&&&&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIDefineByPos"); &&&&&&&&& } &&&&&&& } &&&&&&& &&&&& case SQLT_CHR: &&&&&&& this -&m_SelectVars[i].ValueChar = new char[this -&m_SelectVars[i].VarSize + 1]; &&&&&&& this -&m_SelectVars[i].VarType = TYPE_STRING; &&&&&&& errno = OCIDefineByPos( this -&m_pOCIStmt, &this -&m_pOCIDefine, this -&m_pOCIError, i + 1, &&&&&&&&&&& (dvoid *)this -&m_SelectVars[i].ValueChar,& this -&m_SelectVars[i].VarSize + 1, SQLT_STR, this -&indp, (ub2 *)0, (ub2 *)0, OCI_DEFAULT ); &&&&&&& if ( errno ) &&&&&&& { &&&&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIDefineByPos"); &&&&&&& } &&&&&&& &&&&& case SQLT_BLOB: &&&&&&& /* Allocate lobLocator */ &&&&&&& errno = OCIDe.orAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_SelectVars[i].lobLocator, (ub4)OCI_DTYPE_LOB, (size_t)0, (dvoid **)0 ); &&&&&&& if ( errno ) &&&&&&& { &&&&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIDe.orAlloc"); &&&&&&& } &&&&&&& this -&m_SelectVars[i].VarType = TYPE_BLOB; &&&&&&& errno = OCIDefineByPos( this -&m_pOCIStmt, &this -&m_pOCIDefine, this -&m_pOCIError, (ub4)i + 1, (dvoid *)&this -&m_SelectVars[i].lobLocator, (sb4)0, &&&&&&&&&&& (ub2)SQLT_BLOB, this -&indp, (ub2 *)0, (ub2 *)0, (ub4)OCI_DEFAULT); &&&&&&& if ( errno ) &&&&&&& { &&&&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIDefineByPos"); &&&&&&& } &&&&&&& &&&&& case SQLT_CLOB: &&&&&&& /* Allocate lobLocator */ &&&&&&& errno = OCIDe.orAlloc( (dvoid *)this -&m_pOCIEnv, (dvoid **)&this -&m_SelectVars[i].lobLocator, (ub4)OCI_DTYPE_LOB, (size_t)0, (dvoid **)0 ); &&&&&&& if ( errno ) &&&&&&& { &&&&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIDe.orAlloc"); &&&&&&& } &&&&&&& this -&m_SelectVars[i].VarType = TYPE_BLOB; &&&&&&& errno = OCIDefineByPos( this -&m_pOCIStmt, &this -&m_pOCIDefine, this -&m_pOCIError, (ub4)i + 1, (dvoid *)&this -&m_SelectVars[i].lobLocator, (sb4)0, &&&&&&&&&&& (ub2)SQLT_BLOB, this -&indp, (ub2 *)0, (ub2 *)0, (ub4)OCI_DEFAULT); &&&&&&& if ( errno ) &&&&&&& { &&&&&&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserSelect OCIDefineByPos"); &&&&&&& } &&&&&&& &&&&& } &&& } &&& return 0; & } & catch ( OCIException &ex ) & { &&& /* Free Stmt */ &&& errno = OCIHandleFree( (dvoid *)this -&m_pOCIStmt, (ub4)OCI_HTYPE_STMT ); &&& if ( errno ) &&& { &&&&& OCIError::PrintError(errno, (char *)"OCIDB::UserExecute Ex OCIHandleFree"); &&& } &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  int OCIDB::UserFetch() { & & try & { &&& errno = OCIStmtFetch( this -&m_pOCIStmt, this -&m_pOCIError, 1, OCI_FETCH_NEXT, OCI_DEFAULT ); &&& if ( errno && errno != OCI_NO_DATA ) &&& { &&&&& throw OCIException(errno, this -&m_pOCIError, (char *)"OCIDB::UserFetch OCIStmtFetch"); &&& } &&& if ( errno == OCI_NO_DATA ) &&&&& return 1; &&& return 0; & } & catch ( OCIException &ex ) & { &&& std::cout && ex.GetErrFunc() && ex.GetErrMsg() && std:: &&& return -1; & } }
  int OCIDB::UserSelectFree() { & & for ( i = 0 ; i & this -&m_iSelectVarsC i++ ) & { &&& switch ( this -&m_SelectVars[i].VarType ) &&& { &&& case TYPE_STRING: &&&&& delete [] this -&m_SelectVars[i].ValueC &&&&& &&& case TYPE_FLOAT: &&&&& delete this -&m_SelectVars[i].ValueF &&&&& &&& case TYPE_INT: &&&&& delete this -&m_SelectVars[i].ValueI &&&&& &&& } & } & return this -&UserFree(); }
  int OCIDB::UserGetInt(int index) { & switch ( this -&m_SelectVars[index].VarType ) & { & case TYPE_FLOAT: &&& return (int)*m_SelectVars[index].ValueF &&& & case TYPE_INT: &&& return *m_SelectVars[index].ValueI &&& & default: &&& return 0; & } }
  int OCIDB::UserGetInt(char * name) { & & for ( i = 0 ; i & this -&m_iSelectVarsC i++ ) & { &&& if ( this -&StrCmp(m_SelectVars[i].VarName, name) ) &&& { &&&&& switch ( this -&m_SelectVars[i].VarType ) &&&&& { &&&&& case TYPE_FLOAT: &&&&&&& return (int)*m_SelectVars[i].ValueF &&&&&&& &&&&& case TYPE_INT: &&&&&&& return *m_SelectVars[i].ValueI &&&&&&& &&&&& default: &&&&&&& return 0; &&&&& } &&& } & } & return 0; }
  float OCIDB::UserGetFloat(int index) { & switch ( this -&m_SelectVars[index].VarType ) & { & case TYPE_FLOAT: &&& return *m_SelectVars[index].ValueF &&& & case TYPE_INT: &&& return (float)*m_SelectVars[index].ValueI &&& & default: &&& return 0; & } }
  float OCIDB::UserGetFloat(char * name) { & & for ( i = 0 ; i & this -&m_iSelectVarsC i++ ) & { &&& if ( this -&StrCmp(m_SelectVars[i].VarName, name) ) &&& { &&&&& switch ( this -&m_SelectVars[i].VarType ) &&&&& { &&&&& case TYPE_FLOAT: &&&&&&& return *m_SelectVars[i].ValueF &&&&&&& &&&&& case TYPE_INT: &&&&&&& return (float)*m_SelectVars[i].ValueI &&&&&&& &&&&& default: &&&&&&& return 0; &&&&& } &&& } & } & return 0; }
  char * OCIDB::UserGetString(int index) { & if ( this -&m_SelectVars[index].VarType == TYPE_STRING ) & { &&& return this -&m_SelectVars[index].ValueC & } & else & { &&& return 0; & } }
  char * OCIDB::UserGetString(char * name) { & & for ( i = 0 ; i & this -&m_iSelectVarsC i++ ) & { &&& if ( this -&StrCmp(m_SelectVars[i].VarName, name) ) &&& { &&&&& if ( this -&m_SelectVars[i].VarType == TYPE_STRING ) &&&&& { &&&&&&& return this -&m_SelectVars[i].ValueC &&&&& } &&& } & } & return 0; }
  char * OCIDB::UserGetBlob(int index) { & if ( this -&m_SelectVars[index].VarType == TYPE_BLOB ) & { &&& return this -&m_SelectVars[index].ValueC & } & else & { &&& return 0; & } }
  char * OCIDB::UserGetBlob(char * name) { & & for ( i = 0 ; i & this -&m_iSelectVarsC i++ ) & { &&& if ( this -&StrCmp(m_SelectVars[i].VarName, name) ) &&& { &&&&& if ( this -&m_SelectVars[i].VarType == TYPE_BLOB ) &&&&& { &&&&&&& return this -&m_SelectVars[i].ValueC &&&&& } &&& } & } & return 0; }
  vector& vector&string& & OCIDB::getResult() { & & vector&string& objectV & StringTools stringT & while ( this -&UserFetch() == 0 ) & { &&& objectValue.clear(); &&& for ( i = 0 ; i & this -&m_iSelectVarsC i++ ) &&& { &&&&& switch ( this -&m_SelectVars[i].VarType ) &&&&& { &&&&& case TYPE_STRING: &&&&&&& objectValue.push_back(this -&UserGetString(i)); &&&&&&& &&&&& case TYPE_FLOAT: &&&&&&& objectValue.push_back(stringTools.ToString(this -&UserGetFloat(i))); &&&&&&& &&&&& case TYPE_INT: &&&&&&& objectValue.push_back(stringTools.ToString(this -&UserGetInt(i))); &&&&&&& &&&&& case TYPE_BLOB: &&&&&&& &&&&& } &&& } &&& resultList.push_back(objectValue); & }
  return resultL }
  void inline OCIDB::StrUpper(char * str) { & & int sLen = strlen(str); & for ( i = 0 ; i & sL i++ ) & { &&& str[i] = toupper(str[i]); & } }
  bool inline OCIDB::StrCmp(const char * ori, const char * des) { & int iLenOri, iLenD &
  iLenOri = strlen(ori); & iLenDes = strlen(des);
  if ( iLenOri != iLenDes ) &&&
  for ( j = 0 ; j & iLenO j++ ) & { &&& if ( toupper(ori[j]) != toupper(des[j]) ) &&& { &&&&& &&& } & } & }
  五、修改建议
  本套代码只是处理了LOB类型的绑定,没有处理LOB类型数据的读取。本人在以后的完善中,打算把runSQLCommand(char * sql)函数分解成两个或者三个函数,分别执行select和insert等语句。
  在程序中,我并没有强制要求参数必须为const,可能会出现一些安全问题。本文仅起抛砖引玉的作用,希望有高手可以指点我程序中的问题。
H3C认证Java认证Oracle认证
基础英语软考英语项目管理英语职场英语
.NETPowerBuilderWeb开发游戏开发Perl
二级模拟试题一级模拟试题一级考试经验四级考试资料
软件测试软件外包系统分析与建模敏捷开发
法律法规历年试题软考英语网络管理员系统架构设计师信息系统监理师
高级通信工程师考试大纲设备环境综合能力
路由技术网络存储无线网络网络设备
CPMP考试prince2认证项目范围管理项目配置管理项目管理案例项目经理项目干系人管理
职称考试题目
招生信息考研政治
网络安全安全设置工具使用手机安全
生物识别传感器物联网传输层物联网前沿技术物联网案例分析
Java核心技术J2ME教程
Linux系统管理Linux编程Linux安全AIX教程
Windows系统管理Windows教程Windows网络管理Windows故障
数据库开发Sybase数据库Informix数据库
&&&&&&&&&&&&&&&
希赛网 版权所有 & &&}

我要回帖

更多关于 exec.commandcontext 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信