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

            Khan's Notebook GCC/GNU/Linux Delphi/Window Java/Anywhere

            路漫漫,長修遠(yuǎn),我們不能沒有錢
            隨筆 - 173, 文章 - 0, 評論 - 257, 引用 - 0
            數(shù)據(jù)加載中……

            OCI for Windows 環(huán)境手工配置

            本來公司的項目是在linux下處理的. 由于近期人員調(diào)動. 需要增加幾個新人. 為了讓不熟悉linux開發(fā)環(huán)境的新人能夠盡快上手使用公司的基礎(chǔ)類庫, 所以我承擔(dān)了搭建windows下的開發(fā)環(huán)境搭建工作

            其中第一項就是將公司使用的基于oci的封裝ocicpp編譯出一個mingw32的版本

            1. 必要工具

            Instant Client Downloads for Microsoft Windows

            http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html
            oracle instant Client

            mingw32

            自行搜索下載地址, 本人使用3.42
            gcc的win32版本

            pexports for mingw32

            自行搜索下載地址
            將c的dll導(dǎo)出為def的工具, 如果你的mingw沒有自帶. 請自行下載. 并放到path可以找到的地方, 不支持c++的dll.

            以上工具自行安裝
            instantclient解壓到D:\Develop\Cplus\instantclient_11_1\
            mingw32安裝到D:\Develop\Cplus\MinGW\
            pexports.exe解壓到D:\Develop\Cplus\MinGW\bin\


            2. 生成能被mingw32調(diào)用的oci lib
            由于oracle 官方的oci sdk并無提供可供mingw link的包. 所以我們需要手工根據(jù)dll做一個

            使用dll產(chǎn)生mingw32的lib
            導(dǎo)出def
            D:\Develop\Cplus\instantclient_11_1\sdk\lib>pexports oci.dll > oci.def

            生成lib
            D:\Develop\Cplus\instantclient_11_1\sdk\lib>dlltool --dllname oci.dll --def oci.def --output-lib liboci.a

            這樣我們就有了一個可以mingw32 link的 liboci.a了


            3.配置oracle instant Client
            只需要3個環(huán)境變量
            TNS_ADMIN=D:\Develop\Cplus\instantclient_11_1
            NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
            PATH=%PATH%;%TNS_ADMIN%\


            4.編譯執(zhí)行測試程序.
            保密協(xié)議導(dǎo)致我無法公開ocicpp的源碼.
            但是可以貼基于ocicpp的測試程序

            #include <unistd.h>
            #include <stdio.h>
            #include <stdlib.h>
            #include <iostream>
            #include "ocicpp/ocicpp.h"
            #include "ocicpp/db.h"

            using    namespace    OCICPP;


            bool InsertDataBySQL(Connection* pConn)
            {
                Cursor    cursor;
                string strSQL;

                strSQL = "INSERT INTO testOCICPP (TestId, UserName, PassWord, Address ) VALUES(13, 'xxxxx', '!@#$1234', 'xxxxx')";

                try {
                    pConn->execQuery(strSQL, cursor);
                    cursor.drop();
                    pConn->transCommit();
                }
                catch (OraError err) {
                    cout << "InsertDataBySQL Exception: " <<  err.message << endl;
                    return false;
                }
                return true;
            }

            bool UpdateDataBySQL(Connection* pConn)
            {
                Cursor    cursor;
                string strSQL;

                strSQL = "UPDATE testOCICPP SET PassWord = '&*()7890'";

                try {
                    pConn->execQuery(strSQL, cursor);
                    cursor.drop();
                    pConn->transCommit();
                }
                catch (OraError err) {
                    cout << "UpdateDataBySQL Exception: " <<  err.message << endl;
                    return false;
                }
                return true;
            }

            bool DelRecordBySQL(Connection* pConn)
            {
                Cursor    cursor;
                string strSQL;

                strSQL = "DELETE FROM testOCICPP";

                try {
                    pConn->execQuery(strSQL, cursor);
                    cursor.drop();
                    pConn->transCommit();
                }
                catch (OraError err) {
                    cout << "DelRecordBySQL Exception: " <<  err.message << endl;
                    return false;
                }
                return true;
            }
            bool FetchDataBySQL(Connection* pConn)
            {
                Cursor    cursor;
                string strSQL;

                strSQL = "SELECT MEMBERID,MOBILE,PASSWD,ADDRESS FROM tblmember where rownum<20";

                try {
                    pConn->execQuery(strSQL, cursor);
                    while (cursor.fetch())        {
                        cout << ".......... Record .........." << endl;
                        cout << "TestId: " << cursor.getInt("MEMBERID") << endl;
                        cout << "UserName: " << cursor.getStr("MOBILE") << endl;
                        cout << "PassWord: " << cursor.getStr("PASSWD") << endl;
                        cout << "Address: " << cursor.getStr("ADDRESS") << endl;
                    }
                    cursor.drop();
                    pConn->transCommit();
                }
                catch (OraError err) {
                    cout << "FetchDataBySQL Exception: " <<  err.message << endl;
                    return false;
                }
                return true;
            }

            bool InsertDataByProcedure(Connection* pConn)
            {
                Cursor    cursor;
                string strSQL;
                int iRetCode=0;
                strSQL = "BEGIN testProcInsert(13, 'xxxxx', '!@#$1234', 'xxxxx', :RetCode); END;";

                try {
                    pConn->prepare(strSQL, cursor);
                    cursor.bind(":RetCode", iRetCode);
                    cursor.execute();        cursor.drop();
                }
                catch (OraError err) {
                    cout << "InsertDataBySQL Exception: " <<  err.message << endl;
                    return false;
                }
                cout << "InsertDataByProcedure RetCode: " << iRetCode << endl;

                return true;
            }

            bool UpdateDataByProcedure(Connection* pConn)
            {

                return false;
            }

            bool DelRecordByProcedure(Connection* pConn)
            {
                return false;
            }


            bool FetchDataByProcedure(Connection* pConn)
            {

                return false;
            }

            int StartRun(int p_iMode)
            {
                Connection    dbConn;

                OCICPP::db::init();

                try{
                    OCICPP::db::connect("smsdb", "point", "point1234", dbConn);

                    switch(p_iMode)
                    {
                    case 1:
                        InsertDataBySQL(&dbConn);
                        break;
                    case 2:
                        UpdateDataBySQL(&dbConn);
                        break;
                    case 3:
                        DelRecordBySQL(&dbConn);
                        break;
                    case 4:
                        FetchDataBySQL(&dbConn);
                        break;
                    case 5:
                        InsertDataByProcedure(&dbConn);
                        break;
                    case 6:
                        UpdateDataByProcedure(&dbConn);
                        break;
                    case 7:
                        DelRecordByProcedure(&dbConn);
                        break;
                    case 8:
                        FetchDataByProcedure(&dbConn);
                        break;
                    default:
                        break;
                    }
                } catch(OraError err) {
                    cout << "OraError Exception: " << err.message << endl;
                }
                return 0;
            }

            int main(int argc, char* argv[])
            {
                if (argc != 2)
                {
                    cout << endl;
                    cout << "Please input run mode (1 - 6): " << endl;
                    cout << endl;
                    cout << "    1:  InsertDataBySQL" << endl;
                    cout << "    2:  UpdateDataBySQL" << endl;
                    cout << "    3:  DelRecordBySQL" << endl;
                    cout << "    4:  FetchDataBySQL" << endl;
                    cout << "    5:  InsertDataByProcedure" << endl;
                    cout << "    6:  UpdateDataByProcedure" << endl;
                    cout << "    7:  DelRecordByProcedure" << endl;
                    cout << "    8:  FetchDataByProcedure" << endl;
                    cout << endl;
                    exit(-1);
                }
                int iMode = atoi(argv[1]);

                //pid_t iPid;
               
                //iPid = fork();
               
                //if (iPid == 0)
                //{
                    StartRun(iMode);
                    exit(0);
                //}
                //else if (iPid < 0)
                //{
                //    cout << "Fork Failure" << endl;
                //}
                //sleep(3);
                cout << "................. Finish ................." << endl;
                return 0;
            }


            /*****************************************************************
            CREATE TABLE testOCICPP
            (
                TestId            number(10, 0)    DEFAULT 1 NOT NULL,
                UserName        varchar2(16)    DEFAULT ' ' NOT NULL,
                PassWord        varchar2(16)    DEFAULT ' ' NOT NULL,
                Address            varchar2(128)    DEFAULT ' ' NOT NULL
            )tablespace rism_db;


            CREATE OR REPLACE PROCEDURE testProcInsert(
                p_iTestId IN number, p_sUserName IN string, p_sPassWord IN string,
                p_sAddress IN string, p_iRetCode OUT number)
            IS
            BEGIN
                p_iRetCode := 0;
                INSERT INTO testOCICPP(TestId, UserName, PassWord, Address)
                    VALUES(p_iTestId, p_sUserName, p_sPassWord, p_sAddress);
                COMMIT;

                EXCEPTION
                    WHEN OTHERS THEN
                        p_iRetCode := SQLCODE;
            END;
            /



            *****************************************************************/


            編譯成ocicpp.exe

            此時需要兩個dll文件與ocicpp.exe在同一個目錄
            在oracle instant Client安裝目錄下找到oraociei11.dll oci.dll
            根據(jù)版本不同. oraociei11.dll這個文件名或許會有差異.
            也可以將倆dll扔到system32目錄下


            本人服務(wù)器端為rhel 3.4 ,數(shù)據(jù)庫環(huán)境為9.2.04
            客戶端環(huán)境為windows mingw32-gcc3.42

            posted on 2010-03-23 17:30 Khan 閱讀(4456) 評論(2)  編輯 收藏 引用 所屬分類: GCC/G++跨平臺開發(fā)

            評論

            # re: OCI for Windows 環(huán)境手工配置  回復(fù)  更多評論   

            純粹路過..還在寫這個啊.
            2010-04-27 02:00 | greathjw

            # re: OCI for Windows 環(huán)境手工配置  回復(fù)  更多評論   

            @greathjw

            什么都得玩一玩...
            2010-06-02 10:30 | Khan.Lau
            97精品依人久久久大香线蕉97| 国产高潮国产高潮久久久| 久久99亚洲网美利坚合众国| 四虎久久影院| 亚洲Av无码国产情品久久| 91精品日韩人妻无码久久不卡| 久久99精品国产麻豆| 久久人人爽人人爽人人片av高请 | 97超级碰碰碰久久久久| 伊人久久大香线蕉av不变影院| 中文无码久久精品| 新狼窝色AV性久久久久久| 久久亚洲春色中文字幕久久久| 久久亚洲私人国产精品| 国产Av激情久久无码天堂| 日本三级久久网| 亚洲国产成人久久精品99| 久久精品桃花综合| 欧洲精品久久久av无码电影| 996久久国产精品线观看| 国产精品欧美亚洲韩国日本久久 | 国内精品久久久久久久影视麻豆 | 久久久久久国产精品美女| 欧美精品乱码99久久蜜桃| 久久青青草原亚洲av无码app| 无码精品久久久天天影视| 久久香蕉国产线看观看精品yw| 99久久国语露脸精品国产| 精品国产福利久久久| 99国内精品久久久久久久| 国内精品久久久久久久coent| 久久噜噜久久久精品66| 久久中文字幕人妻熟av女| 亚洲国产另类久久久精品黑人 | 99久久精品费精品国产| 精品久久久久久无码人妻蜜桃 | 久久精品亚洲乱码伦伦中文| 久久人人爽人人爽人人片av麻烦| 久久久无码精品亚洲日韩按摩 | 国产精品久久免费| 久久免费大片|