• <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

            統(tǒng)計(jì)

            留言簿(1)

            積分與排名

            Linux好站點(diǎn)

            Oracle

            閱讀排行榜

            評(píng)論排行榜

            C++類庫(kù):OTL通用的數(shù)據(jù)庫(kù)連接類庫(kù)

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

            下載網(wǎng)址:http://otl.sourceforge.net/

            OTL使用簡(jiǎn)單, 只要頭文件中包含有: #include "otlv4.h" 就可,實(shí)際上整個(gè)OTL就一個(gè).H的文件,使用起來(lái)極為的方便。

            OTL使用方法:

            1、首先指定要連接的數(shù)據(jù)庫(kù)類型,OTL用宏定義來(lái)指定要連接的數(shù)據(jù)庫(kù)類型。OTL會(huì)根據(jù)這個(gè)宏定義來(lái)初始化數(shù)據(jù)庫(kù)連接的環(huán)境。

            相關(guān)的宏定義列表 http://otl.sourceforge.net/otl3_compile.htm

            如: #define OTL_ORA8I 表示連接Oracle 8i 數(shù)據(jù)庫(kù)。

             

            2、例子

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

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

            otl_connect db; // 定義數(shù)據(jù)庫(kù)實(shí)例

             

            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環(huán)境
             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(); //斷開(kāi)數(shù)據(jù)庫(kù)連接

             return 0;

            }

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

            評(píng)論

            # re: C++類庫(kù):OTL通用的數(shù)據(jù)庫(kù)連接類庫(kù) 2016-02-26 18:29 aaa

            asasasas  回復(fù)  更多評(píng)論   

            久久精品国产影库免费看 | 国内精品久久久久久野外| 亚洲国产成人精品女人久久久 | 亚洲AⅤ优女AV综合久久久| 九九精品99久久久香蕉| 久久久久久久女国产乱让韩| 日批日出水久久亚洲精品tv| 麻豆av久久av盛宴av| 99久久国产综合精品女同图片| 久久青青草原精品国产| 色婷婷综合久久久中文字幕| 亚洲中文字幕无码久久综合网| 国内精品久久久人妻中文字幕| 久久99国产精品久久99| 精品多毛少妇人妻AV免费久久| 久久久久国产一区二区三区| 热久久最新网站获取| 国内精品人妻无码久久久影院导航 | 欧美久久综合性欧美| 久久精品国产72国产精福利| 久久精品青青草原伊人| 久久久久女人精品毛片| 精品国产乱码久久久久久浪潮| 一本久道久久综合狠狠爱| 97精品伊人久久大香线蕉app| 久久国产精品免费一区| 久久亚洲AV无码精品色午夜| 精品久久人妻av中文字幕| 久久91这里精品国产2020| 久久综合一区二区无码| 69久久精品无码一区二区| 久久91这里精品国产2020| 亚洲AV日韩精品久久久久久| 激情综合色综合久久综合| 午夜精品久久久久久久久| 国产精品va久久久久久久| 日产精品久久久久久久| 亚洲国产精品婷婷久久| 久久午夜福利无码1000合集| 国产成人久久777777| 国产精品9999久久久久|