Skip to content

Commit

Permalink
新增SQLITE WAL模式多线程写数据库程序;
Browse files Browse the repository at this point in the history
删除sqltableview;
  • Loading branch information
RealChuan committed Nov 2, 2023
1 parent 6103df7 commit 6bec3f2
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 442 deletions.
81 changes: 29 additions & 52 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,32 @@ AnalyzeTemporaryDtors: false
FormatStyle: file
User: user
CheckOptions:
- key: readability-identifier-naming.AbstractClassCase
value: CamelCase
- key: readability-identifier-naming.ClassCase
value: CamelCase
- key: readability-identifier-naming.ClassConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.ClassConstantPrefix
value: 'k'
- key: readability-identifier-naming.ClassMemberCase
value: lower_case
- key: readability-identifier-naming.ClassMemberPrefix
value: 'm_'
- key: readability-identifier-naming.ClassMethodCase
value: camelBack
- key: readability-identifier-naming.ConstexprVariableCase
value: UPPER_CASE
- key: readability-identifier-naming.ConstexprVariablePrefix
value: 'k'
- key: readability-identifier-naming.EnumCase
value: CamelCase
- key: readability-identifier-naming.EnumConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.EnumConstantPrefix
value: ''
- key: readability-identifier-naming.FunctionCase
value: camelBack
- key: readability-identifier-naming.FunctionParameterCase
value: lower_case
- key: readability-identifier-naming.GlobalConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.GlobalConstantPrefix
value: 'k'
- key: readability-identifier-naming.GlobalFunctionCase
value: camelBack
- key: readability-identifier-naming.GlobalVariableCase
value: lower_case
- key: readability-identifier-naming.GlobalVariablePrefix
value: 'g_'
- key: readability-identifier-naming.InlineNamespaceCase
value: lower_case
- key: readability-identifier-naming.LocalConstantCase
value: UPPER_CASE
- key: readability-identifier-naming.LocalConstantPrefix
value: 'k'
- key: readability-identifier-naming.LocalVariableCase
value: lower_case
- key: readability-identifier-naming.MacroDefinitionCase
value: UPPER_CASE
- key: readability-identifier-naming.NamespaceCase
value: lower_case
- key: bugprone-narrowing-conversions.IgnoreFloatingPointPrecisionLoss
value: 'false'
# 类名改为大驼峰

- key: readability-identifier-naming.ClassCase
value: CamelCase

# 函数名改为小驼峰

- key: readability-identifier-naming.FunctionCase
value: camelBack

# 变量名改为小驼峰

- key: readability-identifier-naming.VariableCase
value: camelBack

# 关闭一些过于严苛或者不适合的检查

- key: readability-braces-around-statements.ShortStatementLines
value: '0'
- key: readability-magic-numbers.IgnorePowersOf2IntegerLiterals
value: '1'
- key: modernize-use-trailing-return-type.UseEastWestConst
value: '1'
- key: readability-identifier-naming.ClassMemberPrefix
value: 'm_'
- key: readability-identifier-naming.ConstexprVariablePrefix
value: 'k'
- key: readability-identifier-naming.GlobalVariablePrefix
value: 'g_'
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ add_subdirectory(ProgressArc)
add_subdirectory(ProgressBar)
add_subdirectory(ReactorServer)
add_subdirectory(SlipButton)
add_subdirectory(SqlTabview)
add_subdirectory(SqliteWAL)
add_subdirectory(TableViewModel)
add_subdirectory(Thread)
add_subdirectory(TreeViewModel)
Expand Down
2 changes: 1 addition & 1 deletion Qt-Examples.pro
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SUBDIRS += \
ReactorServer \
SimpleUdp \
SlipButton \
SqlTabview \
SqliteWAL \
TableViewModel \
Thread \
TreeViewModel \
Expand Down
83 changes: 50 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

