Proyectos de Subversion Iphone Microlearning - Inconcert

Rev

Rev 16 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 16 Rev 17
Línea 3... Línea 3...
3
//  twogetskills
3
//  twogetskills
4
//
4
//
5
//  Created by Efrain Yanez Recanatini on 2/21/22.
5
//  Created by Efrain Yanez Recanatini on 2/21/22.
6
//
6
//
Línea 7... Línea 7...
7
 
7
 
8
import UIKit
8
import SwiftUI
Línea 9... Línea 9...
9
import SQLite3
9
import SQLite3
-
 
10
 
10
 
11
class SlideDao {
11
class SlideDao {
-
 
12
    private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
12
    private var database = Environment(\.database).wrappedValue
13
    public var db : OpaquePointer?
13
    private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
14
    
-
 
-
 
14
 
15
    func getCountByCapsuleUuid(capsuleUuid: String) -> Int {
15
    func getCountByCapsuleUuid(capsuleUuid: String) -> Int {
16
        
16
        let db = database.open()
Línea 17... Línea 17...
17
        let query = "SELECT COUNT(*) AS total FROM " + Constants.TABLE_SLIDE +
17
        let query = "SELECT COUNT(*) AS total FROM " + Constants.TABLE_SLIDE +
18
            " WHERE " + Constants.TABLE_SLIDE_FIELD_CAPSULE_UUID + " = '\(capsuleUuid)'  ;"
18
            " WHERE " + Constants.TABLE_SLIDE_FIELD_CAPSULE_UUID + " = '\(capsuleUuid)'  ;"
Línea 32... Línea 32...
32
        sqlite3_finalize(statement)
32
        sqlite3_finalize(statement)
33
        return count
33
        return count
34
    }
34
    }
Línea 35... Línea 35...
35
 
35
 
36
    func getCountByTopicUuid(topicUuid: String) -> Int {
-
 
-
 
36
    func getCountByTopicUuid(topicUuid: String) -> Int {
37
        
37
        let db = database.open()
38
        let query = "SELECT COUNT(*) AS total FROM " + Constants.TABLE_SLIDE +
38
        let query = "SELECT COUNT(*) AS total FROM " + Constants.TABLE_SLIDE +
Línea 39... Línea 39...
39
            " WHERE " + Constants.TABLE_SLIDE_FIELD_TOPIC_UUID + " = '\(topicUuid)' ;"
39
            " WHERE " + Constants.TABLE_SLIDE_FIELD_TOPIC_UUID + " = '\(topicUuid)' ;"
40
 
40
 
Línea 53... Línea 53...
53
        sqlite3_finalize(statement)
53
        sqlite3_finalize(statement)
54
        return count
54
        return count
55
    }
55
    }
Línea 56... Línea 56...
56
 
56
 
57
    func selectAllByCapsuleUuid(capsuleUuid: String)-> [SlideModel] {
-
 
-
 
57
    func selectAllByCapsuleUuid(capsuleUuid: String)-> [SlideModel] {
58
        
58
        let db = database.open()
Línea 59... Línea 59...
59
        var records = [SlideModel]()
59
        var records = [SlideModel]()
60
        
60
        
61
        var query = "SELECT " + Constants.TABLE_SLIDE_FIELD_UUID
61
        var query = "SELECT " + Constants.TABLE_SLIDE_FIELD_UUID
Línea 100... Línea 100...
100
        return records
100
        return records
101
    }
101
    }
Línea 102... Línea 102...
102
    
102
    
103
 
-
 
-
 
103
 
104
    func selectByUuid(uuid: String)-> SlideModel {
104
    func selectByUuid(uuid: String)-> SlideModel {
105
        
105
        let db = database.open()
106
        var model = SlideModel()
106
        var model = SlideModel()
107
        var query = "SELECT " + Constants.TABLE_SLIDE_FIELD_UUID
107
        var query = "SELECT " + Constants.TABLE_SLIDE_FIELD_UUID
108
        query = query + ", " + Constants.TABLE_SLIDE_FIELD_TOPIC_UUID
108
        query = query + ", " + Constants.TABLE_SLIDE_FIELD_TOPIC_UUID
Línea 141... Línea 141...
141
        sqlite3_finalize(statement)
141
        sqlite3_finalize(statement)
142
        return model
142
        return model
143
    }
143
    }
Línea 144... Línea 144...
144
        
144
        
145
    func insert(slide : SlideModel) {
-
 
-
 
145
    func insert(slide : SlideModel) {
146
        
146
        let db = database.open()
147
        var query = "INSERT INTO " + Constants.TABLE_SLIDE + " ( "
147
        var query = "INSERT INTO " + Constants.TABLE_SLIDE + " ( "
148
        query = query + Constants.TABLE_SLIDE_FIELD_UUID + ", "
148
        query = query + Constants.TABLE_SLIDE_FIELD_UUID + ", "
149
        query = query + Constants.TABLE_SLIDE_FIELD_TOPIC_UUID + ", "
149
        query = query + Constants.TABLE_SLIDE_FIELD_TOPIC_UUID + ", "
150
        query = query + Constants.TABLE_SLIDE_FIELD_CAPSULE_UUID + ", "
150
        query = query + Constants.TABLE_SLIDE_FIELD_CAPSULE_UUID + ", "
Línea 188... Línea 188...
188
       
188
       
189
        sqlite3_finalize(statement)
189
        sqlite3_finalize(statement)
Línea 190... Línea 190...
190
    }
190
    }
191
 
-
 
-
 
191
 
192
    func update(slide: SlideModel) {
192
    func update(slide: SlideModel) {
193
        
193
        let db = database.open()
194
        var query = "UPDATE " + Constants.TABLE_SLIDE
194
        var query = "UPDATE " + Constants.TABLE_SLIDE
195
        query = query + " SET " + Constants.TABLE_SLIDE_FIELD_QUIZ_UUID + " = '\(slide.quizUuid)', "
195
        query = query + " SET " + Constants.TABLE_SLIDE_FIELD_QUIZ_UUID + " = '\(slide.quizUuid)', "
196
        query = query + Constants.TABLE_SLIDE_FIELD_NAME + " = '\(slide.name)', "
196
        query = query + Constants.TABLE_SLIDE_FIELD_NAME + " = '\(slide.name)', "
Línea 214... Línea 214...
214
        }
214
        }
215
        sqlite3_finalize(statement)
215
        sqlite3_finalize(statement)
216
    }
216
    }
