当前位置:网站首页>Qt编译数据库插件通用步骤说明
Qt编译数据库插件通用步骤说明
2022-06-25 03:44:00 【feiyangqingyun】
近期特意花了点时间,在之前数据库集成应用这个组件的基础上再次迭代完善,历经九九八十一难,将Qt的各种数据库插件,十几个Qt版本,全部编译一遍,同时打通了插件形式直连数据库和ODBC数据源连接方式,做过各种对比测试,不同数据库不同分页算法,不同日期时间范围判断查询等。
安装对应的数据库,安装后会有include头文件和lib链接库文件,这是基本的前提,编译数据库插件必须要有这两个东西。务必注意,32位的Qt必须安装32位的数据库才能正常编译成功,位数要一致。
准备好数据库插件源码,比如qt-everywhere-src-5.14.2\qtbase\src\plugins\sqldrivers\mysql,可以在安装Qt的时候勾选src,或者后期直接官网重新下载源码解压出来。
打开你要编译的数据库插件源码,比如mysql就打开mysql.pro,oracle就打开oci.pro。
在pro中注释掉一行 #QMAKE_USE += mysql,如果是oci项目则是#QMAKE_USE += oci。
qsqldriverbase.pri文件中注释掉 #include($$shadowed($$PWD)/qtsqldrivers-config.pri)。
mysql.pro文件内容下面加上如下代码。
path = C:/Qt/mysql-5.7.30-winx64
INCLUDEPATH += $$path/include
win32:LIBS += -L$$path/lib -llibmysql
- oci.pro文件内容下面加上如下代码。
path = C:/app/Administrator/product/11.2.0/client_1
INCLUDEPATH += $$path/oci/include
win32:LIBS += -L$$path/oci/lib/msvc -loci
以上写法同时支持mingw和msvc,其他系统编译过程也是类似。编译完成后默认会在你当前源码所在盘符的根目录下,会出现plugins目录,里面sqldrivers目录下就是对应编译生成好的插件动态库。
默认oracle的插件驱动代码是按照oracle12的函数写的,如果链接的是oracle11,则需要改动两行代码才能编译成功。打开qsql_oci.cpp文件大概在1559行代码左右,有个OCIBindByPos2函数改成OCIBindByPos,下面还有一行bindColumn.lengths改成(ub2*)bindColumn.lengths。
程序打包发布,所有前提:注意区分32/64位,你的程序是32位的就必须带上32位的库,64位的必须带上64位的库,这点Qt的库也是这个要求。mysql发布最简单,带上一个mysql的动态库文件就行(windows上的是libmysql.dll),非常简单。sqlserver不用带,因为是微软的亲儿子,一般操作系统自带。postgres需要带上libpq.dll、libintl-8.dll、libiconv-2.dll、libeay32.dll、ssleay32.dll这几个文件就行。oracle比较特殊,文件很多,基本上还是建议直接安装个oracle client客户端软件,然后对应bin目录设置到环境变量就好。
打包发布后测试下来,发现32位的程序也可以正常连接64位的mysql,64位的程序也可以正常连接32位的mysql,因此判断只要和程序的库的位数一致就行(编译的时候也是这个规则,32位的Qt程序编译数据库插件也要用32位的数据库链接库。),不需要和具体的数据库的位数一致,测试过mysql、sqlserver数据库都是类似规则,postgresql只测试了32位,oracle只测试了64位,现在绝大部分系统也都是64位了。
大量测试对比下来,通过odbc数据源的方式和直连数据库的方式批量插入大量数据记录,直连方式速度更快,约5%左右,所以建议尽量采用此方式,是在没有此方式的环境才采用odbc数据源的方式,Qt默认永远自带odbc数据库插件。
边栏推荐
- 用CPU方案打破内存墙?学PayPal堆傲腾扩容量,漏查欺诈交易量可降至1/30
- Redis related-02
- 多睡觉,能减肥,芝加哥大学最新研究:每天多睡1小时,等于少吃一根炸鸡腿...
- Is it safe for tonghuashun securities to open an account
- Comprehensive operation of financial risk management X of Dongcai
- Randla net: efficient semantic segmentation of large scale point clouds
- Redis related-03
- The more AI evolves, the more it resembles the human brain! Meta found the "prefrontal cortex" of the machine. AI scholars and neuroscientists were surprised
- China's SkyEye found suspicious signals of extraterrestrial civilization. Musk said that the Starship began its orbital test flight in July. Netinfo office: app should not force users to agree to proc
- Jilin University 22 spring March new development English comprehensive course (I) assignment assessment-00080
猜你喜欢
居家办公之后才明白的时间管理 | 社区征文
AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"
Amazon's other side in China
老叶的祝福
Perfect shuffle problem
Self cultivation and learning encouragement
Apple's legendary design team disbanded after jobs refused to obey cook
Randla net: efficient semantic segmentation of large scale point clouds
The release function completed 02 "IVX low code sign in system production"
威马招股书拆解:电动竞争已结束,智能排位赛刚开始
随机推荐
AI writes its own code to let agents evolve! The big model of openai has the flavor of "human thought"
教你如何在winpe里安装win11系统
AI自己写代码让智能体进化!OpenAI的大模型有“人类思想”那味了
Musk was sued for $258billion in MLM claims. TSMC announced the 2nm process. The Chinese Academy of Sciences found that the lunar soil contained water in the form of hydroxyl. Today, more big news is
Is it safe to open a stock account with the customer's haircut account link? Tell me what you know
現在,耳朵也要進入元宇宙了
Work assessment of pharmaceutical polymer materials of Jilin University in March of the 22nd spring -00025
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
Demonstration of combination of dream CAD cloud map and GIS
Tianshu night reading notes - 8.4 diskperf disassembly
孙武玩《魔兽》?有图有真相
Collaboration + Security + storage, cloud box helps Shenzhen edetai restructure its data center
Is it safe for tonghuashun securities to open an account
About PLSQL error initialization failure
【Rust投稿】从零实现消息中间件(6)-CLIENT
签到功能完成03《ivx低代码签到系统制作》
windows 2003 64位系统php运行报错:1% 不是有效的 win32 应用程序
程序员真人秀又来了!呼兰当主持挑灯狂补知识,SSS大佬本科竟是药学,清华朱军张敏等加入导师团...
华为上诉失败,被禁止在瑞典销售 5G 设备;苹果公司市值重获全球第一;Deno 完成 2100 万美元 A 轮融资|极客头条
Svn deployment