Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
DoraemonKit
提交
ac4dbfc9
D
DoraemonKit
项目概览
DiDi
/
DoraemonKit
大约 1 年 前同步成功
通知
166
Star
19623
Fork
3062
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
DoraemonKit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ac4dbfc9
编写于
3月 31, 2019
作者:
Y
yixiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
iOS数据库中表名的预览
上级
b2f1510a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
218 addition
and
3 deletion
+218
-3
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/Util/DoraemonDBManager.h
...raemonKit/Src/Core/Plugin/Sanbox/Util/DoraemonDBManager.h
+23
-0
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/Util/DoraemonDBManager.m
...raemonKit/Src/Core/Plugin/Sanbox/Util/DoraemonDBManager.m
+61
-0
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/VC/DoraemonDBTableViewController.h
...Src/Core/Plugin/Sanbox/VC/DoraemonDBTableViewController.h
+16
-0
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/VC/DoraemonDBTableViewController.m
...Src/Core/Plugin/Sanbox/VC/DoraemonDBTableViewController.m
+24
-0
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/VC/DoraemonSanboxDetailViewController.m
...ore/Plugin/Sanbox/VC/DoraemonSanboxDetailViewController.m
+45
-3
iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/Sanbox/DoraemonDemoSanboxViewController.m
...nKitDemo/DemoVC/Sanbox/DoraemonDemoSanboxViewController.m
+49
-0
未找到文件。
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/Util/DoraemonDBManager.h
0 → 100644
浏览文件 @
ac4dbfc9
//
// DoraemonDBManager.h
// DoraemonKit-DoraemonKit
//
// Created by yixiang on 2019/3/30.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface
DoraemonDBManager
:
NSObject
+
(
DoraemonDBManager
*
)
shareManager
;
@property
(
nonatomic
,
copy
)
NSString
*
dbPath
;
@property
(
nonatomic
,
copy
)
NSString
*
tableName
;
-
(
NSArray
*
)
tablesAtDB
;
@end
NS_ASSUME_NONNULL_END
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/Util/DoraemonDBManager.m
0 → 100644
浏览文件 @
ac4dbfc9
//
// DoraemonDBManager.m
// DoraemonKit-DoraemonKit
//
// Created by yixiang on 2019/3/30.
//
#import "DoraemonDBManager.h"
#import <sqlite3.h>
@interface
DoraemonDBManager
()
@end
@implementation
DoraemonDBManager
+
(
DoraemonDBManager
*
)
shareManager
{
static
dispatch_once_t
once
;
static
DoraemonDBManager
*
instance
;
dispatch_once
(
&
once
,
^
{
instance
=
[[
DoraemonDBManager
alloc
]
init
];
});
return
instance
;
}
//打开数据库
-
(
sqlite3
*
)
openDB
{
sqlite3
*
db
=
nil
;
sqlite3_open
([
self
.
dbPath
UTF8String
],
&
db
);
return
db
;
}
//获取指定路径数据库中的数据表
-
(
NSArray
*
)
tablesAtDB
{
sqlite3
*
db
=
[
self
openDB
];
if
(
db
==
nil
)
{
return
nil
;
}
NSMutableArray
*
tableNameArray
=
[
NSMutableArray
array
];
//查询sqlite_master表
NSString
*
sql
=
@"select type, tbl_name from sqlite_master"
;
sqlite3_stmt
*
stmt
=
NULL
;
if
(
sqlite3_prepare_v2
(
db
,
sql
.
UTF8String
,
-
1
,
&
stmt
,
NULL
)
==
SQLITE_OK
)
{
while
(
sqlite3_step
(
stmt
)
==
SQLITE_ROW
)
{
const
unsigned
char
*
type_c
=
sqlite3_column_text
(
stmt
,
0
);
const
unsigned
char
*
tbl_name_c
=
sqlite3_column_text
(
stmt
,
1
);
NSString
*
type
=
[
NSString
stringWithUTF8String
:
type_c
];
NSString
*
tbl_name
=
[
NSString
stringWithUTF8String
:
tbl_name_c
];
if
(
type
&&
[
type
isEqualToString
:
@"table"
])
{
[
tableNameArray
addObject
:
tbl_name
];
}
}
}
return
tableNameArray
;
}
@end
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/VC/DoraemonDBTableViewController.h
0 → 100644
浏览文件 @
ac4dbfc9
//
// DoraemonDBTableViewController.h
// AFNetworking
//
// Created by yixiang on 2019/3/31.
//
#import "DoraemonBaseViewController.h"
NS_ASSUME_NONNULL_BEGIN
@interface
DoraemonDBTableViewController
:
DoraemonBaseViewController
@end
NS_ASSUME_NONNULL_END
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/VC/DoraemonDBTableViewController.m
0 → 100644
浏览文件 @
ac4dbfc9
//
// DoraemonDBTableViewController.m
// AFNetworking
//
// Created by yixiang on 2019/3/31.
//
#import "DoraemonDBTableViewController.h"
#import "DoraemonDBManager.h"
@interface
DoraemonDBTableViewController
()
@end
@implementation
DoraemonDBTableViewController
-
(
void
)
viewDidLoad
{
[
super
viewDidLoad
];
self
.
title
=
[
DoraemonDBManager
shareManager
].
tableName
;
}
@end
iOS/DoraemonKit/Src/Core/Plugin/Sanbox/VC/DoraemonSanboxDetailViewController.m
浏览文件 @
ac4dbfc9
...
...
@@ -12,12 +12,16 @@
#import "UIView+Doraemon.h"
#import "Doraemoni18NUtil.h"
#import <QuickLook/QuickLook.h>
#import "DoraemonDBManager.h"
#import "DoraemonDBTableViewController.h"
@interface
DoraemonSanboxDetailViewController
()
<
QLPreviewControllerDelegate
,
QLPreviewControllerDataSource
>
@interface
DoraemonSanboxDetailViewController
()
<
QLPreviewControllerDelegate
,
QLPreviewControllerDataSource
,
UITableViewDelegate
,
UITableViewDataSource
>
@property
(
nonatomic
,
strong
)
UIImageView
*
imageView
;
@property
(
nonatomic
,
strong
)
UITextView
*
textView
;
@property
(
nonatomic
,
strong
)
AVPlayerViewController
*
playerView
;
@property
(
nonatomic
,
copy
)
NSArray
*
tableNameArray
;
@property
(
nonatomic
,
strong
)
UITableView
*
dbTableNameTableView
;
@end
...
...
@@ -56,8 +60,8 @@
}
else
if
([
path
hasSuffix
:
@".DB"
]
||
[
path
hasSuffix
:
@".db"
]
||
[
path
hasSuffix
:
@".sqlite"
]
||
[
path
hasSuffix
:
@".SQLITE"
]){
//数据库文件
self
.
title
=
DoraemonLocalizedString
(
@"数据库预览"
);
[
self
browseDBTable
];
}
else
{
// 其他文件 尝试使用 QLPreviewController进行打开
QLPreviewController
*
myQlPreViewController
=
[[
QLPreviewController
alloc
]
init
];
...
...
@@ -131,6 +135,43 @@
[
self
.
view
addSubview
:
self
.
playerView
.
view
];
}
//浏览数据库中所有数据表
-
(
void
)
browseDBTable
{
[
DoraemonDBManager
shareManager
].
dbPath
=
self
.
filePath
;
self
.
tableNameArray
=
[[
DoraemonDBManager
shareManager
]
tablesAtDB
];
self
.
dbTableNameTableView
=
[[
UITableView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
self
.
view
.
doraemon_width
,
self
.
view
.
doraemon_height
)
style
:
UITableViewStylePlain
];
self
.
dbTableNameTableView
.
backgroundColor
=
[
UIColor
whiteColor
];
self
.
dbTableNameTableView
.
delegate
=
self
;
self
.
dbTableNameTableView
.
dataSource
=
self
;
[
self
.
view
addSubview
:
self
.
dbTableNameTableView
];
}
#pragma mark - UITableViewDelegate,UITableViewDataSource
-
(
NSInteger
)
tableView
:(
UITableView
*
)
tableView
numberOfRowsInSection
:(
NSInteger
)
section
{
return
self
.
tableNameArray
.
count
;
}
-
(
UITableViewCell
*
)
tableView
:(
UITableView
*
)
tableView
cellForRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
static
NSString
*
identifer
=
@"db_table_name"
;
UITableViewCell
*
cell
=
[
tableView
dequeueReusableCellWithIdentifier
:
identifer
];
if
(
!
cell
)
{
cell
=
[[
UITableViewCell
alloc
]
initWithStyle
:
UITableViewCellStyleDefault
reuseIdentifier
:
identifer
];
}
cell
.
textLabel
.
text
=
self
.
tableNameArray
[
indexPath
.
row
];
return
cell
;
}
-
(
void
)
tableView
:(
UITableView
*
)
tableView
didSelectRowAtIndexPath
:(
NSIndexPath
*
)
indexPath
{
[
tableView
deselectRowAtIndexPath
:
indexPath
animated
:
YES
];
NSString
*
tableName
=
[
self
.
tableNameArray
objectAtIndex
:
indexPath
.
row
];
[
DoraemonDBManager
shareManager
].
tableName
=
tableName
;
DoraemonDBTableViewController
*
vc
=
[[
DoraemonDBTableViewController
alloc
]
init
];
[
self
.
navigationController
pushViewController
:
vc
animated
:
YES
];
}
#pragma mark - QLPreviewControllerDataSource
-
(
NSInteger
)
numberOfPreviewItemsInPreviewController
:(
QLPreviewController
*
)
controller
{
return
1
;
}
...
...
@@ -140,4 +181,5 @@
}
@end
iOS/DoraemonKitDemo/DoraemonKitDemo/DemoVC/Sanbox/DoraemonDemoSanboxViewController.m
浏览文件 @
ac4dbfc9
...
...
@@ -9,6 +9,7 @@
#import "DoraemonDemoSanboxViewController.h"
#import <DoraemonKit/UIView+Doraemon.h>
#import "DoraemonDefine.h"
#import <sqlite3.h>
@interface
DoraemonDemoSanboxViewController
()
...
...
@@ -49,6 +50,12 @@
[
btn4
setTitle
:
@"添加html到沙盒中"
forState
:
UIControlStateNormal
];
[
btn4
addTarget
:
self
action
:
@selector
(
addHtmlFile
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
view
addSubview
:
btn4
];
UIButton
*
btn5
=
[[
UIButton
alloc
]
initWithFrame
:
CGRectMake
(
0
,
btn4
.
doraemon_bottom
+
20
,
self
.
view
.
doraemon_width
,
60
)];
btn5
.
backgroundColor
=
[
UIColor
orangeColor
];
[
btn5
setTitle
:
@"添加DB到沙盒中"
forState
:
UIControlStateNormal
];
[
btn5
addTarget
:
self
action
:
@selector
(
addDBFile
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
self
.
view
addSubview
:
btn5
];
}
-
(
void
)
addFile
{
...
...
@@ -98,6 +105,48 @@
[
self
copyBundleToSanboxWithName
:
@"doraemon"
type
:
@"html"
];
}
-
(
void
)
addDBFile
{
NSString
*
path_document
=
NSHomeDirectory
();
NSString
*
appendingString
=
[
NSString
stringWithFormat
:
@"/Documents/doraemon.db"
];
NSString
*
toPath
=
[
path_document
stringByAppendingString
:
appendingString
];
const
char
*
filename
=
[
toPath
UTF8String
];
sqlite3
*
db
=
nil
;
int
result
=
sqlite3_open
(
filename
,
&
db
);
if
(
result
==
SQLITE_OK
){
NSLog
(
@"打开数据库成功"
);
}
else
{
NSLog
(
@"打开数据库失败"
);
}
//2.创建表
const
char
*
sql
=
"CREATE TABLE IF NOT EXISTS t_students (id integer PRIMARY KEY AUTOINCREMENT,name text NOT NULL,age integer NOT NULL);"
;
char
*
errmsg
=
NULL
;
result
=
sqlite3_exec
(
db
,
sql
,
NULL
,
NULL
,
&
errmsg
);
if
(
result
==
SQLITE_OK
)
{
NSLog
(
@"创表成功"
);
}
else
{
NSLog
(
@"创表失败----%s"
,
errmsg
);
}
//插入数据
for
(
int
i
=
0
;
i
<
20
;
i
++
)
{
//1.拼接SQL语句
NSString
*
name
=
[
NSString
stringWithFormat
:
@"文晓--%d"
,
arc4random_uniform
(
100
)];
int
age
=
arc4random_uniform
(
20
)
+
10
;
NSString
*
sql
=
[
NSString
stringWithFormat
:
@"INSERT INTO t_students (name,age) VALUES ('%@',%d);"
,
name
,
age
];
//2.执行SQL语句
char
*
errmsg
=
NULL
;
sqlite3_exec
(
db
,
sql
.
UTF8String
,
NULL
,
NULL
,
&
errmsg
);
if
(
errmsg
)
{
//如果有错误信息
NSLog
(
@"插入数据失败--%s"
,
errmsg
);
}
else
{
NSLog
(
@"插入数据成功"
);
}
}
}
-
(
void
)
copyBundleToSanboxWithName
:(
NSString
*
)
name
type
:(
NSString
*
)
type
{
NSFileManager
*
fileManage
=
[
NSFileManager
defaultManager
];
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录