Línea 217... Línea 217...
217
 
217
 
218
    func remove(uuid: String) {
-
 
-
 
218
    func remove(uuid: String) {
219
        
219
        let db = database.open()
220
        let query = "DELETE FROM " + Constants.TABLE_SLIDE +
220
        let query = "DELETE FROM " + Constants.TABLE_SLIDE +
221
            " WHERE " + Constants.TABLE_SLIDE_FIELD_UUID + " = '\(uuid)' ;"
221
            " WHERE " + Constants.TABLE_SLIDE_FIELD_UUID + " = '\(uuid)' ;"
222
        var statement : OpaquePointer? = nil
222
        var statement : OpaquePointer? = nil
223
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
223
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
Línea 231... Línea 231...
231
        }
231
        }
232
        sqlite3_finalize(statement)
232
        sqlite3_finalize(statement)
233
    }
233
    }
Línea 234... Línea 234...
234
 
234
 
235
    func removeAll() {
-
 
-
 
235
    func removeAll() {
236
        
236
        let db = database.open()
237
        let query = "DELETE FROM " + Constants.TABLE_SLIDE + ";"
237
        let query = "DELETE FROM " + Constants.TABLE_SLIDE + ";"
238
        var statement : OpaquePointer? = nil
238
        var statement : OpaquePointer? = nil
239
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
239
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
240
            if sqlite3_step(statement) != SQLITE_DONE {
240
            if sqlite3_step(statement) != SQLITE_DONE {