Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize General data Generator in Qt Database

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to implement a general data generator in Qt database. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

I. Preface

There are two application scenarios that need to use a data generator, one is to test the performance of the database, for example, it takes time to compare query or update statements between 1 million and 10 million records, and the other is to randomly simulate and generate a pile of data. used to test the performance of the program, to see whether the code execution of the program is affected when the amount of data in the program reaches millions of levels. Many people think that the performance of the sqlite database is more than hundreds of thousands, so they use this data generator to generate a random simulation to generate 100 million records, and test it down to find that there is a loss of performance, but unlike the legendary garbage, at least it is completely available, as long as you pay attention to the index, the file volume is relatively large, the file volume expands to 1.2GB, and it is estimated that the performance loss is largely in disk read and write.

By processing different sql statements (query, insert, delete, update) for various databases (sqlite, postgres, mysql, sqlserver, etc.) at different data volume stages (10, 000, 1 million, 10 million, etc.), Qt has built-in sqlite database, so the support for sqlite is the fastest and most friendly, followed by postgresql database, followed by mysql, and the database with the worst performance is the database connected in ODBC mode. For example, sqlserver database must be connected in the form of odbc, because odbc is an intermediate tier, and its theoretical performance is certainly not as fast as direct connection processing, but throughout the scenarios of various projects written in Qt, it rarely requires tens of millions of levels of data, and to this extent, you can consider sub-database and sub-table to solve.

II. Functional features

At the same time, it supports a variety of databases such as odbc, sqlite, mysql, postgresql, sqlserver, oracle, people's Congress and so on.

A database class can not only manage local database communication, but also support remote database communication.

Database threads support the execution of various sql statements, including individual and batch statements.

All classes in the component print messages, error messages, and execution results are signaled.

Integrated database general page turning class (responsible for specific processing logic), with paging navigation controls (responsible for appearance), to form a super powerful page turning control.

Integrated database automatic cleaning class, set the maximum number of records to automatically clean up early data in the background.

Integrated custom delegate class, supporting check boxes, text boxes, drop-down boxes, date boxes, fine-tuning boxes, progress bars, and so on.

At the same time support Qt4-Qt6, test Qt4.6 to Qt6.3 any version, any system and compiler.

This component is trouble-free 360 days 7 times 24 hours running in at least tens of thousands of sites, commercial grade quality assurance.

Each class corresponds to a complete and detailed usage example, with detailed annotations, which is very suitable for reading and learning.

It can be run as a stand-alone program, such as automatically cleaning up early data and synchronizing data to the cloud.

All threading, no card interface, automatically reconnect the database.

General test case, sqlite database, database generator inserts 1000 records per second for about 0.003 seconds, while automatically cleans up data classes and deletes 1000 records per second for about 0.13s. Different threads do not interfere with each other.

Third, experience address

Experience address: https://pan.baidu.com/s/15ZKAlptW-rDcNq8zlzdYLg extraction code: uyes file name: bin_dbtool.zip

Domestic site: https://gitee.com/feiyangqingyun

International site: https://github.com/feiyangqingyun

4. Effect picture

5. Related code void frmDbCreat::on_btnOpen_clicked () {if (ui- > btnOpen- > text () = = "Open database") {DbInfo dbInfo; dbInfo.connName = this- > objectName (); dbInfo.dbName = AppConfig::DbName2; dbInfo.hostName = AppConfig::HostName2; dbInfo.hostPort = AppConfig::HostPort2; dbInfo.userName = AppConfig::UserName2; dbInfo.userPwd = AppConfig::UserPwd2 QString dbType = AppConfig::DbType2.toUpper (); if (dbType = = "SQLITE") {dbInfo.dbName = DbHelper::getDbDefaultFile ();} dbConn- > setConnInfo (DbHelper::getDbType (dbType), dbInfo); if (dbConn- > openDb ()) {dbConn- > start (); ui- > btnOpen- > setText ("shut down database") } else {QString error = dbConn- > getDatabase (). LastError (). Text (); QUIHelper::showMessageBoxError ("failed to open database!\ n" + error, 3);}} else {dbConn- > stop (); dbConn- > closeDb (); ui- > btnOpen- > setText ("Open database"); on_btnClear_clicked () } QTimer::singleShot (100,100, this, SLOT (getMaxID ()); QTimer::singleShot (1000, this, SLOT (on_btnStart_clicked ();} void frmDbCreat::on_btnCopy_clicked () {/ / paste database setting parameters to ui- > cboxDbType- > setCurrentIndex (ui- > cboxDbType- > findText (AppConfig::LocalDbType)); ui- > txtDbName- > setText (AppConfig::LocalDbName); ui- > txtHostName- > setText (AppConfig::LocalHostName) Ui- > txtHostPort- > setText (QString::number (AppConfig::LocalHostPort)); ui- > txtUserName- > setText (AppConfig::LocalUserName); ui- > txtUserPwd- > setText (AppConfig::LocalUserPwd);} void frmDbCreat::getMaxID () {if (! dbConn- > getOk ()) {return;} / / take out the corresponding table name and self-increment field QString sqlColumn = AppConfig::SqlColumn2; QString sqlValue = AppConfig::SqlValue2 according to the insert sql statement If (sqlValue.contains ("AUTO_INCREMENT")) {sqlColumn.replace ("insert into", "); sqlValue.replace (" values ","); QString tableName = sqlColumn.split (" ("). First (); sqlColumn.replace (tableName,"); sqlColumn.replace ("(", "); sqlColumn.replace (") ",") SqlValue.replace ((","); sqlValue.replace (")", "); QStringList listColumn = sqlColumn.split (", "); QStringList listValue = sqlValue.split (", "); int index = listValue.indexOf (" 'AUTO_INCREMENT' "); QString columnName = listColumn.at (index) / / fetch the maximum number of records maxID = DbHelper::getMaxID (tableName, columnName, dbConn- > getDatabase ());}} void frmDbCreat::on_btnDo_clicked () {if (! dbConn- > getOk ()) {return;} QString sql = AppConfig::SqlColumn2 + "" + AppConfig::SqlValue2; / / qDebug () btnStart- > text () = "start the service") {on_btnDo_clicked () Timer- > start (); ui- > btnStart- > setText ("stop service");} else {timer- > stop (); ui- > btnStart- > setText ("start service") }} this is the end of the article on "how to implement a general data generator in Qt database". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report