首先说明:如果你进入了这篇文章,证明你应该会sql语句了,以下就是简单的 增删查
![](https://img.haomeiwen.com/i1254409/2d9695c350dafe23.gif)
-
1 创建的代码
64234D5F-386A-4191-B4AC-2C701EA688E4.png
功能代码实现(查询-删除-更新)
@IBOutlet weak var height: UITextField!
@IBOutlet weak var name: UITextField!
@IBOutlet weak var pid: UITextField!
//添加
@IBAction func add(sender: AnyObject) {
CommonFunction.ExecuteUpdate("insert into T_Person (pid ,name, height) values (?, ?, ?) ", ["1" as AnyObject,"2" as AnyObject,"3" as AnyObject]) { (isOk) in
if(isOk){
CommonFunction.HUD("成功", type: MsgType.success)
}
else{
CommonFunction.HUD("失败", type: MsgType.error)
}
}
}
//条件查询
@IBAction func selecta(sender: AnyObject) {
CommonFunction.ExecuteQuery("select * from T_Person where pid = (?) ", [1 as AnyObject]) { (Result) in
CommonFunction.HUD("查询成功", type: MsgType.success)
while Result.next() {
let pid:Int32 = Result.int(forColumn: "pid") as Int32
let name:String = Result.string(forColumn: "name") as String
let height:Double = Result.double(forColumn: "height") as Double
print("pid:\(pid),name:\(name)","height:\(height)");
}
}
}
//全部查询
@IBAction func readall(sender: AnyObject) {
CommonFunction.ExecuteQuery("select * from T_Person ", nil) { (Result) in
CommonFunction.HUD("查询成功", type: MsgType.success)
while Result.next() {
let pid:Int32 = Result.int(forColumn: "pid") as Int32
let name:String = Result.string(forColumn: "name") as String
let height:Double = Result.double(forColumn: "height") as Double
print("pid:\(pid),name:\(name)","height:\(height)");
}
}
}
//全部删除
@IBAction func alldel(sender: AnyObject) {
CommonFunction.ExecuteUpdate("delete from T_Person ", nil) { (isOk) in
if(isOk){
CommonFunction.HUD("成功", type: MsgType.success)
}
else{
CommonFunction.HUD("失败", type: MsgType.error)
}
}
}
如需代码,请移动到--->http://www.jianshu.com/p/0f950c180cb8
网友评论