Skip to content

Commit fbaa2c8

Browse files
author
whqfor
committedDec 28, 2020
表字段操作
1 parent 8282ce8 commit fbaa2c8

File tree

3 files changed

+79
-71
lines changed

3 files changed

+79
-71
lines changed
 

‎.flutter-plugins-dependencies

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"sqflite","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.2+1/","dependencies":[]},{"name":"url_launcher","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher-5.7.10/","dependencies":[]}],"android":[{"name":"sqflite","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.2+1/","dependencies":[]},{"name":"url_launcher","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher-5.7.10/","dependencies":[]}],"macos":[{"name":"sqflite","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.2+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher_macos-0.0.1+9/","dependencies":[]}],"linux":[{"name":"url_launcher_linux","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher_linux-0.0.1+4/","dependencies":[]}],"windows":[{"name":"url_launcher_windows","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher_windows-0.0.1+3/","dependencies":[]}],"web":[{"name":"url_launcher_web","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher_web-0.1.5+1/","dependencies":[]}]},"dependencyGraph":[{"name":"sqflite","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2020-12-24 18:19:13.418702","version":"1.22.5"}
1+
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"sqflite","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.2+1/","dependencies":[]},{"name":"url_launcher","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher-5.7.10/","dependencies":[]}],"android":[{"name":"sqflite","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.2+1/","dependencies":[]},{"name":"url_launcher","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher-5.7.10/","dependencies":[]}],"macos":[{"name":"sqflite","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/sqflite-1.3.2+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher_macos-0.0.1+9/","dependencies":[]}],"linux":[{"name":"url_launcher_linux","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher_linux-0.0.1+4/","dependencies":[]}],"windows":[{"name":"url_launcher_windows","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher_windows-0.0.1+3/","dependencies":[]}],"web":[{"name":"url_launcher_web","path":"/Users/tal/.pub-cache/hosted/pub.flutter-io.cn/url_launcher_web-0.1.5+1/","dependencies":[]}]},"dependencyGraph":[{"name":"sqflite","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos","url_launcher_windows"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]},{"name":"url_launcher_windows","dependencies":[]}],"date_created":"2020-12-25 17:29:15.400678","version":"1.22.5"}