## [QT实用小技巧(想到就更新) | 自由意志 (realchuan.github.io)](https://realchuan.github.io/2021/10/12/QT%E5%AE%9E%E7%94%A8%E5%B0%8F%E6%8A%80%E5%B7%A7%EF%BC%88%E6%83%B3%E5%88%B0%E5%B0%B1%E6%9B%B4%E6%96%B0%EF%BC%89/)

## [Battery](Battery/)——电池
## [Battery](/Battery/)——电池

<table>
<tr>
Expand All @@ -14,74 +14,76 @@
</tr>
</table>

## [Bootstarp](Bootstarp/)--程序开机自启动设置和检测;
## [Bootstarp](/Bootstarp/)--程序开机自启动设置和检测

1. Windows下读写注册表实现开机自启动,有两个位置可以写入;

```powershell
HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run //对于所有用户
HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run // 对于当前用户
```

2. MacOS下拷贝plist文件到~/Library/LaunchAgents/,使用launchctl load/unload命令实现开机自启动;
3. Ubuntu下有两种方式:
1. 使用systemctl --user enable/disable命令实现开机自启动;
1. 拷贝.service和.timer文件到~/.config/systemd/user/,使用systemctl --user enable/disable命令实现开机自启动;
2. systemctl命令用于.timer文件,.timer文件用于定时执行.service文件,防止图形界面启动后,出现qxcbconnection: could not connect to display错误;
2. 把/usr/share/Application/下的.desktop文件拷贝到~/.config/autostart/下,实现开机自启动(未验证);

## [BubbleWindow](BubbleWindow/)——气泡式对话框,也可作工具提示(ToolTip)
## [BubbleWindow](/BubbleWindow/)——气泡式对话框,也可作工具提示(ToolTip)

<div align=center><img src="BubbleWindow/picture/Bubble.png"></div>

## [Chart](Chart/)——可视化图表绘制,参考[ 使用 QChart 显示实时动态曲线 ](https://qtdebug.com/qtbook-paint-realtime-curve-qchart/ "qtdebug/公孙二狗") 和QChart相关示例
## [Chart](Chart/)——可视化图表绘制,参考[使用 QChart 显示实时动态曲线](https://qtdebug.com/qtbook-paint-realtime-curve-qchart/ "qtdebug/公孙二狗") 和QChart相关示例

<div align=center><img src="Chart/picture/Chart_1.png">图一二是动态曲线</div>
<div align=center><img src="Chart/picture/Chart_2.png">图一二是动态曲线, 图二坐标轴也会动态变化</div>

## [CheckBoxStandardItem](/CheckBoxStandardItem)——可以勾选的StandardItem,而且根据勾选状态自动更新父节点状态或者子节点状态
## [CheckBoxStandardItem](/CheckBoxStandardItem/)——可以勾选的StandardItem,而且根据勾选状态自动更新父节点状态或者子节点状态

<div align=center><img src="CheckBoxStandardItem/picture/checkBoxStandardItem.png"></div>

## [Clock](/Clock)——时钟
## [Clock](/Clock/)——时钟

<div align=center><img src="Clock/picture/Clock.png"></div>

## [DashBoard](/DashBoard)——仪表盘
## [DashBoard](/DashBoard/)——仪表盘

<div align=center><img src="DashBoard/picture/DashBoard.png"></div>

## [FlowLayout](FlowLayout/)——流式布局,来自QT示例Flow Layout Example
## [FlowLayout](/FlowLayout/)——流式布局,来自QT示例Flow Layout Example

<div align=center><img src="FlowLayout/picture/FlowLayout.png"></div>

## [DragDrop](DragDrop/)——简单控件拖拽,参考QT示例Drag and Drop Puzzle Example
## [DragDrop](/DragDrop/)——简单控件拖拽,参考QT示例Drag and Drop Puzzle Example

## [HttpClient ](/HttpClient)——http客户端
## [HttpClient](/HttpClient/)——http客户端

