swift - SQLite数据库的使用(引用)
SQLite轻量级数据库在移动应用中使用非常普遍,但是目前的库是C编写的,为了方便使用,对SQLite相关的操作用Swift进行了封装。这个封装代码使用了一个开源项目SQLiteDB,地址是:https://github.com/fahimf/sqlitedb
当前,SQLiteDB库已经升级至Swift3
下面通过一个阳历展示SQlite数据库连接,创建表,查询数据,插入数据,删除数据等操作
1、当输入用户名和手机号,点击保存即可将数据存入数据库
2、下次启动,自动从数据库中载入初始化信息
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAWEAAADrCAYAAAC4oyfdAAAKr2lDQ1BJQ0MgUHJvZmlsZQAASImVlwdUU1kax+97L73QEnoLvQlSBAJIDS106WAjJJRQYgwEFFERGVRgLKiIgDqiIyAKjkoRGyKIbRCw1wEZFJRxsCAqKvOAJezsnt09+z/ny/2dL/f+3/du7j3nCwCUBxyhMAWWASBVkC4K9nJjREZFM/D9AAIIIAAmMOFw04SuQUF+ANXs+Hd9vIfORnXbdMrr37//r5LlxaVxAYCCUI7lpXFTUT6NxgWuUJQOAIIG0MlMF05xKcp0EVogysemOGGGW6c4dobvTM8JDWahPAQAgcLhiBIAIH9A84wMbgLqQ6GjbC7g8QUou6PsxE3k8FDOQ3leauqKKT6BsmHsP/kk/M0zVuLJ4SRIeOZdpkVw56cJUzir/8/t+N9KTRHPPkMbDUqiyDsYHRXQPatOXuErYUFsQOAs83nT86c5UewdNsvcNFb0LPM47r6zLE4Oc51ljmhuLT+dHTrLohXBEn9BSoCfxD+OLeG4NI+QWY7ne7JnOSsxNGKWM/jhAbOclhziOzeHJcmLxMGSmuNFnpJ3TE2bq43LmXtWemKo91wNkZJ6eHHuHpK8IEwyX5juJvEUpgTN1Z/iJcmnZYRI1qajB2yWkzg+QXM+QZL9AX6ABdyBKfAHgSAAsEEoOqKr0uNWTZ1pwFohXC3iJySmM1zRWxPHYAu4ZvMYluYWtgBM3cGZn/htxfTdguTH53LZ6BlkGaLJ9rlcxEMAqq4BoLpjLqctD4C8NAA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oRySK3qE+rSsGiIZ9VHbEI8oxbv0oYrZXr+/hMiy1pmK8Q42SFnECgAAUS4AJDpYm8EOjSiYUYfqPBTnYqyHx/s5y1viKyrVZwp1er3vG//cvFiga/qAx4x3Yj7zpOOrAbaXFb/8Df0OdLVnakF8iCQfwKIcP4Z08MeCbznoCOjU8nK/fpo8rBZrIH05/8jcvtOICNwuqQujLfGRX70v1z538siP6Ihar95Qf2+AWt6U0X8V77oyg89pSax/keCQKEJIMKFJk5/uyLQqO6DCbVY1/SR5Qq1aF113Q5qzO8lFVVLVVvv3DK9Z6+DGjVhopueLlxTX/KIPlXXJTKpLoj/uxL//YleLW9+ZUuXbsb7qqqNX/MvBApJQN++JAjsPwIbKpB/cd2Vnh6RH1cL9k+uuFJT4cjklCu/9k2OfH5MhVmt2Hc/plENjzmyoAL8628kN9nSZ3Tnrj6uPOyK/SjQz77PkRWt+1vnt8rr4Rf+afu66W1xDYFcEnBcTblscLdt8deWd0uKcnsi4LsWQnl372nEVIoIgVz/tWUs4YgsPMPMkgDimyUwiodFAJ9wWOTpFwIQgIASQIR5G0AAAhAIkQAiHCJ8uoYABCCACPMegAAEIBAiAUQ4RPh0DQEIQAAR5j0AAQhAIEQCocUJhzhnuoYABCCwbwhgCe+bpWAgEIBAKRJAhEtx1ZkzBCCwbwggwvtmKRgIBCBQigQQ4VJcdeYMAQjsGwKI8L5ZCgYCAQiUIgFEuBRXnTlDAAL7hgAivG+WgoFAAAKlSAARLsVVZ84QgMC+IYAI75ulYCAQgEApEkCES3HVmTMEILBvCCDC+2YpGAgEIFCKBBDhUlx15gwBCOwbAojwvlkKBgIBCJQigf8HmwyvOt87HGMAAAAASUVORK5CYII=" alt="" />
操作步骤:
1)和oc一样,需要在Build Phases -> Link Binary With Libraries中点击加号,添加libsqlite3.0.tdb到项目中来
2)创建连接文件Bridging-Header.h,并导入sqlite3的头文件
3)在项目编译属性引用头文件
4)导入SQLiteDB的代码(SQLiteDB.swift、SQLTable.swift和String-Extras.swift),注意:最好是复制到工程里面,然后add进去,这样的话,不容易报错,不要直接拖!
5)核心代码如下:
import UIKit class ThirtyViewController: UIViewController { var db:SQLiteDB! @IBOutlet weak var telTF: UITextField!
@IBOutlet weak var userTF: UITextField!
@IBOutlet weak var saveClick: UIButton!
@IBOutlet weak var activityClick: UIButton! override func viewDidLoad() {
super.viewDidLoad() //获取数据实例
db = SQLiteDB.sharedInstance //如果表还不存在则创建表(其中uid为自增主键)
let result = db.execute(sql: "create table if not exists t_user(uid integer primary key,uname varchar(20),mobile varchar(20))")
print(result) //如果有数据则加载
initUser() } //点击保存
@IBAction func SaveClick(_ sender: Any) { saveUser() } //从SQLite加载数据
func initUser() {
let data = db.query(sql: "select * from t_user")
if data.count > {
//获取最后一行数据显示
let user = data[data.count - ]
userTF.text = user["uname"] as? String
telTF.text = user["mobile"] as? String } }
//从SQLite删除数据
@IBAction func delegateClick(_ sender: Any) { let data = db.execute(sql: "delete from t_user where uname='Jason1'")
print("data is \(data)") } //保存数据到SQLite
func saveUser() {
let uname = self.userTF.text
let mobile = self.telTF.text //插入数据库,这里用到了esc字符编码函数,其实是调用桥接文件实现的
let sql = "insert into t_user(uname,mobile) values('\(uname)','\(mobile)')" print("sql:\(sql)") //通过封装的方法执行sql
let result = db.execute(sql: sql)
print(result) } }
swift - SQLite数据库的使用(引用)的更多相关文章
- iOS - Swift SQLite 数据库存储
前言 采用 SQLite 数据库来存储数据.SQLite 作为一中小型数据库,应用 iOS 中,跟前三种保存方式相比,相对比较复杂一些. 注意:写入数据库,字符串可以采用 char 方式,而从数据库中 ...
- Android 学习笔记之如何使用SQLite数据库来保存数据...
PS:最近一阵子都在为考试复习...坑爹的计算机网络,复习了3天,最后该不会的还是不会...明天还考英语...真蛋疼... 学习内容: 1.使用SQLite数据库来保存数据... SQLite: ...
- Windows Phone8 中如何引用 SQLite 数据库
SQLite数据库介绍 1.SQLite是一款轻型的嵌入式数据库,使用C++开发,使用非常广泛 2.SQLite是一款跨平台的数据库,支持Windows.Linux.Android.IOS.Windo ...
- Windows Phone8 中如何引用 SQLite 数据库2
本博文编写环境 VS2013 + WP8 SDK 上篇介绍完了SQLite在wp中的部署(具体请参阅 Windows Phone8 中如何引用 SQLite 数据库),下面来看如何使用 SQLite ...
- VS中引用第三方库的方法(配置sqlite数据库)
我们在编写程序时,,不可避免的会使用第三方的库文件,很少使用源文件(.cpp),大部分是使用对类进行声明的头文件和封装了类的链接库(静态lib或动态dll),比如我们写程序用的iostream这个库, ...
- windows phone 8.1开发SQlite数据库引用安装
原文出自:http://www.bcmeng.com/windows-phone-sqlite/ windows phone 8.1开发SQlite数据库引用安装 第一步: 安装SQlite forw ...
- [Swift通天遁地]七、数据与安全-(5)高效操作SQLite数据库
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- SQlite数据库框架:LitePal
常用的数据库框架Android的发展的速度是难以置信的,Android出来哪一年我还在小学上学很,还能很清楚的记得,那年一切,但是那个时候的我怎么可能也不会想到自己将来会要去做Android.Andr ...
- Android之SQLite数据库篇
一.SQLite简介 Google为Andriod的较大的数据处理提供了SQLite,他在数据存储.管理.维护等各方面都相当出色,功能也非常的强大. 二.SQLite的特点 1.轻量级使用 SQLit ...
随机推荐
- SQL数据库异地备份
服务器:windows sever 2008(简称为A) 数据库:SQL server 2008 R2(安装在A上) 普通台式机:windows 7(简称为B) 目的:将A中的数据定时自动备份到B中 ...
- Linux命令-目录处理命令:rm
rm grub.conf 删除当前目录中grub.conf文件 (最好是先复制一个文件,然后再删除,这样保险) rm -f grub.conf 强制删除当前目录中的grub.conf文件 (不需要确认 ...
- C#:XML操作(简单)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.X ...
- 摘:C/C++中时间类time.h
摘要:本文从介绍基础概念入手,探讨了在C/C++中对日期和时间操作所用到的数据结构和函数,并对计时.时间的获取.时间的计算和显示格式等方面进行了阐述.本文还通过大量的实例向你展示了time.h头文件中 ...
- 转 Android Activity之间动画完整版详解
标签:Android Activity动画详解 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://mzh3344258.blog.5 ...
- 交叉编译Node.js到OpenWrt(HG255D)
操作系统:deepin linux 2013 或 ubuntu 13.04 1.安装交叉编译前.须要安装的包 sudo apt-get install build-essential subversi ...
- Object-C支持多继承吗?可以实现多个接口吗?Category是什么?
转自:http://blog.sina.com.cn/s/blog_7afd7d7801016t3t.html Object-C支持多继承吗?可以实现多个接口吗?Category是什么?重写一个类的方 ...
- UIImageView的一些用法
转自:http://blog.sina.com.cn/s/blog_60e2dbcf01014bfm.html //初始化 UIImageView *imageView=[[UIImageView ...
- ural1517后缀数组
题意:求两串字符(0————255)的最长公共字串 思路:先将两个字符链接起来,中间用一个不曾出现过的字符,然后直接求出height数组,然后根据它的特性,求出最长的公共字串,当然这个最长公共字串的坐 ...
- sql 记录
INSERT INTO B([name],[info]) SELECT [name,'10'] FROM A 级联更新1:update tb1, tb2 set tb1.a=tb2.a,tb1.b=t ...