‎lib/button.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class DButton extends StatelessWidget {
1818
@override
1919
Widget build(BuildContext context) {
2020
return Container(
21-
margin: EdgeInsets.only(top: 2),
21+
margin: EdgeInsets.fromLTRB(2, 2, 2, 0),
2222
child: TextButton(
2323
onPressed: this.fn,
2424
style: TextButton.styleFrom(

‎lib/main.dart

+77-69
Original file line numberDiff line numberDiff line change
@@ -93,78 +93,86 @@ class _MyHomePageState extends State<MyHomePage> {
9393
title: Text(widget.title),
9494
),
9595
body: Center(
96-
child: Column(
97-
mainAxisAlignment: MainAxisAlignment.center,
98-
children: <Widget>[
99-
Text('数据库基地址: $_databasesPath'),
100-
SizedBox(height: 5),
101-
Text('demo.db 数据库地址: $_dbPath'),
102-
DButton('创建/获取数据库', () async {
103-
initDatabase();
104-
}),
105-
DButton('创建一张表', () async {
106-
// Insert some records in a transaction
107-
print('create table Test2 begin');
108-
await _database.execute(
109-
'CREATE TABLE Test2 (id INTEGER PRIMARY KEY, name TEXT, value INTEGER, num REAL)');
110-
print('create table Test2 end');
111-
}),
112-
DButton('新增表字段', () async {
113-
print('新增字段 begin');
114-
await _database.execute(
115-
'alter table Test2 ADD num2 REAL NOT NULL Default 0');
116-
print('新增字段 end');
117-
}),
118-
DButton('更改表字段', () async {
119-
print('更改字段 begin');
120-
await _database
121-
.execute('alter table Test2 rename column num to num3');
122-
print('更改字段 end');
123-
}),
124-
SizedBox(height: 5),
125-
Text('数据库的操作有两种方式,一种是直接使用sql语句进行操作,即Raw SQL操作, '
126-
'另一种是基于SQL helpers的操作,两种方式各有优势,点击下方查看具体使用'),
127-
SizedBox(height: 5),
128-
Row(
129-
mainAxisAlignment: MainAxisAlignment.spaceAround,
130-
children: [
131-
// 本demo中_database使用单例,直接传值db,或者传db路径再根据路径获取db,是一样的
132-
DButton('Raw SQL方式', () async {
133-
Navigator.of(context).push(MaterialPageRoute(
134-
builder: (BuildContext context) => RawSql(_database)));
135-
}),
136-
Container(width: 1, height: 40, color: Colors.grey),
137-
DButton('SQL helpers方式', () async {
138-
Navigator.of(context).push(MaterialPageRoute(
139-
builder: (BuildContext context) => SQLHelpers(_dbPath)));
140-
}),
141-
],
142-
),
143-
DButton('关闭数据库', () async {
144-
// Close the database
145-
print('close db');
146-
int version = await _database.getVersion();
147-
print('getVersion $version');
96+
child: Container(
97+
margin: EdgeInsets.symmetric(horizontal: 5),
98+
child: Column(
99+
mainAxisAlignment: MainAxisAlignment.center,
100+
children: <Widget>[
101+
Text('数据库基地址: $_databasesPath'),
102+
SizedBox(height: 5),
103+
Text('demo.db 数据库地址: $_dbPath'),
104+
DButton('创建/获取数据库', () async {
105+
initDatabase();
106+
}),
107+
Row(
108+
mainAxisAlignment: MainAxisAlignment.center,
109+
children: [
110+
DButton('创建一张表', () async {
111+
// Insert some records in a transaction
112+
print('create table Test2 begin');
113+
await _database.execute(
114+
'CREATE TABLE Test2 (id INTEGER PRIMARY KEY, name TEXT, value INTEGER, num REAL)');
115+
print('create table Test2 end');
116+
}),
117+
DButton('新增表字段', () async {
118+
print('新增字段 begin');
119+
await _database.execute(
120+
'alter table Test2 ADD num2 REAL NOT NULL Default 0');
121+
print('新增字段 end');
122+
}),
123+
DButton('更改表字段', () async {
124+
print('更改字段 begin');
125+
await _database
126+
.execute('alter table Test2 rename column num to num3');
127+
print('更改字段 end');
128+
}),
129+
],
130+
),
131+
SizedBox(height: 5),
132+
Text('数据库的操作有两种方式,一种是直接使用sql语句进行操作,即Raw SQL方式, '
133+
'另一种是基于SQL helpers的操作,两种方式各有优势,点击下方查看具体使用'),
134+
SizedBox(height: 5),
135+
Row(
136+
mainAxisAlignment: MainAxisAlignment.spaceAround,
137+
children: [
138+
// 本demo中_database使用单例,直接传值db,或者传db路径再根据路径获取db,是一样的
139+
DButton('Raw SQL方式', () async {
140+
Navigator.of(context).push(MaterialPageRoute(
141+
builder: (BuildContext context) => RawSql(_database)));
142+
}),
143+
Container(width: 1, height: 40, color: Colors.grey),
144+
DButton('SQL helpers方式', () async {
145+
Navigator.of(context).push(MaterialPageRoute(
146+
builder: (BuildContext context) => SQLHelpers(_dbPath)));
147+
}),
148+
],
149+
),
150+
DButton('关闭数据库', () async {
151+
// Close the database
152+
print('close db');
153+
int version = await _database.getVersion();
154+
print('getVersion $version');
148155

149-
await _database.close();
156+
await _database.close();
150157

151-
version = await _database.getVersion();
152-
print('getVersion $version');
153-
}),
154-
DButton('删除数据库', () async {
155-
// Delete the database
156-
await deleteDatabase(_dbPath);
157-
}),
158+
version = await _database.getVersion();
159+
print('getVersion $version');
160+
}),
161+
DButton('删除数据库', () async {
162+
// Delete the database
163+
await deleteDatabase(_dbPath);
164+
}),
158165

159-
DButton('查看本页代码', () async {
160-
final url =
161-
"https://github.com/xes1v1/f_sql/blob/main/lib/main.dart";
162-
if (await canLaunch(url)) {
163-
await launch(url);
164-
}
165-
})
166-
],
167-
),
166+
DButton('查看本页代码', () async {
167+
final url =
168+
"https://github.com/xes1v1/f_sql/blob/main/lib/main.dart";
169+
if (await canLaunch(url)) {
170+
await launch(url);
171+
}
172+
})
173+
],
174+
),
175+
)
168176
),
169177
);
170178
}

0 commit comments

Comments
 (0)
Please sign in to comment.