## [ImageCarousel](ImageCarousel/)——简易图片轮播
## [ImageCarousel](/ImageCarousel/)——简易图片轮播

<div align=center><img src="ImageCarousel/picture/ImageCarousel.jpg"></div>

## [GridViewModel ](/GridViewModel)——基于QListView的自适应宫图
## [GridViewModel](/GridViewModel/)——基于QListView的自适应宫图

<div align=center><img src="GridViewModel/picture/GridView.png"></div>

## [LogAsynchronous](LogAsynchronous/)——异步日志,开辟一个线程专门往文件里写日志,前后端分离
## [LogAsynchronous](/LogAsynchronous/)——异步日志,开辟一个线程专门往文件里写日志,前后端分离

1. 日志文件名:应用程序名(appname).时间(time,精确到秒).主机hostname.进程ID(Tid).log(.count),假如一天内写的单个日志大约接近1G,会自动加后缀(.1,.2.3...,以此类推)新建新的日志文件去写,每天0点依然会rollFile;
1. 正常文件名:LogAsynchronous.2020-04-26-20-29-03.Youth.11828.log;
2. 当日写日志接近1G,新建的文件名:LogAsynchronous.2020-04-26-20-38-55.Youth.11828.log.1;
2. 日志格式:时间(time,精确到毫秒).线程ID(Pid).日志级别(debug).打印信息(msg).文件(File).行号(Line)。
1. 比如:2020-04-26 20:38:55.818 2052 [Debug] 123456789qwertyuioplkjhgfdsa 8412789-File:(..\logAsynchronous\main.cpp) Line:(19);

## [MulClient](MulClient/)——多线程客户端,一个线程一个客户端(怎么可以绕开系统限制,模拟百万个客户端)
## [MulClient](/MulClient/)——多线程客户端,一个线程一个客户端(怎么可以绕开系统限制,模拟百万个客户端)

## [MulServer](MulServer/)——多线程服务端,一个线程一个客户端处理(处理实时性很高的TCP通讯)
## [MulServer](/MulServer/)——多线程服务端,一个线程一个客户端处理(处理实时性很高的TCP通讯)

## [NavigationProgressBar](/NavigationProgressBar)——导航进度栏;
## [NavigationProgressBar](/NavigationProgressBar/)——导航进度栏

<div align=center><img src="NavigationProgressBar/picture/NavigationProgressBar.png"></div>

## [PasswordLineEdit](PasswordLineEdit/)——密码输入框
## [PasswordLineEdit](/PasswordLineEdit/)——密码输入框

<table>
<tr>
Expand All @@ -90,23 +92,23 @@
</tr>
</table>

## [ProgressArc](ProgressArc/)——圆弧进度条
## [ProgressArc](/ProgressArc/)——圆弧进度条

<div align=center><img src="ProgressArc/picture/ProgressArc.png"></div>

## [ProgressBar](ProgressBar)——QProgressBar圆角替代方案
## [ProgressBar](/ProgressBar/)——QProgressBar圆角替代方案

<div align=center><img src="ProgressBar/picture/ProgressBar.png"></div>

## [ReactorServer](ReactorServer/)——多线程服务端,Reactor模式(Echo)
## [ReactorServer](/ReactorServer/)——多线程服务端,Reactor模式(Echo)

## [SimpleUdp](SimpleUdp/)——简单UDP例子,广播和接收
## [SimpleUdp](/SimpleUdp/)——简单UDP例子,广播和接收

## [ShowInMyComputer](ShowInMyComputer/)——在我的电脑中显示当前应用程序
## [ShowInMyComputer](/ShowInMyComputer/)——在我的电脑中显示当前应用程序

防火墙白名单。

## [SlipButton](SlipButton/)——滑动按钮
## [SlipButton](/SlipButton/)——滑动按钮

