Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

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

Rev 19 Rev 61
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 UserLogDao {
11
class UserLogDao {
-
 
Línea 12... Línea -...
12
    private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
-
 
13
    private var database = Database.sharedInstance
-
 
14
    
-
 
15
    static let sharedInstance: UserLogDao = {
-
 
16
           let instance = UserLogDao()
-
 
17
           
-
 
18
           // setup code
-
 
19
           return instance
-
 
20
    }()
12
    private var database = Environment(\.database).wrappedValue
21
 
13
    private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
22
 
14
    
23
    func selectByUserUuidAndActivityAndAddedOn(userUuid: String, activity : String, addedOn : String)-> UserLogModel {
15
    func selectByUserUuidAndActivityAndAddedOn(userUuid: String, activity : String, addedOn : String)-> UserLogModel {
24
        let db = database.open()
16
        let db = database.open()
Línea 53... Línea 45...
53
                model.activity = String(describing: String(cString: sqlite3_column_text(statement, 6)))
45
                model.activity = String(describing: String(cString: sqlite3_column_text(statement, 6)))
54
                model.addedOn = String(describing: String(cString: sqlite3_column_text(statement, 7)))
46
                model.addedOn = String(describing: String(cString: sqlite3_column_text(statement, 7)))
Línea 55... Línea 47...
55
 
47
 
56
            }
48
            }
57
        } else {
-
 
-
 
49
        } else {
58
            database.printError()
50
           
59
        }
51
        }
60
        sqlite3_finalize(statement)
52
        sqlite3_finalize(statement)
61
        return model
53
        return model
Línea 93... Línea 85...
93
                model.addedOn = String(describing: String(cString: sqlite3_column_text(statement, 7)))
85
                model.addedOn = String(describing: String(cString: sqlite3_column_text(statement, 7)))
Línea 94... Línea 86...
94
 
86
 
95
                records.append(model)
87
                records.append(model)
96
            }
88
            }
97
        } else {
-
 
-
 
89
        } else {
98
            database.printError()
90
           
99
        }
91
        }
100
        sqlite3_finalize(statement)
92
        sqlite3_finalize(statement)
101
        return records
93
        return records
Línea 133... Línea 125...
133
                model.addedOn = String(describing: String(cString: sqlite3_column_text(statement, 7)))
125
                model.addedOn = String(describing: String(cString: sqlite3_column_text(statement, 7)))
Línea 134... Línea 126...
134
 
126
 
135
                records.append(model)
127
                records.append(model)
136
            }
128
            }
137
        } else {
-
 
-
 
129
        } else {
138
            database.printError()
130
           
139
        }
131
        }
140
        sqlite3_finalize(statement)
132
        sqlite3_finalize(statement)
141
        return records
133
        return records
Línea 166... Línea 158...
166
            sqlite3_bind_text(statement, 6, record.activity , -1, SQLITE_TRANSIENT)
158
            sqlite3_bind_text(statement, 6, record.activity , -1, SQLITE_TRANSIENT)
167
            sqlite3_bind_text(statement, 7, record.addedOn , -1, SQLITE_TRANSIENT)
159
            sqlite3_bind_text(statement, 7, record.addedOn , -1, SQLITE_TRANSIENT)
Línea 168... Línea 160...
168
 
160
 
169
            if (sqlite3_step(statement) != SQLITE_DONE) {
161
            if (sqlite3_step(statement) != SQLITE_DONE) {
170
                print("No se pudo insertar un registro en la tabla: \(Constants.TABLE_USER_LOG)")
-
 
-
 
162
                print("No se pudo insertar un registro en la tabla: \(Constants.TABLE_USER_LOG)")
171
                database.printError()
163
               
172
            } else {
164
            } else {
173
                print("Insertamos un registo de log")
-
 
-
 
165
                print("Insertamos un registo de log")
174
                database.printError()
166
               
175
            }
167
            }
176
        } else {
168
        } else {
177
            print("Fallo la preparación en el insertar un registro en la tabla: \(Constants.TABLE_USER_LOG)")
-
 
-
 
169
            print("Fallo la preparación en el insertar un registro en la tabla: \(Constants.TABLE_USER_LOG)")
178
            database.printError()
170
           
Línea 179... Línea 171...
179
        }
171
        }
180
       
172
       
Línea 186... Línea 178...
186
        let query = "DELETE FROM " + Constants.TABLE_USER_LOG + " WHERE " + Constants.TABLE_USER_LOG_FIELD_ID + " = " + "\(id) ;"
