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 4... Línea 4...
4
//
4
//
5
//  Created by Efrain Yanez Recanatini on 7/31/22.
5
//  Created by Efrain Yanez Recanatini on 7/31/22.
6
//
6
//
Línea 7... Línea 7...
7
 
7
 
8
 
8
 
Línea 9... Línea 9...
9
import UIKit
9
import SwiftUI
-
 
10
import SQLite3
10
import SQLite3
11
 
11
 
-
 
12
class UserNotificationDao {
12
class UserNotificationDao {
13
    private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
13
    private var database = Environment(\.database).wrappedValue
14
    public var db : OpaquePointer?
-
 
-
 
14
    private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
15
    
15
 
Línea 16... Línea 16...
16
    func selectById(id : Int)-> UserNotificationModel {
16
    func selectById(id : Int)-> UserNotificationModel {
17
        
17
        let db = database.open()
18
        var model = UserNotificationModel ()
18
        var model = UserNotificationModel ()
Línea 65... Línea 65...
65
        sqlite3_finalize(statement)
65
        sqlite3_finalize(statement)
66
        return model
66
        return model
67
    }
67
    }
Línea 68... Línea 68...
68
    
68
    
69
    func selectAllDistinctDateByUserUuid(userUuid : String) -> [String] {
-
 
-
 
69
    func selectAllDistinctDateByUserUuid(userUuid : String) -> [String] {
70
        
70
        let db = database.open()
Línea 71... Línea 71...
71
        var records = [String]()
71
        var records = [String]()
72
        
72
        
73
        var query = "SELECT "
73
        var query = "SELECT "
Línea 94... Línea 94...
94
        return records
94
        return records
95
    }
95
    }
Línea 96... Línea 96...
96
 
96
 
97
 
-
 
-
 
97
 
98
    func selectAllByUserUuidAndDate(userUuid : String, date : String)-> [UserNotificationModel] {
98
    func selectAllByUserUuidAndDate(userUuid : String, date : String)-> [UserNotificationModel] {
Línea 99... Línea 99...
99
        
99
        let db = database.open()
100
        var records = [UserNotificationModel]()
100
        var records = [UserNotificationModel]()
101
        
101
        
Línea 151... Línea 151...
151
        sqlite3_finalize(statement)
151
        sqlite3_finalize(statement)
152
        return records
152
        return records
153
    }
153
    }
Línea 154... Línea 154...
154
    
154
    
155
    func selectAllByUserUuid(userUuid : String)-> [UserNotificationModel] {
-
 
-
 
155
    func selectAllByUserUuid(userUuid : String)-> [UserNotificationModel] {
156
        
156
        let db = database.open()
Línea 157... Línea 157...
157
        var records = [UserNotificationModel]()
157
        var records = [UserNotificationModel]()
158
        
158
        
159
        var query = "SELECT "
159
        var query = "SELECT "
Línea 211... Línea 211...
211
    
211
    
212
 
-
 
-
 
212
 
213
    
213
    
214
    
214
    
Línea 215... Línea 215...
215
    func getCountByUserUuid(userUuid : String) -> Int {
215
    func getCountByUserUuid(userUuid : String) -> Int {
216
        
216
        let db = database.open()
Línea 233... Línea 233...
233
        sqlite3_finalize(statement)
233
        sqlite3_finalize(statement)
234
        return count
234
        return count
235
    }
235
    }
Línea 236... Línea 236...
236
    
236
    
237
    func insert(userNotification : UserNotificationModel) -> Int {
-
 
-
 
237
    func insert(userNotification : UserNotificationModel) -> Int {
238
        
238
        let db = database.open()
239
        var result : Int = 0
239
        var result : Int = 0
240
        var query = "INSERT INTO " + Constants.TABLE_USER_NOTIFICATION + " ( "
240
        var query = "INSERT INTO " + Constants.TABLE_USER_NOTIFICATION + " ( "
241
        query = query + Constants.TABLE_USER_NOTIFICATION_FIELD_USER_UUID + ", "
241
        query = query + Constants.TABLE_USER_NOTIFICATION_FIELD_USER_UUID + ", "
242
        query = query + Constants.TABLE_USER_NOTIFICATION_FIELD_TITLE + ", "
242
        query = query + Constants.TABLE_USER_NOTIFICATION_FIELD_TITLE + ", "
Línea 260... Línea 260...
260
            sqlite3_bind_text(statement, 6, userNotification.command, -1, SQLITE_TRANSIENT)
260
            sqlite3_bind_text(statement, 6, userNotification.command, -1, SQLITE_TRANSIENT)
261
            sqlite3_bind_text(statement, 7, userNotification.dateOn, -1, SQLITE_TRANSIENT)
261
            sqlite3_bind_text(statement, 7, userNotification.dateOn, -1, SQLITE_TRANSIENT)
262
            sqlite3_bind_text(statement, 8, userNotification.timeOn , -1, SQLITE_TRANSIENT)
262
            sqlite3_bind_text(statement, 8, userNotification.timeOn , -1, SQLITE_TRANSIENT)
Línea 263... Línea 263...
263
            
263
            
264
            if (sqlite3_step(statement) == SQLITE_DONE) {
264
            if (sqlite3_step(statement) == SQLITE_DONE) {
265
                result = Int(sqlite3_last_insert_rowid(conn))
265
                result = Int(sqlite3_last_insert_rowid(db))
266
            } else {
266
            } else {
Línea 279... Línea 279...
279
        
279
        
280
        return result
280
        return result
Línea 281... Línea 281...
281
    }
281
    }
282
 
-
 
-
 
282
 
283
    func markViewed(id : Int) {
283
    func markViewed(id : Int) {
284
        
284
        let db = database.open()
285
        var query = "UPDATE " + Constants.TABLE_USER_NOTIFICATION
285
        var query = "UPDATE " + Constants.TABLE_USER_NOTIFICATION
286
        query = query + " SET " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + "  1 "
286
        query = query + " SET " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + "  1 "
287
        query = query + " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_ID + " = '\(id)';"
287
        query = query + " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_ID + " = '\(id)';"
Línea 299... Línea 299...
299
        }
299
        }
300
        sqlite3_finalize(statement)
300
        sqlite3_finalize(statement)
301
    }
301
    }
Línea 302... Línea 302...
302
    
302
    
303
    func markViewedAllPendingByUserUuid(userUuid : String) {
-
 
-
 
303
    func markViewedAllPendingByUserUuid(userUuid : String) {
304
        
304
        let db = database.open()
305
        var query = "UPDATE " + Constants.TABLE_USER_NOTIFICATION
305
        var query = "UPDATE " + Constants.TABLE_USER_NOTIFICATION
306
        query = query + " SET " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + "  1 "
306
        query = query + " SET " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + "  1 "
307
        query = query + " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + " = 0 "
307
        query = query + " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + " = 0 "
308
        query = query + " AND " + Constants.TABLE_USER_NOTIFICATION_FIELD_USER_UUID + " = '\(userUuid)'; "
308
        query = query + " AND " + Constants.TABLE_USER_NOTIFICATION_FIELD_USER_UUID + " = '\(userUuid)'; "
Línea 320... Línea 320...
320
        }
320
        }
321
        sqlite3_finalize(statement)
321
        sqlite3_finalize(statement)
322
    }
322
    }
Línea 323... Línea 323...
323
    
323
    
324
    func markViewedAllPendingByUserUuidAndCommand(userUuid : String, command : String) {
-
 
-
 
324
    func markViewedAllPendingByUserUuidAndCommand(userUuid : String, command : String) {
325
        
325
        let db = database.open()
326
        var query = "UPDATE " + Constants.TABLE_USER_NOTIFICATION
326
        var query = "UPDATE " + Constants.TABLE_USER_NOTIFICATION
327
        query = query + " SET " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + " = 1 "
327
        query = query + " SET " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + " = 1 "
328
        query = query + " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + " = 0 "
328
        query = query + " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_VIEWED + " = 0 "
329
        query = query + " AND " + Constants.TABLE_USER_NOTIFICATION_FIELD_USER_UUID + " = '\(userUuid)'; "
329
        query = query + " AND " + Constants.TABLE_USER_NOTIFICATION_FIELD_USER_UUID + " = '\(userUuid)'; "
Línea 344... Línea 344...
344
    }
344
    }
Línea 345... Línea 345...
345
    
345
    
346
    
346
    
-
 
347
    func removeExpired(userUuid : String)
347
    func removeExpired(userUuid : String)
348
    {
348
    {
349
        let db = database.open()
Línea 349... Línea 350...
349
        let now = Date()
350
        let now = Date()
Línea 376... Línea 377...
376
        
377
        
Línea 377... Línea 378...
377
        
378
        
378
    }
-
 
-
 
379
    }
379
 
380
 
380
    func remove(id: Int) {
381
    func remove(id: Int) {
381
        
382
        let db = database.open()
382
        let query = "DELETE FROM " + Constants.TABLE_USER_NOTIFICATION
383
        let query = "DELETE FROM " + Constants.TABLE_USER_NOTIFICATION
383
            + " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_ID + " = '\(id)' ;"
384
            + " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_ID + " = '\(id)' ;"
Línea 398... Línea 399...
398
 
399
 
399
    
400
    
400
    
-
 
-
 
401
    
401
    func removeAllUserUuidNotEqual(userUuid : String)
402
    func removeAllUserUuidNotEqual(userUuid : String)
402
    {
403
    {
403
        
404
        let db = database.open()
404
        let query = "DELETE FROM " +  Constants.TABLE_USER_NOTIFICATION +
405
        let query = "DELETE FROM " +  Constants.TABLE_USER_NOTIFICATION +
405
            " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_USER_UUID + " <> '\(userUuid)' ;"
406
            " WHERE " + Constants.TABLE_USER_NOTIFICATION_FIELD_USER_UUID + " <> '\(userUuid)' ;"