另:更简单的实现:[有动画效果的 CheckBox](http://qtdebug.com/qtbook-animated-checkbox/)

Expand All @@ -117,9 +119,21 @@
</tr>
</table>

## [SqlTabview](SqlTabview/)——SQLite数据库调用,模型方法;
## [SqliteWAL](/SqliteWAL/)——Sqlite WAL 模式下多线程并发写入数据库程序

### WAL模式的优点

1. 提高了并发性:WAL模式允许多个读取器和一个写入器同时访问数据库,可以提高并发性能和性能;
2. 崩溃恢复:WAL模式在发生崩溃时确保数据库保持一致,通过在提交事务之前将所有更改刷新到日志文件来实现;
3. 改进了写入性能:WAL模式允许并发写入,可以比默认的回滚模式更好地改进写入性能;

### WAL模式的注意事项

## [TableViewModel](TableViewModel/)——表格视图;
1. WAL模式仅适用于SQLite 3.35.5+版本;
2. 增加了磁盘使用量:与回滚模式相比,WAL模式需要更多的磁盘空间,因为它在提交更改之前将所有更改都写入日志文件;
3. 读取性能较慢:在WAL模式下,读取操作不会被写入操作阻塞,如果同时进行读取和写入操作,可能导致数据不一致。

## [TableViewModel](/TableViewModel/)——表格视图

1. 各种自定义代理
1. [ButtonDelegate](./TableViewModel/buttondelegate.h)
Expand All @@ -131,24 +145,27 @@

<div align=center><img src="TableViewModel/picture/TabViewModelDelegate.jpg"></div>

## [Thread](Thread/)——多线程例子,6种写法
## [Thread](/Thread/)——多线程例子,6种写法

## [TreeViewModel](TreeViewModel/)——树形视图(MVC),QtCreator源码
## [TreeViewModel](/TreeViewModel/)——树形视图(MVC),QtCreator源码

<div align=center><img src="TreeViewModel/picture/TreeView.png"></div>
<div align=center><img src="TreeViewModel/picture/ListView.png"></div>

## [Validator](Validator/)——加强版IntValidator(QIntValidator)和DoubleValidator(QDoubleValidator)
## [Validator](/Validator/)——加强版IntValidator(QIntValidator)和DoubleValidator(QDoubleValidator)

## [packaging](/packaging/)——打包脚本

1. [macos](/packaging/macos/)——macos qmake编译、打包dmg包脚本(`python`/`appdmg`);
2. [ubuntu](/packaging/ubuntu/)——ubuntu qmake编译、打包AppImage/deb包脚本(`linuxdeployqt-continuous-x86_64.AppImage`/`dpkg-deb`);
1. [使用root权限打开应用程序的一种方法](/packaging/ubuntu/opt/MyApp/MyApp.sh)

## [packaging](packaging/)——打包脚本;
1. [macos](packaging/macos/)——macos qmake编译、打包dmg包脚本(`python`/`appdmg`);
2. [ubuntu](packaging/ubuntu/)——ubuntu qmake编译、打包AppImage/deb包脚本(`linuxdeployqt-continuous-x86_64.AppImage`/`dpkg-deb`);
1. [使用root权限打开应用程序的一种方法](packaging/ubuntu/opt/MyApp/MyApp.sh)
```shell
#!/bin/sh
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /opt/MyApp/MyApp
```
3. [windows](packaging/windows/)——windows qmake编译、打包安装脚本(`Innosetup`);

3. [windows](/packaging/windows/)——windows qmake编译、打包安装脚本(`Innosetup`);
1. `Innosetup` `signtool`

```
Expand Down
10 changes: 0 additions & 10 deletions SqlTabview/CMakeLists.txt

This file was deleted.

30 changes: 0 additions & 30 deletions SqlTabview/SqlTabview.pro

This file was deleted.

11 changes: 0 additions & 11 deletions SqlTabview/main.cpp

This file was deleted.

Loading

0 comments on commit 6bec3f2

Please sign in to comment.