vc++数据库操作的学习笔记
来源:互联网 发布:首付不够怎么买房知乎 编辑:程序博客网 时间:2024/06/15 12:26
使用powerbuilder,访问数据非常的方便,然后在C++里面要操作数据库就变繁琐了。今天就想把C++中的数据库操作弄的方便点的。希望能和pb的访问方式一样的简单,stirng ls_persionint li_id;string ls_name;select id ,name into :li_id,:ls_name from dict where userid = :li_persion;if(sqlca.sqlcode <>0){}因为C++要使用直接在sql语句中操作变量,只有支持预编绎的嵌入式C才可以,这种方法编码和调试都不方便,除了sqlserver oracle 提供了这样的支持,其它的数据库访问都不是我想要的方式。好好想了想,powerbuild是C语言开发的,oracle也是C语言开发的,为什么不自己实现呢。c++的好处就是功能强大,限制少。只有想不到,没有做不到。主要方法就是参考printf()的写法,活用va_list,va_arg这些宏,就可以方便的实现我的想法 了。定义数据库操作类:interface ITransaction {virtual connect() = 0 virtaul disconnect() = 0 ; }class ISQLite :public ITransaction {}class DataBase:publi ISQLite,public:ISQLServer,:publica :IOracle{}extern DataBase sqlca;class DwObject{属性:item opertion =(int i) //重载各种数据类型{}opettio int() {}}class DataStore {属生: DwObject objectint opertion [](int icol) {return (int)object.item[1] ; //根据列,返回int类型} int SetTransObject(DataBase* db ) ; //int setsqlselect(char* sql ) ; int retrieve(void start,....) ; 属性:dataobject = "dw_1" //窗口控件布局定义在xml中,也可以是sqlite3数据中的blob字段属性 selectString ; 属性 updateString ; 属性 KeyField }class DataWindow {}定义函数int select(LPCSTR sql,...) ;int select(database db ,LPCSTR sql,...) ; int select(database db ,LPCSTR sql,...,valist& list) ; int Connect(Dabase* db=0) ;int DisConnect(Dabase* db=0) ;要实现的访问方式int main(){ //根据DBMS判断 使用哪个接口isqlintreface//SQLCA.DBMS = "OLE DB"//sqlca.DBMS = "OLE DB"sqlca.DBMS = "SQLITE3"sqlca.DBMS = "ORACLE"sqlca.DBMS = "SQLSERVER" sqlca.LogPass = <********>sqlca.LogId = "sa"sqlca.AutoCommit = Falsesqlca.DBParm = "PROVIDER='SQLOLEDB',DATASOURCE='127.0.0.1',PROVIDERSTRING='database='master''"Connect(); if(sqlca.sqlcode !=0){}//检索数据,直接返回到变量中Select( "select id,nam from dict where id = 100",&id,&name) ; if(sqlca.sqlcode !=0){}//使用指定的连接 类似 pb中的using sqlca;功能DataBase* db = new Database() ; Select(db, "select id,nam from dict where id = 100",&id,&name) ; if(db->sqlcode !=0){}DataStore ds ; ds.dataobject = "dw_2"ds.settransobject(sqlca); ds.setselect("select * From user where id =:%d,id) ;ds.retrieve(&id,0) ;//直接返回变量中 ds.getitemstring(1,1) //列序号ds.getitemnumber(1,"id") //序名访问id = ds.item[1]id = ds.item["id"]Disconnect() ; return ; }先这里记录一下思绪。
阅读全文
0 0
- vc++数据库操作的学习笔记
- vc中的CString的操作-学习笔记
- 【VC++ 中使用ADO操作数据库学习笔记】 基础环境的设置
- 【VC++ 中使用ADO操作数据库学习笔记】_ConnectionPtr指针的基本用法
- VC学习笔记2文档视图操作
- VC学习笔记7文件操作
- VC学习笔记8INI文件操作
- VC操作Excel(学习笔记)
- unity3d数据库操作学习笔记
- C#操作数据库 学习笔记
- hibernate 学习笔记-操作数据库
- Python学习笔记-数据库操作
- VC++数据库学习笔记:ADO:: Connection 对象
- 数据库的操作笔记
- Python的学习笔记(四)(MySQL数据库的操作)
- php学习笔记(十七)简单的数据库操作链接
- ThinkPHP学习笔记(十八)数据库表的关联操作
- MySQL学习笔记2:数据库的基本操作
- android studio Error occurred during initialization of VM Could not reserve enough space
- 各类排序算法
- Java保留小数位的4种方法
- java反射基础
- 洛谷p1108低价购买
- vc++数据库操作的学习笔记
- 剑指offer(19)—顺时针打印矩阵
- Linux启动关闭图形界面
- POJ 3261 Milk Patterns (后缀树组)
- Visual Studio 2012
- 类-成员变量和局部变量
- python+selenium自动化软件测试(第9章) :Logging模块
- apache 2.4 访问权限配置
- bzoj4818 [Sdoi2017]序列计数