Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // SecondViewController.swift
- // shoppingList
- //
- // Created by Connor O'NEILL (001029853) on 15/11/2017.
- // Copyright © 2017 Connor O'NEILL (001029853). All rights reserved.
- //
- import UIKit
- class SecondViewController: UIViewController {
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- if sqlite3_open(getDBPath(), &db) == SQLITE_OK
- }
- var db: COpaquePointer = nil
- func getDBPath() ->String{
- let paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
- let documentsDir = paths[0]
- let databasePath = (documentsDir as NSString).stringByAppendingPathComponent("shoppingListDB.db")
- return databasePath;
- }
- var shoppingArray:[shoppingList] = []
- func selectQuery(){
- let selectQueryStatement = "SELECT * FROM shoppingList"
- var queryStatement: COpaquePointer = nil
- if (sqlite3_prepare_v2(db,selectQueryStatement, -1, &queryStatement, nil) == SQLITE_OK){
- print("Query result:")
- while (sqlite3_step(queryStatement) == SQLITE_ROW) {
- let itemField = sqlite3_column_text(queryStatement, 0)
- let item = String.fromCString(UnsafePointer<CChar>(itemField))!
- let price = sqlite3_column_double(queryStatement, 1)
- let groupField = sqlite3_column_text(queryStatement, 2)
- let group = String.fromCString(UnsafePointer<CChar>(groupField))
- let quantity = sqlite3_column_int(queryStatement, 3)
- print("\(item)")
- let s = shoppingList(item: item, price: price, group: group!, quantity: quantity)
- shoppingArray.append(s)
- }
- }
- else{
- print("SELECT statement no worky")
- }
- sqlite3_finalize(queryStatement)
- sqlite3_close(db)
- }
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- // Dispose of any resources that can be recreated.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement