• <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>
            posts - 45,  comments - 232,  trackbacks - 0

            工程下載: http://www.shnenglu.com/Files/dyj057/AdoDbv1.0-2007-1-25.rar

            前幾日看到有位大哥發(fā)布的 ADO 數(shù)據(jù)庫(kù)的封裝,到處是模板,不免有些頭暈,想起自己寫的 ADO 數(shù)據(jù)庫(kù)封裝了,首先聲明沒有模板。但根據(jù)我 3 年使用的經(jīng)驗(yàn),確實(shí)很實(shí)用,

            特點(diǎn):

            l???????? 多線程安全的。

            l???????? 使用標(biāo)準(zhǔn) C++ 數(shù)據(jù)類型,屏蔽了 com 數(shù)據(jù)類型和異常,減少了復(fù)雜性。

            l???????? 操作簡(jiǎn)單,直觀

            1 .下面是使用它進(jìn)行存儲(chǔ)過程的例子代碼:

            異常的處理請(qǐng)參看: http://www.shnenglu.com/dyj057/archive/2007/01/24/17944.html

            #include "AdoConn.h"

            #include "AdoStoredProc.h"

            #include "comm_exception.h"

            using namespace C2217::StdLib;

            using namespace C2217::Data;

            void main()

            {

            ?????? try

            ?????? {

            ????????????? CAdoConn _conn("Provider=SQLOLEDB;Data Source=192.9.207.214;Initial Catalog=ibmsweb;User ID=sa; Password=sa;");

            ????????????? _conn.Open();

            ????????????? CAdoStoredProc sp(_conn,"Accounts_Roles_Create");

            ?

            ????????????? CAdoStringPara para("Description", "Para9", 50);

            ????????????? sp.AddPara(&para);

            ?

            ????????????? int count =0? ;//sp.ExecuteNonQuery();

            ????????????? cout << " affected cout " << count <<endl;

            ??????

            ????????????? CAdoStringPara *pStringPara = dynamic_cast<CAdoStringPara *>(sp["Description"]);

            ????????????? if(pStringPara)

            ????????????? {

            ???????????????????? cout << pStringPara->getValue() <<endl;

            ????????????? }

            ?

            ????????????? sp.ClearParameters();

            ?

            ????????????? //Read to dataset

            ????????????? CAdoRecordSet readResult;

            ????????????? sp.setSpName("Accounts_Users_Select_All");

            ????????????? cout << "Read affected item cout : " << sp.Execute(readResult);

            ?

            ????????????? //cout << "Read Count :" << readResult.getRecordCount() <<endl;

            ?????? }

            ?????? catch(comm_exception &e)

            ?????? {

            ????????????? SET_CATCH_POS(e);

            ????????????? std::cout << e;

            ?????? }

            ?????? catch(const exception &e)

            ?????? {

            ????????????? cout << e.what();

            ?????? }

            }

            2 .讀取數(shù)據(jù)的例子:

            const CAdoConn &? _conn? =S_DeviceDb::instance()->GetAdoConn();

            ?????? CString sql;

            ?????? sql.Format("select * from %s where tag_name = '%s' ",

            ????????????? m_tableName, GetName() );

            ?????? CAdoRecordSet result;

            ?????? int count = _conn.Execute(sql, result);

            ?????? if(count ==1)

            ?????? {

            ????????????? result.MoveFirst();

            ????????????? SetDescription( result.readStr("description").c_str());

            ????????????? SetUnits( result.readStr("uints").c_str());

            ????????????? SetType( result.readStr("data_type").c_str());

            ????????????? SetWritebale( result.readInt("writeable"));

            ????????????? SetExpress( result.readStr("cacu_express").c_str() );

            ????????????? SetDeviceAddress( result.readInt("device_address"));

            ????????????? SetRegisterAddress( result.readInt("register_address"));

            ????????????? SetDataLen( result.readInt("data_length"));

            ????????????? SetBitsStartIndex( result.readInt("start_bit_index"));

            ????????????? SetBitsCount( result.readInt("bit_count"));

            ?????? }

            3 .刪除數(shù)據(jù)的例子:

            const CAdoConn &? _conn? =S_DeviceDb::instance()->GetAdoConn();

            ?????? CString sql;

            ?????? sql.Format("delete from %s where tag_name = '%s'", m_tableName, GetName() );

            ?????? _conn.ExecuteNonQuery( sql);

            4 .更新數(shù)據(jù)的例子:

            const CAdoConn & ?_conn? =S_DeviceDb::instance()->GetAdoConn();

            ?????? CString sql;

            ?????? sql.Format("update %s set description='%s',? uints='%s', data_type='%s',\

            ???????????????????? ?? writeable=%d, cacu_express='%s', device_address=%d, register_address=%d, data_length =%d,\

            ???????????????????? ?? start_bit_index = %d, bit_count = %d where tag_name = '%s' ", m_tableName, GetDescription(), GetUnits(), GetType(),

            ???????????????????? ?? IsWriteable(), GetExpress(), GetDeviceAddress(), GetRegisterAddress(), GetDataLen(), GetBitsStartIndex(), GetBitsCount(), GetName() );

            ??????

            ?????? VERIFY(_conn.ExecuteNonQuery(sql));

            posted on 2007-01-26 09:53 天下無(wú)雙 閱讀(2041) 評(píng)論(2)  編輯 收藏 引用 所屬分類: C/C++

            FeedBack:
            # re: ADO數(shù)據(jù)庫(kù)操作的C++封裝
            2007-01-31 15:07 | eXile
            前幾日看到有位大哥發(fā)布的 ADO 數(shù)據(jù)庫(kù)的封裝,到處是模板,不免有些頭暈....

            呵呵,是說(shuō)的我嗎?關(guān)于模板,我的看法是,在做庫(kù)的封裝時(shí),可以無(wú)所顧忌地使用,以作最大優(yōu)化,在做業(yè)務(wù)邏輯時(shí),盡量不要使用,以便于維護(hù)。

            我做的封裝,如下所示,表中有哪些字段,什么類型,一目了然,在此引入模板我覺得是必要的。
            struct TUser
            {
            AdoCol<int> m_id;
            AdoCol<std::string> m_name;
            AdoCol<int> m_type;
            AdoCol<AdoBLOB> m_blob;
            };


              回復(fù)  更多評(píng)論
              
            # re: ADO數(shù)據(jù)庫(kù)操作的C++封裝
            2007-01-31 15:19 | 天下無(wú)雙
            我明白你的意思,如果程序員對(duì)模板不是很熟悉,如像這樣的代碼:
            template <class RowT>
            void Bind(RowT& r)
            {
            MY_STATIC_ASSERT(field_count == RowT::size);

            r.BindField(fid, "id", &m_id);
            r.BindField(fname, "name", &m_name);
            r.BindField(ftype, "type", &m_type);
            }
            要上手還是要一段時(shí)間 。  回復(fù)  更多評(píng)論
              

            常用鏈接

            留言簿(15)

            隨筆分類

            隨筆檔案

            相冊(cè)

            我的其它領(lǐng)域Blog

            搜索

            •  

            積分與排名

            • 積分 - 207229
            • 排名 - 130

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久精品国产91久久综合麻豆自制| 亚洲综合婷婷久久| 久久久久久国产精品免费免费| 国产美女久久精品香蕉69| 国产精品亚洲综合专区片高清久久久| 久久精品视频91| 亚洲精品高清国产一线久久| 国产精品99久久久久久董美香 | 2020最新久久久视精品爱| 久久久青草青青国产亚洲免观| 国产精品久久久久久吹潮| 欧美日韩精品久久久久| 99久久99久久精品国产片果冻| 久久99热这里只有精品66| 热久久国产精品| 国产精品99久久久久久人| 狠狠色婷婷久久综合频道日韩| 久久精品二区| 丁香五月网久久综合| 亚洲国产精品久久久天堂| 久久九九免费高清视频 | 久久国产成人午夜aⅴ影院| 99麻豆久久久国产精品免费| 中文字幕无码久久人妻| 99久久精品免费看国产一区二区三区| 99久久国产亚洲高清观看2024 | 久久综合狠狠综合久久综合88| 思思久久99热只有频精品66| 久久久精品无码专区不卡| 精品久久久久久国产牛牛app| 亚洲精品国产成人99久久| 国产精品久久久亚洲| 久久精品国产99国产精品澳门| 久久精品毛片免费观看| 99久久超碰中文字幕伊人| 丰满少妇人妻久久久久久| 久久66热人妻偷产精品9| 国内精品久久久久久野外| 秋霞久久国产精品电影院| 久久青青草原亚洲av无码| 性做久久久久久久久浪潮|