DTL 事务控制语言

1、一个简单的事务

  • 开启事务:start transaction
  • 回滚事务:rollback
  • 提交事务:commit
mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)


mysql> update user set fee = 1200 where id = 1;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0


mysql> select * from user;
+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+
| id | user_name | sex | password                         | email           | address | fee     | age | create_at           |
+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+
|  1 | sian      | 男  | e10adc3949ba59abbe56e057f20f883e | yusian@163.com  | NULL    | 1200.00 |  32 | 2019-04-23 14:45:36 |
|  2 | 余西安    | 男  | c4ca4238a0b923820dcc509a6f75849b | yusian@163.com  | NULL    |    1.00 |  33 | 2019-04-21 17:12:55 |
|  3 | Jack      | 男  | c81e728d9d4c2f636f067f89cc14862c | jack@yusian.com | NULL    |    0.00 |  22 | 2019-04-21 20:11:59 |
|  4 | Rose      | 女  | eccbc87e4b5ce2fe28308fd9f2a7baf3 | rose@yusian.com | NULL    |    0.00 |  18 | 2019-04-22 10:46:41 |
|  5 | Sim       | 女  | a87ff679a2f3e71d9181a67b7542122c | sim@yusian.com  | NULL    |    0.00 |  28 | 2019-04-22 10:46:41 |
|  6 | Tony      | 男  | c4ca4238a0b923820dcc509a6f75849b | tony@yusian.com | NULL    |    0.00 |  22 | 2019-04-21 20:41:26 |
+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+
6 rows in set (0.00 sec)


mysql> rollback;
Query OK, 0 rows affected (0.00 sec)


mysql> select * from user;
+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+
| id | user_name | sex | password                         | email           | address | fee     | age | create_at           |
+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+
|  1 | sian      | 男  | e10adc3949ba59abbe56e057f20f883e | yusian@163.com  | NULL    | 1100.00 |  32 | 2019-04-23 14:38:53 |
|  2 | 余西安    | 男  | c4ca4238a0b923820dcc509a6f75849b | yusian@163.com  | NULL    |    1.00 |  33 | 2019-04-21 17:12:55 |
|  3 | Jack      | 男  | c81e728d9d4c2f636f067f89cc14862c | jack@yusian.com | NULL    |    0.00 |  22 | 2019-04-21 20:11:59 |
|  4 | Rose      | 女  | eccbc87e4b5ce2fe28308fd9f2a7baf3 | rose@yusian.com | NULL    |    0.00 |  18 | 2019-04-22 10:46:41 |
|  5 | Sim       | 女  | a87ff679a2f3e71d9181a67b7542122c | sim@yusian.com  | NULL    |    0.00 |  28 | 2019-04-22 10:46:41 |
|  6 | Tony      | 男  | c4ca4238a0b923820dcc509a6f75849b | tony@yusian.com | NULL    |    0.00 |  22 | 2019-04-21 20:41:26 |
+----+-----------+-----+----------------------------------+-----------------+---------+---------+-----+---------------------+
6 rows in set (0.00 sec)

[……]

继续阅读

DQL常用操作及常见问题

DQL: Database Query Language

1、查询某字段去重复

  • select distinct xxxx from xxxx

2、合并字段查询函数concat( )、concat_ws( )

  • select concat(user_name, password) from user;
  • select concat(user_name, password) as user_name_email from user;
  • select concat_ws(‘->’, user_name, password) from user; // 查询结果用’->’分隔符隔开
    [……]

    继续阅读

DDL常用操作及常见问题

DDL(data defination language)数据定义语言

1、字符编码问题

  • 查看当前编码方式,show variables like ‘%char%’;
  • 设置当前操作及显示编码方式 set names utf8;
  • 修改xxx表的默认字符集:alter table xxx default character set utf8;
  • 修改数据库xxx默认字符集:alter database xxx default character set utf8;
  • 修改表创建字段默认字符集:alter table xxx default character set utf8 collate u[……]

    继续阅读

Swift5.0基本语法

1、数组

// 定义不可变数组
let array:[String] = ["1", "2", "3", "4"]
print(array)
// 定义可变数组
var mutArray = ["one", "two", "three", "four"]
print(mutArray)
// 修改数组元素值
mutArray[0] = "1";
print(mutArray)
// 根据范围修改元素值
mutArray[1...3] = ["2", "3", "4"]
print(mutArray)
// 增加元素
mutArray += ["five", "six”];
print(mutArray)

[……]

继续阅读

多路IO转接模型

1、select函数

#include <sys/select.h>

/* According to earlier standards */
#include <sys/time.h>
#include <sys/types.h>
#include <unistd.h>

int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);

void FD_CLR(int fd, fd_set *set);
int  FD_ISSET(int fd, fd_set *set);
void FD_SET(int fd, fd_set *set);
void FD_ZERO(fd_set *set);

demo示例[……]

继续阅读