Skip to content

Commit

Permalink
feat: 更新示例
Browse files Browse the repository at this point in the history
  • Loading branch information
dunwu committed Oct 25, 2023
1 parent 4c3ab73 commit 088d49c
Show file tree
Hide file tree
Showing 18 changed files with 130 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
* Mysql 测试例
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @see https://dev.mysql.com/doc/connector-j/5.1/en/
*/
public class MysqlDemoTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @since 2018/6/19
*/
public class RedissonStandaloneTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Jedis 测试例
*
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @see https://github.com/xetorthio/jedis
*/
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Set;

/**
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("dev")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @since 2019-03-05
*/
@Slf4j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.sql.Statement;

/**
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @since 2019-03-05
*/
public class SqliteDemo {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- --------------------------------------------------------------------------------------
-- 查找重复的电子邮箱
-- @link https://leetcode-cn.com/problems/duplicate-emails/
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2020/02/29
-- ----------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion codes/mysql/SQL必知必会示例/select.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 查询示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/5/5
-- ----------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion codes/mysql/SQL性能优化/SQL函数影响索引.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- 函数操作影响索引效率示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- ----------------------------------------------------------------------------------------

-- 步骤 1、建表
Expand Down
2 changes: 1 addition & 1 deletion codes/mysql/SQL性能优化/等MDL锁.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- 函数操作影响索引效率示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- ----------------------------------------------------------------------------------------

CREATE TABLE t (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 事务示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2020/02/29
-- ----------------------------------------------------------------------------------------

Expand Down
55 changes: 55 additions & 0 deletions codes/mysql/事务/幻读示例1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- --------------------------------------------------------------------------------------
-- 幻读示例
-- 实验说明:以下 SQL 脚本必须严格按照顺序执行,并且事务 A 和事务 B 必须在不同的 Client 中执行。
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2023/10/25
-- ----------------------------------------------------------------------------------------

-- --------------------------------------------------------------------- (1)数据初始化

-- 创建表 test
CREATE TABLE `test` (
`id` INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
`value` INT(10) NOT NULL
);

-- 数据初始化
INSERT INTO `test` (`id`, `value`) VALUES (1, 1);
INSERT INTO `test` (`id`, `value`) VALUES (2, 2);
INSERT INTO `test` (`id`, `value`) VALUES (3, 3);

-- --------------------------------------------------------------------- (2)事务 A

BEGIN;

-- 查询 id = 4 的记录
SELECT * FROM `test` WHERE `id` = 4;
-- 结果为空

-- --------------------------------------------------------------------- (3)事务 B

BEGIN;

INSERT INTO `test` (`id`, `value`) VALUES (4, 4);

COMMIT;

-- --------------------------------------------------------------------- (4)事务 A

-- 查询 id = 4 的记录
SELECT * FROM `test` WHERE `id` = 4;
-- 结果依然为空

-- 成功更新本应看不到的记录 id = 4
UPDATE `test` SET `value` = 0 WHERE `id` = 4;

-- 再一次查询 id = 4 的记录
SELECT * FROM `test` WHERE `id` = 4;
-- 结果为:
-- +----+-------+
-- | id | value |
-- +----+-------+
-- | 4 | 0 |
-- +----+-------+

COMMIT;
53 changes: 53 additions & 0 deletions codes/mysql/事务/幻读示例2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- --------------------------------------------------------------------------------------
-- 幻读示例
-- 实验说明:以下 SQL 脚本必须严格按照顺序执行,并且事务 A 和事务 B 必须在不同的 Client 中执行。
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2023/10/25
-- ----------------------------------------------------------------------------------------

-- --------------------------------------------------------------------- (1)数据初始化

-- 创建表 test
CREATE TABLE `test` (
`id` INT(10) UNSIGNED PRIMARY KEY AUTO_INCREMENT,
`value` INT(10) NOT NULL
);

-- 数据初始化
INSERT INTO `test` (`id`, `value`) VALUES (1, 1);
INSERT INTO `test` (`id`, `value`) VALUES (2, 2);
INSERT INTO `test` (`id`, `value`) VALUES (3, 3);

-- --------------------------------------------------------------------- (2)事务 A

BEGIN;

-- 查询 id > 2 的记录数
SELECT COUNT(*) FROM `test` WHERE `id` > 2;
-- 结果为:
-- +----------+
-- | count(*) |
-- +----------+
-- | 1 |
-- +----------+

-- --------------------------------------------------------------------- (3)事务 B

BEGIN;

INSERT INTO `test` (`id`, `value`) VALUES (4, 4);

COMMIT;

-- --------------------------------------------------------------------- (4)事务 A

-- 查询 id = 4 的记录
SELECT COUNT(*) FROM `test` WHERE `id` > 2 FOR UPDATE;
-- 结果为:
-- +----------+
-- | count(*) |
-- +----------+
-- | 2 |
-- +----------+

COMMIT;
2 changes: 1 addition & 1 deletion codes/mysql/基本DDL示例.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 基本 DDL 语句示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/4/28
-- ----------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion codes/mysql/基本DML示例.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 基本 DML 语句示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/4/28
-- ----------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion codes/mysql/基本TCL示例.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 基本 TCL 语句示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/4/28
-- ----------------------------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion codes/mysql/常见查询示例.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- --------------------------------------------------------------------------------------
-- Mysql 常见查询示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/5/4
-- ----------------------------------------------------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions codes/mysql/触发器示例.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* Mysql 触发器(TRIGGER)创建、使用示例
* @author Zhang Peng
* @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
* @date 2018/5/2
*/
-- --------------------------------------------------------------------------------------
-- Mysql 基本 DDL 语句示例
-- @author Zhang Peng
-- @author <a href="mailto:forbreak@163.com">Zhang Peng</a>
-- @date 2018/4/28
-- ----------------------------------------------------------------------------------------

Expand Down

0 comments on commit 088d49c

Please sign in to comment.