Proyectos de Subversion Iphone Microlearning - Nuevo Interface

Rev

Rev 19 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 19 Rev 61
Línea 4... Línea 4...
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
 
8
 
Línea 9... Línea 9...
9
import UIKit
9
import SwiftUI
-
 
10
import SQLite3
10
import SQLite3
11
 
11
 
-
 
12
class SyncDao {
-
 
13
    private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
-
 
14
    private var database = Database.sharedInstance
-
 
15
    
-
 
16
    static let sharedInstance: SyncDao = {
-
 
17
           let instance = SyncDao()
-
 
18
           
-
 
Línea 19... Línea 12...
19
           // setup code
12
class SyncDao {
20
           return instance
13
    private var database = Environment(\.database).wrappedValue
21
    }()
14
    private let SQLITE_TRANSIENT = unsafeBitCast(-1, to: sqlite3_destructor_type.self)
22
 
15
 
Línea 33... Línea 26...
33
            sqlite3_bind_text(statement, 2, record.data , -1, SQLITE_TRANSIENT)
26
            sqlite3_bind_text(statement, 2, record.data , -1, SQLITE_TRANSIENT)
34
           if (sqlite3_step(statement) == SQLITE_DONE) {
27
           if (sqlite3_step(statement) == SQLITE_DONE) {
35
               result = Int(sqlite3_last_insert_rowid(db))
28
               result = Int(sqlite3_last_insert_rowid(db))
36
           } else {
29
           } else {
37
                print("No se pudo insertar el registro ( type: \(record.type) data: \(record.data)   en la tabla: \(Constants.TABLE_SYNC)")
30
                print("No se pudo insertar el registro ( type: \(record.type) data: \(record.data)   en la tabla: \(Constants.TABLE_SYNC)")
38
                database.printError()
-
 
-
 
31
               
Línea 39... Línea 32...
39
            
32
            
Línea 40... Línea 33...
40
           }
33
           }
41
           
34
           
42
        } else {
-
 
-
 
35
        } else {
43
            print("Fallo la preparación del insert en la tabla: \(Constants.TABLE_SYNC)")
36
            print("Fallo la preparación del insert en la tabla: \(Constants.TABLE_SYNC)")
Línea 44... Línea 37...
44
            database.printError()
37
           
45
        }
38
        }
46
        
39
        
Línea 66... Línea 59...
66
                record.type = Int(sqlite3_column_int(statement, 1))
59
                record.type = Int(sqlite3_column_int(statement, 1))
67
                record.data = String(describing: String(cString: sqlite3_column_text(statement, 2)))
60
                record.data = String(describing: String(cString: sqlite3_column_text(statement, 2)))
Línea 68... Línea 61...
68
                
61
                
69
            }
62
            }
70
        } else {
-
 
-
 
63
        } else {
71
            database.printError()
64
           
72
        }
65
        }
73
        sqlite3_finalize(statement)
66
        sqlite3_finalize(statement)
74
        return record
67
        return record
Línea 85... Línea 78...
85
        if (sqlite3_prepare(db, query, -1, &statement, nil) == SQLITE_OK) {
78
        if (sqlite3_prepare(db, query, -1, &statement, nil) == SQLITE_OK) {
86
            if(sqlite3_step(statement) == SQLITE_ROW){
79
            if(sqlite3_step(statement) == SQLITE_ROW){
87
                count = Int(sqlite3_column_int(statement, 0))
80
                count = Int(sqlite3_column_int(statement, 0))
88
            }
81
            }
89
        } else {
82
        } else {
90
            database.printError()
-
 
-
 
83
           
91
        }
84
        }
92
        sqlite3_finalize(statement)
85
        sqlite3_finalize(statement)
93
        return count
86
        return count
94
    }
87
    }
Línea 115... Línea 108...
115
                model.data = String(describing: String(cString: sqlite3_column_text(statement, 2)))
108
                model.data = String(describing: String(cString: sqlite3_column_text(statement, 2)))
Línea 116... Línea 109...
116
                
109
                
117
                records.append(model)
110
                records.append(model)
118
            }
111
            }
119
        } else {
-
 
-
 
112
        } else {
120
            database.printError()
113
           
121
        }
114
        }
122
        sqlite3_finalize(statement)
115
        sqlite3_finalize(statement)
123
        return records
116
        return records
Línea 128... Línea 121...
128
        let query = "DELETE FROM " + Constants.TABLE_SYNC + " WHERE " + Constants.TABLE_SYNC_FIELD_ID + " = " + "\(id) ;"
121
        let query = "DELETE FROM " + Constants.TABLE_SYNC + " WHERE " + Constants.TABLE_SYNC_FIELD_ID + " = " + "\(id) ;"
129
        var statement : OpaquePointer? = nil
122
        var statement : OpaquePointer? = nil
130
        if (sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK) {
123
        if (sqlite3_prepare_v2(db, query, -1, &statement, nil) == SQLITE_OK) {
131
            if (sqlite3_step(statement) != SQLITE_DONE) {
124
            if (sqlite3_step(statement) != SQLITE_DONE) {
132
                print("No se pudo borrar el ID: \(id) de la tabla: \(Constants.TABLE_SYNC)")
125
                print("No se pudo borrar el ID: \(id) de la tabla: \(Constants.TABLE_SYNC)")
133
                database.printError()
-
 
-
 
126
               
134
            } 
127
            } 
135
        } else {
128
        } else {
136
            database.printError()
-
 
-
 
129
           
137
        }
130
        }
138
        sqlite3_finalize(statement)
131
        sqlite3_finalize(statement)
139
    }
132
    }
140
}
133
}