Last active
January 20, 2023 14:06
-
-
Save 1000copy/21ddeb508bae4b803d9c2e97075bb2fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class CellData{ | |
var _str:String | |
var _b : Bool | |
var str:String{get{return _str}set(value){_str = value}} | |
var b : Bool{get{return _b}set(value){ | |
_b = value | |
arr.u(self) | |
}} | |
init(str: String, b: Bool) { | |
self._str = str | |
self._b = b | |
} | |
} | |
// -2 duplicated | |
// -1 append | |
// other index of array | |
func findIndex1(ele : String,arr:[CellData]) -> Int{ | |
var index = 0 | |
for e in arr{ | |
if ele > e.str{ | |
index += 1 | |
}else if ele == e.str{ | |
return -2 | |
}else{ | |
return index | |
} | |
} | |
return -1 | |
} | |
func findEqual(ele : String,arr:[CellData]) -> Int{ | |
var index = 0 | |
for e in arr{ | |
if ele > e.str{ | |
index += 1 | |
}else if ele == e.str{ | |
return index | |
} | |
} | |
return -1 | |
} | |
func hasAlarm(_ arr:[CellData]) -> Bool{ | |
var t = Date.now | |
let formatter = DateFormatter() | |
formatter.dateFormat = "HH:mm" | |
var ele = formatter.string(from: t) | |
for e in arr{ | |
if ele > e.str{ | |
continue | |
}else if ele == e.str{ | |
return e.b | |
}else{ | |
return false | |
} | |
} | |
return false | |
} | |
class Storage{ | |
var arr :[CellData]=[] | |
// CRUD | |
func create(_ d:CellData) -> Int{ | |
let index = findIndex1(ele: d.str,arr:arr) | |
if index == -1 { | |
arr.append(d) | |
s.insert(d.str as NSString , d.b ? 1 : 0) | |
return arr.count - 1 | |
}else if index == -2 { | |
return -2 | |
}else{ | |
arr.insert(d,at:index) | |
s.insert(d.str as NSString , d.b ? 1 : 0) | |
return index | |
} | |
// return index | |
} | |
func r(_ i:Int)->CellData{ | |
return arr[i] | |
} | |
func all()->Void{ | |
var cs = s.query() | |
for c in cs { | |
arr.append(CellData(str : c.str , b: c.b)) | |
} | |
// return arr[i] | |
} | |
func u(_ d:CellData){ | |
let index = findEqual(ele: d.str,arr:arr) | |
if index != -1 { | |
arr[index] = d | |
s.update(d.str as NSString,d.b ? 1 : 0) | |
} | |
} | |
func d(_ i:Int){ | |
s.delete(arr[i].str as NSString) | |
arr.remove(at: i) | |
} | |
func ac(){ | |
arr.removeAll() | |
} | |
var count:Int{return arr.count} | |
// var _sql : Sql | |
// var sql : Sql{get{return _sql}set(value){_sql = value}} | |
} | |
class ASwitch:UISwitch{ | |
// var indexPath:IndexPath? | |
var data : CellData? | |
} | |
var arr1 = [CellData(str:"swift",b:true),CellData(str:"swift",b:true),CellData(str:"swift",b:true)] | |
var s = Sql() | |
var arr : Storage=Storage() | |
class LangTableCustomCell : UITableViewCell{ | |
var mainLabel : UILabel | |
var s:ASwitch | |
var data : CellData | |
required override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | |
s = ASwitch(frame:CGRectMake(110.0, 0.0, 220.0, 15.0)) | |
mainLabel = UILabel(frame:CGRectMake(0.0, 0.0, 110.0, 15.0)) | |
data = CellData(str:"21:36",b:true) | |
// s!.backgroundColor = UIColor.blue | |
// mainLabel!.backgroundColor = UIColor.red | |
super.init(style: style,reuseIdentifier: reuseIdentifier) | |
self.contentView.addSubview(mainLabel) | |
self.contentView.addSubview(s) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) is not supported") | |
} | |
} | |
class LangTable : UITableView,UITableViewDataSource,UITableViewDelegate{ | |
// var a: LangTableCustomCell? | |
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { | |
let deleteAction = UIContextualAction(style: .destructive, | |
title: "Delete") { [weak self] _, _, complete in | |
arr.d(indexPath.row) | |
tableView.deleteRows(at: [indexPath], with: .automatic) | |
complete(true) | |
} | |
deleteAction.backgroundColor = .red | |
return UISwipeActionsConfiguration(actions: [deleteAction]) | |
} | |
// instead of a gesture recognizer you can use this delegate method | |
// it will be called whenever you tap on a cell | |
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
// whatever you gesture recognizer did | |
print("tap") | |
} | |
private func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCell.EditingStyle, forRowAtIndexPath indexPath: IndexPath) { | |
if editingStyle == .delete{ | |
arr.d(indexPath.row) | |
var ips : [IndexPath] = [] | |
ips.append(indexPath) | |
self.beginUpdates() | |
self.deleteRows(at:ips, with: .fade) | |
self.endUpdates() | |
} | |
} | |
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { | |
return true | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let a = LangTableCustomCell(style: UITableViewCell.CellStyle.value1, reuseIdentifier: nil) | |
a.mainLabel.text = arr.r(indexPath.row).str | |
a.s.isOn = arr.r(indexPath.row).b | |
a.s.data = arr.r(indexPath.row) | |
a.data = arr.r(indexPath.row) | |
a.s.addTarget(self, action: #selector(clickme(sender:)), for: .valueChanged) | |
return a | |
} | |
override init(frame: CGRect, style: UITableView.Style) { | |
super.init(frame:frame,style:style) | |
self.dataSource = self | |
self.delegate = self | |
// self.canCancelContentTouches = false | |
} | |
@objc func clickme(sender:ASwitch!){ | |
sender!.data!.b = sender!.isOn | |
print(sender.data!.str,sender.data!.b) | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder:aDecoder) | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return arr.count | |
} | |
} | |
class ViewController1: UIViewController { | |
var t : UIDatePicker | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.view.isOpaque = false | |
self.view.backgroundColor = .white // .clear || try other colors, say: .white or black with | |
let button = UIButton() | |
button.frame = CGRectMake(10,50,50,50) | |
self.view.addSubview(button) | |
button.backgroundColor = UIColor.blue | |
button.setTitle("OK", for: [.normal]) | |
button.addTarget(self, action: #selector(clickme(sender:)), for: .touchDown) | |
let button1 = UIButton() | |
button1.frame = CGRectMake(70,50,80,50) | |
self.view.addSubview(button1) | |
button1.backgroundColor = UIColor.blue | |
button1.setTitle("Cancel", for: [.normal]) | |
button1.addTarget(self, action: #selector(cancel(sender:)), for: .touchDown) | |
t.datePickerMode = .time | |
t.preferredDatePickerStyle = .wheels | |
// t.locale?.hourCycle = .oneToTwentyFour | |
t.locale = Locale(identifier: "en_GB");//oneToTwentyFour | |
t.frame = CGRectMake(10,250,150,150) | |
self.view.addSubview(t) | |
let label = UILabel() | |
label.frame = CGRect(x: 220, y: 150, width: 200, height: 20) | |
label.text = "Minutes" | |
view.addSubview(label) | |
self.view = view | |
let mySegmentedControl = UISegmentedControl (items: ["1","15","30"]) | |
mySegmentedControl.frame = CGRect(x: 10, y: 150, width: 200, height: 20) | |
mySegmentedControl.selectedSegmentIndex = 1 | |
mySegmentedControl.addTarget(self, action: #selector(self.segmentedValueChanged(_:)), for: .valueChanged) | |
self.view.addSubview(mySegmentedControl) | |
} | |
required init?(coder: NSCoder) { | |
fatalError("init(coder:) is not supported") | |
} | |
init() { | |
answer = "undefined" | |
t = UIDatePicker() | |
super.init(nibName: nil, bundle: nil) | |
} | |
@objc func segmentedValueChanged(_ sender:UISegmentedControl!) | |
{ | |
// print("Selected Segment Index is : \(sender.selectedSegmentIndex)") | |
if sender.selectedSegmentIndex == 0 { | |
self.t.minuteInterval = 1 | |
}else if sender.selectedSegmentIndex == 1 { | |
self.t.minuteInterval = 15 | |
}else if sender.selectedSegmentIndex == 2 { | |
self.t.minuteInterval = 30 | |
} | |
// The interval value must be evenly divided into 60; if it isn’t, the default value is used. The default and minimum values are 1; the maximum value is 30. | |
// self.t.minuteInterval = 60 | |
} | |
@objc | |
func clickme(sender:UIButton!){ | |
// answer = "OK" | |
let formatter = DateFormatter() | |
formatter.dateFormat = "HH:mm" | |
// 更新 UILabel 的內容 | |
var r = formatter.string( | |
from: t.date) | |
authorizationCompletionBlock!(r) | |
self.dismiss(animated: true) | |
} | |
@objc | |
func cancel(sender:UIButton!){ | |
// answer = "Cancel" | |
authorizationCompletionBlock!("") | |
self.dismiss(animated: true) | |
} | |
var answer : String | |
var authorizationCompletionBlock:((String)->())? = {_ in} | |
} | |
func requestPermission() { | |
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { success, error in | |
if success { | |
print("All set!") | |
} else if let error = error { | |
print(error.localizedDescription) | |
} | |
} | |
} | |
class vc2 : UIViewController{ | |
required init?(coder: NSCoder) { | |
super.init(coder: coder) | |
} | |
init() { | |
super.init(nibName: nil, bundle: nil) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let button = UIButton() | |
button.frame = CGRectMake(10,50,50,50) | |
self.view.addSubview(button) | |
button.backgroundColor = UIColor.blue | |
button.setTitle("+", for: [.normal]) | |
//button.addTarget(self, action: Selector("clickme:"), for: .touchDown) | |
button.addTarget(self, action: #selector(r(sender:)), for: .touchDown) | |
playSound() | |
let mainLabel = UILabel(frame:CGRectMake(50, 150.0, 110.0, 15.0)) | |
mainLabel.text = "alarm" | |
self.view.addSubview(mainLabel) | |
self.view.isOpaque = false | |
self.view.backgroundColor = .white // .clear || try other colors, say: .white or black with | |
} | |
@objc func r(sender:UIButton!){ | |
// self.isEditing = true | |
player?.stop() | |
self.dismiss(animated: true) | |
} | |
} | |
class ViewController: UIViewController { | |
var a :LangTable | |
required init?(coder: NSCoder) { | |
a = LangTable() | |
let _ = s.openDatabase() | |
s.createTable() | |
arr.all() | |
super.init(coder: coder) | |
} | |
// init() { | |
// a = LangTable() | |
// super.init(nibName: nil, bundle: nil) | |
// } | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// self.userNotificationCenter.delegate = self | |
// requestPermission() | |
//withTimeInterval is counting by second | |
Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { (_) in | |
let date = Date() | |
let df = DateFormatter() | |
df.dateFormat = "HH:mm" | |
let dateString = df.string(from: date) | |
print(dateString) | |
if hasAlarm(arr.arr){ | |
arr.u(CellData(str:dateString,b:false)) | |
self.a.reloadData() | |
if UIApplication.shared.applicationState == .active { | |
self.present(vc2(),animated: true) | |
}else{ | |
// make notify | |
print("make notify") | |
let content = UNMutableNotificationContent() | |
content.title = "alarm" | |
content.subtitle = "time" | |
content.body = "body" | |
content.badge = 1 | |
content.sound = UNNotificationSound.default | |
// let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0, repeats: false) | |
let request = UNNotificationRequest(identifier: "notification", content: content, trigger: nil) | |
UNUserNotificationCenter.current().add(request, withCompletionHandler: {error in | |
print("成功建立通知...") | |
}) | |
} | |
} | |
print(UIApplication.shared.applicationState == .active ) | |
} | |
// arr.create(CellData(str:"21:36",b:true)) | |
//button | |
let button = UIButton() | |
button.frame = CGRectMake(10,50,50,50) | |
self.view.addSubview(button) | |
button.backgroundColor = UIColor.blue | |
button.setTitle("+", for: [.normal]) | |
//button.addTarget(self, action: Selector("clickme:"), for: .touchDown) | |
button.addTarget(self, action: #selector(clickme(sender:)), for: .touchDown) | |
//button1 | |
let button1 = UIButton() | |
button1.frame = CGRectMake(70,50,50,50) | |
self.view.addSubview(button1) | |
button1.backgroundColor = UIColor.blue | |
button1.setTitle("AC", for: [.normal]) | |
//button.addTarget(self, action: Selector("clickme:"), for: .touchDown) | |
button1.addTarget(self, action: #selector(ac(sender:)), for: .touchDown) | |
// button2 | |
let button2 = UIButton() | |
button2.frame = CGRectMake(130,50,50,50) | |
self.view.addSubview(button2) | |
button2.backgroundColor = UIColor.blue | |
button2.setTitle("+...", for: [.normal]) | |
//button.addTarget(self, action: Selector("clickme:"), for: .touchDown) | |
button2.addTarget(self, action: #selector(clickme1(sender:)), for: .touchDown) | |
let button3 = UIButton() | |
button3.frame = CGRectMake(190,50,50,50) | |
self.view.addSubview(button3) | |
button3.backgroundColor = UIColor.blue | |
button3.setTitle("-", for: [.normal]) | |
//button.addTarget(self, action: Selector("clickme:"), for: .touchDown) | |
button3.addTarget(self, action: #selector(r(sender:)), for: .touchDown) | |
a.frame = CGRectMake(0,100,200,1050) | |
self.view.addSubview(a) | |
let button4 = UIButton() | |
button4.frame = CGRectMake(250,50,50,50) | |
self.view.addSubview(button4) | |
button4.backgroundColor = UIColor.blue | |
button4.setTitle("P", for: [.normal]) | |
//button.addTarget(self, action: Selector("clickme:"), for: .touchDown) | |
button4.addTarget(self, action: #selector(r4(sender:)), for: .touchDown) | |
} | |
override func setEditing(_ editing: Bool, animated: Bool) { | |
super.setEditing(editing, animated: animated) | |
self.a.setEditing(editing, animated: animated) | |
} | |
@objc | |
func r(sender:UIButton!){ | |
// self.isEditing = true | |
print("r") | |
a.setEditing(true, animated: true) | |
} | |
@objc | |
func clickme(sender:UIButton!){ | |
// arr.create(CellData(str:"5",b:true)) | |
// print("4") | |
// self.a.reloadData() | |
// let alert = UIAlertController(title: "Hi", message: "I am message", preferredStyle:.alert) | |
// // Closure | |
// alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in | |
// print("OK") | |
// })) | |
// alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler:abcd)) | |
// present(alert, animated: true, completion: nil) | |
} | |
@objc | |
func clickme1(sender:UIButton!){ | |
// popover? | |
let popover = ViewController1() | |
// popover.modalPresentationStyle = .overCurrentContext | |
popover.authorizationCompletionBlock = { str in | |
let index1 = arr.create(CellData(str:str,b:true)) | |
if(index1 == -2){ | |
let alert = UIAlertController(title: "dupicated", message: "alarm exists already!", preferredStyle:.actionSheet) | |
// Closure | |
// alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action: UIAlertAction!) in | |
//// print("OK") | |
// })) | |
// åalert.addAction(UIAlertAction(title: "Cancel", style: .default, handler:abcd)) | |
popover.present(alert, animated: true, completion: nil) | |
return | |
} | |
self.a.beginUpdates() | |
self.a.insertRows(at: [IndexPath(row: index1, section: 0)], with: .automatic) | |
self.a.endUpdates() | |
// self.a.reloadData() | |
} | |
present(popover,animated: true,completion:{ () -> Void in | |
// print(popover.answer) | |
print("exit") | |
}) | |
} | |
func abcd(action: UIAlertAction!) { | |
print("Cancel") | |
} | |
@objc | |
func ac(sender:UIButton!){ | |
arr.ac() | |
self.a.reloadData() | |
} | |
@objc | |
func r4(sender:UIButton!){ | |
playSound() | |
// do { | |
// if let fileURL = Bundle.main.path(forResource: "office_phone-ring_medium-loudaif-14604", ofType: "mp3") { | |
// let ap = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileURL)) | |
// ap.delegate = self as? AVAudioPlayerDelegate | |
// ap.numberOfLoops = -1 | |
// ap.volume = 1 | |
// ap.prepareToPlay() | |
// ap.play() | |
// } else { | |
// print("No file with specified name exists") | |
// } | |
// } catch let error { | |
// print("Can't play the audio file failed with an error \(error.localizedDescription)") | |
// } | |
} | |
} | |
import AVFoundation | |
var player: AVAudioPlayer? | |
func playSound() { | |
guard let url = Bundle.main.url(forResource: "office_phone-ring_medium-loudaif-14604", withExtension: "mp3") else { return } | |
do { | |
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) | |
try AVAudioSession.sharedInstance().setActive(true) | |
/* The following line is required for the player to work on iOS 11. Change the file type accordingly*/ | |
player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue) | |
/* iOS 10 and earlier require the following line: | |
player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileTypeMPEGLayer3) */ | |
guard let player = player else { return } | |
player.play() | |
} catch let error { | |
print(error.localizedDescription) | |
} | |
} | |
struct Cell{ | |
var str : String; | |
var b : Bool | |
} | |
import SQLite3 | |
class Sql{ | |
var part1DbPath : String?="db2" | |
var db: OpaquePointer? | |
func openDatabase() -> OpaquePointer? { | |
let path = NSSearchPathForDirectoriesInDomains( | |
.documentDirectory, .userDomainMask, true | |
).first! | |
part1DbPath = "\(path)/\(part1DbPath)" | |
guard let part1DbPath = part1DbPath else { | |
print("part1DbPath is nil.") | |
return nil | |
} | |
if sqlite3_open(part1DbPath, &db) == SQLITE_OK { | |
print("Successfully opened connection to database at \(part1DbPath)") | |
return db | |
} else { | |
print("Unable to open database.") | |
let errorMessage = String(cString: sqlite3_errmsg(db)) | |
print("\nQuery is not prepared! \(errorMessage)") | |
return nil | |
} | |
} | |
let createTableString = """ | |
CREATE TABLE alarm( | |
str CHAR(255), | |
b int); | |
""" | |
func createTable() { | |
// 1 | |
var createTableStatement: OpaquePointer? | |
// 2 | |
if sqlite3_prepare_v2(db, createTableString, -1, &createTableStatement, nil) == | |
SQLITE_OK { | |
// 3 | |
if sqlite3_step(createTableStatement) == SQLITE_DONE { | |
print("alarm table created.") | |
deleteAll() | |
} else { | |
print("alarm table is not created.") | |
} | |
} else { | |
print("\nCREATE TABLE statement is not prepared.") | |
} | |
// 4 | |
sqlite3_finalize(createTableStatement) | |
} | |
let insertStatementString = "INSERT INTO alarm (str, b) VALUES (?, ?);" | |
func insert(_ p1 : NSString,_ p2 : Int32) { | |
print("insert ",p2,p1) | |
var insertStatement: OpaquePointer? | |
// 1 | |
if sqlite3_prepare_v2(db, insertStatementString, -1, &insertStatement, nil) == | |
SQLITE_OK { | |
sqlite3_bind_int(insertStatement, 2, p2) | |
sqlite3_bind_text(insertStatement, 1, p1.utf8String, -1, nil) | |
if sqlite3_step(insertStatement) == SQLITE_DONE { | |
print("\nSuccessfully inserted row.") | |
} else { | |
print("\nCould not insert row.") | |
} | |
} else { | |
print("\nINSERT statement is not prepared.") | |
} | |
// 5 | |
sqlite3_finalize(insertStatement) | |
} | |
func q1() -> Void{ | |
let cells = query() | |
for cell in cells{ | |
print("\(cell.str) | \(cell.b)") | |
} | |
} | |
let queryStatementString = "SELECT * FROM alarm;" | |
func query() -> [Cell] { | |
var r : [Cell] = [] | |
var queryStatement: OpaquePointer? | |
// 1 | |
if sqlite3_prepare_v2(db, queryStatementString, -1, &queryStatement, nil) == | |
SQLITE_OK { | |
print("\nQuery Result:") | |
while sqlite3_step(queryStatement) == SQLITE_ROW { | |
// 3 | |
let b = sqlite3_column_int(queryStatement, 1) | |
// 4 | |
guard let queryResultCol1 = sqlite3_column_text(queryStatement, 0) else { | |
print("Query result is nil") | |
return [] | |
} | |
let str = String(cString: queryResultCol1) | |
r.append(Cell(str: str, b: b == 1)) | |
// print("\(str) | \(b)") | |
} | |
} else { | |
// 6 | |
let errorMessage = String(cString: sqlite3_errmsg(db)) | |
print("\nQuery is not prepared \(errorMessage)") | |
} | |
// 7 | |
sqlite3_finalize(queryStatement) | |
return r | |
} | |
let updateStatementString = "UPDATE alarm SET b = ? WHERE str = ?;" | |
func update(_ p1 : NSString,_ p2 : Int32) { | |
var updateStatement: OpaquePointer? | |
if sqlite3_prepare_v2(db, updateStatementString, -1, &updateStatement, nil) == | |
SQLITE_OK { | |
sqlite3_bind_int(updateStatement, 1, p2) | |
sqlite3_bind_text(updateStatement, 2, p1.utf8String, -1, nil) | |
if sqlite3_step(updateStatement) == SQLITE_DONE { | |
print("\nSuccessfully updated row.") | |
} else { | |
print("\nCould not update row.") | |
} | |
} else { | |
print("\nUPDATE statement is not prepared") | |
} | |
sqlite3_finalize(updateStatement) | |
} | |
let deleteStatementString = "DELETE FROM alarm WHERE str = ?;" | |
func delete(_ p1 : NSString) { | |
var deleteStatement: OpaquePointer? | |
if sqlite3_prepare_v2(db, deleteStatementString, -1, &deleteStatement, nil) == | |
SQLITE_OK { | |
sqlite3_bind_text(deleteStatement, 1, p1.utf8String, -1, nil) | |
if sqlite3_step(deleteStatement) == SQLITE_DONE { | |
print("\nSuccessfully deleted row.") | |
} else { | |
print("\nCould not delete row.") | |
} | |
} else { | |
print("\nDELETE statement could not be prepared") | |
} | |
sqlite3_finalize(deleteStatement) | |
} | |
let deleteAllString = "DELETE FROM alarm;" | |
func deleteAll() { | |
var deleteStatement: OpaquePointer? | |
if sqlite3_prepare_v2(db, deleteAllString, -1, &deleteStatement, nil) == | |
SQLITE_OK { | |
if sqlite3_step(deleteStatement) == SQLITE_DONE { | |
print("\nSuccessfully deleted all row.") | |
} else { | |
print("\nCould not delete row.") | |
} | |
} else { | |
print("\nDELETE statement could not be prepared") | |
} | |
sqlite3_finalize(deleteStatement) | |
} | |
let malformedQueryString = "SELECT Stuff from Things WHERE Whatever;" | |
func prepareMalformedQuery() { | |
var malformedStatement: OpaquePointer? | |
// 1 | |
if sqlite3_prepare_v2(db, malformedQueryString, -1, &malformedStatement, nil) | |
== SQLITE_OK { | |
print("\nThis should not have happened.") | |
} else { | |
// 2 | |
let errorMessage = String(cString: sqlite3_errmsg(db)) | |
print("\nQuery is not prepared! \(errorMessage)") | |
} | |
// 3 | |
sqlite3_finalize(malformedStatement) | |
} | |
} | |
//var s = Sql() | |
//let db = s.openDatabase() | |
//s.createTable() | |
//s.insert("21:36",1) | |
//s.insert("22:36",1) | |
//s.q1() | |
//s.update("21:36",0) | |
//s.q1() | |
// | |
//s.delete("21:36") | |
//s.deleteAll() | |
//s.prepareMalformedQuery() | |
////s.query() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment