• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            舞影凌亂

            專注C/C++,Linux

            統計

            留言簿(1)

            積分與排名

            Linux好站點

            Oracle

            閱讀排行榜

            評論排行榜

            C++類庫:OTL通用的數據庫連接類庫

            OTL是一個純C++的通用數據庫連接模板庫,可以支持各種當下流行的數據庫,如Oracle,Sybase, MySQL, PostgreSQL, EnterpriseDB, SQLite,  MS ACCESS, Firebird等等.它是一個跨平臺類庫,在MS Windows, Linux/Unix/Mac OS X 都可以使用。

            下載網址:http://otl.sourceforge.net/

            OTL使用簡單, 只要頭文件中包含有: #include "otlv4.h" 就可,實際上整個OTL就一個.H的文件,使用起來極為的方便。

            OTL使用方法:

            1、首先指定要連接的數據庫類型,OTL用宏定義來指定要連接的數據庫類型。OTL會根據這個宏定義來初始化數據庫連接的環境。

            相關的宏定義列表 http://otl.sourceforge.net/otl3_compile.htm

            如: #define OTL_ORA8I 表示連接Oracle 8i 數據庫。

             

            2、例子

            #include <iostream>
            using namespace std;
            #include <stdio.h>

            #define OTL_ORA8I // 指定連接的數據庫類型
            #include <otlv4.h> // include the OTL 4 header file

            otl_connect db; // 定義數據庫實例

             

            void insert()
            // 添加記錄

            {
             otl_stream o(50, // buffer size
                          "insert into test_tab values(:f1<float>,:f2<char[31]>)",
                             // SQL statement
                          db // connect object
                         );
             char tmp[32];

             for(int i=1;i<=100;++i){
            #if defined(_MSC_VER)
            #if (_MSC_VER >= 1400) // VC++ 8.0 or higher
              sprintf_s(tmp,sizeof(tmp),"Name%d",i);
            #else
              sprintf(tmp,"Name%d",i);
            #endif
            #else
              sprintf(tmp,"Name%d",i);
            #endif
              o<<static_cast<float>(i)<<tmp;
             }
            }

            //查詢記錄

            void select()
            {
             otl_stream i(50, // buffer size
                          "begin "
                           open :cur1 for "
                            select * from test_tab "
                            where f1>=:f<int> and f1<=:f*2; "
                          "end;", // SELECT statement via referenced cursor
                          db, // connect object
                          ":cur1" // referenced cursor placeholder name
                         );
               // create select stream
             
             otl_column_desc* desc;
             int desc_len;

             i<<4; // Before the child SELECT statement can be described,
                   // the PL/SQL master block needs to be executed.
                   // Forcing the execution of the blcok by entering its input
                   // patameter.

             desc=i.describe_select(desc_len);

             for(int n=0;n<desc_len;++n){
              cout<<"========== COLUMN #"<<n+1<<" ==========="<<endl;
              cout<<"name="<<desc[n].name<<endl;
              cout<<"dbtype="<<desc[n].dbtype<<endl;
              cout<<"otl_var_dbtype="<<desc[n].otl_var_dbtype<<endl;
              cout<<"dbsize="<<desc[n].dbsize<<endl;
              cout<<"scale="<<desc[n].scale<<endl;
              cout<<"prec="<<desc[n].prec<<endl;
              cout<<"nullok="<<desc[n].nullok<<endl;
             }
             

            }

            int main()
            {
             otl_connect::otl_initialize(); // 初始化Oracle環境
             try{

              db.rlogon("scott/tiger"); // 連接Oracle

              otl_cursor::direct_exec
               (
                db,
                "drop table test_tab",
                otl_exception::disabled // disable OTL exceptions
               ); // drop table

              otl_cursor::direct_exec
               (
                db,
                "create table test_tab(f1 number, f2 varchar2(30))"
                );  // create table

              insert(); 
              select();

             }

             catch(otl_exception& p){ // intercept OTL exceptions
              cerr<<p.msg<<endl; // print out error message
              cerr<<p.stm_text<<endl; // print out SQL that caused the error
              cerr<<p.var_info<<endl; // print out the variable that caused the error
             }

             db.logoff(); //斷開數據庫連接

             return 0;

            }

            posted on 2010-06-02 00:05 幽夢新影 閱讀(6357) 評論(1)  編輯 收藏 引用 所屬分類: C/C++基礎知識

            評論

            # re: C++類庫:OTL通用的數據庫連接類庫 2016-02-26 18:29 aaa

            asasasas  回復  更多評論   

            精品人妻伦一二三区久久| 久久久久黑人强伦姧人妻| 超级97碰碰碰碰久久久久最新| 久久受www免费人成_看片中文| 婷婷五月深深久久精品| 久久精品人人做人人爽电影| 亚洲Av无码国产情品久久| 精品久久久久香蕉网| 久久乐国产精品亚洲综合| 亚洲AV无码一区东京热久久| 国产精品无码久久综合网| 久久精品国产亚洲av麻豆图片 | 九九精品久久久久久噜噜| 无码人妻久久一区二区三区| 国产一久久香蕉国产线看观看| 日本精品久久久久影院日本| 精品久久久久久亚洲精品| 人人狠狠综合久久亚洲高清| 久久99毛片免费观看不卡| 精产国品久久一二三产区区别| 久久成人国产精品二三区| 色综合久久久久综合体桃花网| 久久精品国产一区二区| 国产日产久久高清欧美一区| 久久亚洲精品成人无码网站| 国产成人精品久久| 久久综合欧美成人| 久久久久综合网久久| 久久精品国产亚洲AV嫖农村妇女| 99久久久久| 久久精品国产亚洲av日韩| 日本亚洲色大成网站WWW久久| 亚洲国产精品无码久久久秋霞2| 国内高清久久久久久| 成人免费网站久久久| 无码精品久久久天天影视| 久久97久久97精品免视看秋霞| 久久久久久久久久久久中文字幕 | 99久久精品国产一区二区| 2021久久国自产拍精品| 久久国产精品99久久久久久老狼|