178
        let query = "DELETE FROM " + Constants.TABLE_USER_LOG + " WHERE " + Constants.TABLE_USER_LOG_FIELD_ID + " = " + "\(id) ;"
187
        var statement : OpaquePointer? = nil
179
        var statement : OpaquePointer? = nil
188
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
180
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
189
            if sqlite3_step(statement) != SQLITE_DONE {
181
            if sqlite3_step(statement) != SQLITE_DONE {
190
                print("No se pudo borrar el registro con el id: \(id) en la tabla: \(Constants.TABLE_USER_LOG)")
182
                print("No se pudo borrar el registro con el id: \(id) en la tabla: \(Constants.TABLE_USER_LOG)")
191
                database.printError()
-
 
-
 
183
               
192
            }
184
            }
193
        } else {
185
        } else {
194
            print("No se pudo borrar el registro con id: \(id) en la tabla: \(Constants.TABLE_USER_LOG)")
186
            print("No se pudo borrar el registro con id: \(id) en la tabla: \(Constants.TABLE_USER_LOG)")
195
            database.printError()
-
 
-
 
187
           
196
        }
188
        }
197
        sqlite3_finalize(statement)
189
        sqlite3_finalize(statement)
198
    }
190
    }
Línea 199... Línea 191...
199
 
191
 
Línea 202... Línea 194...
202
        let query = "DELETE FROM " + Constants.TABLE_USER_LOG + ";"
194
        let query = "DELETE FROM " + Constants.TABLE_USER_LOG + ";"
203
        var statement : OpaquePointer? = nil
195
        var statement : OpaquePointer? = nil
204
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
196
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
205
            if sqlite3_step(statement) != SQLITE_DONE {
197
            if sqlite3_step(statement) != SQLITE_DONE {
206
                print("No se pudo borrar todos los registros en la tabla: \(Constants.TABLE_USER_LOG)")
198
                print("No se pudo borrar todos los registros en la tabla: \(Constants.TABLE_USER_LOG)")
207
                database.printError()
-
 
-
 
199
               
208
            }
200
            }
209
        } else {
201
        } else {
210
            print("Fallo la preparación de borrar todos los registros en la tabla: \(Constants.TABLE_USER_LOG)")
202
            print("Fallo la preparación de borrar todos los registros en la tabla: \(Constants.TABLE_USER_LOG)")
211
            database.printError()
-
 
-
 
203
           
212
        }
204
        }
213
        sqlite3_finalize(statement)
205
        sqlite3_finalize(statement)
214
    }
206
    }
Línea 215... Línea 207...
215
    
207
    
Línea 221... Línea 213...
221
        var statement : OpaquePointer? = nil
213
        var statement : OpaquePointer? = nil
222
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
214
        if sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK{
223
            if sqlite3_step(statement) != SQLITE_DONE {
215
            if sqlite3_step(statement) != SQLITE_DONE {
224
                print("No se pudo borrar todos los registros en la tabla: \(Constants.TABLE_USER_LOG) " +
216
                print("No se pudo borrar todos los registros en la tabla: \(Constants.TABLE_USER_LOG) " +
225
                        " de usuarios diferents a : \(userUuid) ")
217
                        " de usuarios diferents a : \(userUuid) ")
226
                database.printError()
-
 
-
 
218
               
Línea 227... Línea 219...
227
                
219
                
228
            } else {
220
            } else {
229
                print("Se borraron todos los registros en la tabla: \(Constants.TABLE_USER_LOG) " +
221
                print("Se borraron todos los registros en la tabla: \(Constants.TABLE_USER_LOG) " +
230
                        " de usuarios diferents a : \(userUuid) ")
-
 
-
 
222
                        " de usuarios diferents a : \(userUuid) ")
231
                database.printError()
223
               
232
            }
224
            }
233
        } else {
225
        } else {
234
            print("Fallo la preparación de borrar todos los registros en la tabla: \(Constants.TABLE_USER_LOG) de los usuarios diferentes a : \(userUuid)")
-
 
-
 
226
            print("Fallo la preparación de borrar todos los registros en la tabla: \(Constants.TABLE_USER_LOG) de los usuarios diferentes a : \(userUuid)")
235
            database.printError()
227
           
236
        }
228
        }
237
        sqlite3_finalize(statement)
229
        sqlite3_finalize(statement)