当前位置:网站首页>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数据库插件。

边栏推荐
- Redis related-03
- Work assessment of pharmacotherapeutics of Jilin University in March of the 22nd spring -00064
- Collaboration + Security + storage, cloud box helps Shenzhen edetai restructure its data center
- 【组队学习】SQL编程语言笔记——Task04
- Demonstration of combination of dream CAD cloud map and GIS
- Self cultivation and learning encouragement
- Is it safe to open a stock account with the customer's haircut account link? Tell me what you know
- The problem that only the home page can be accessed under openSUSE Apache laravel
- Maintenant, les oreilles vont entrer dans le métacosme.
- 亚马逊在中国的另一面
猜你喜欢

Lu Qi invests in quantum computing for the first time

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

腾讯开源项目「应龙」成Apache顶级项目:前身长期服务微信支付,能hold住百万亿级数据流处理...

Mobile mall project operation

谷歌创始人布林二婚破裂:被曝1月已提出与华裔妻子离婚,目前身家6314亿美元...
![[rust submission] review impl trail and dyn trail in rust](/img/bc/05b3e031659ce19d6f6e3887d70512.jpg)
[rust submission] review impl trail and dyn trail in rust

Why can banana be a random number generator? Because it is the "king of radiation" in the fruit industry

The era of copilot free is over! The official version is 67 yuan / month, and the student party and the defenders of popular open source projects can prostitute for nothing

后台页制作01《ivx低代码签到系统制作》

签到功能完成03《ivx低代码签到系统制作》
随机推荐
亚马逊在中国的另一面
Understand (DI) dependency injection in PHP
Tencent's open source project "Yinglong" has become a top-level project of Apache: the former long-term service wechat payment can hold a million billion level of data stream processing
AI自己写代码让智能体进化!OpenAI的大模型有“人类思想”那味了
Crawler grabs the idea of reading on wechat
Tencent Open Source Project "Yinglong" est devenu un projet Apache de haut niveau: l'ancien Service à long terme Wechat payment, peut maintenir un million de milliards de niveaux de traitement de flux
Is it safe to open a stock account on Huatai Securities?
TC object structure and abbreviation
Russian Airi Research Institute, etc. | SEMA: prediction of antigen B cell conformation characterization using deep transfer learning
Standing at the center of the storm: how to change the engine of Tencent
How to choose a securities company when opening an account with a compass? Which is safer
吴恩达机器学习新课程又来了!旁听免费,小白友好
OpenSUSE environment variable settings
Two common OEE monitoring methods for equipment utilization
Copilot免费时代结束!正式版67元/月,学生党和热门开源项目维护者可白嫖
Work assessment of pharmaceutical polymer materials of Jilin University in March of the 22nd spring -00025
zabbix的安装避坑指南
华为上诉失败,被禁止在瑞典销售 5G 设备;苹果公司市值重获全球第一;Deno 完成 2100 万美元 A 轮融资|极客头条
Work assessment of Biopharmaceutics of Jilin University in March of the 22nd spring -00005
Redis related-01