I've already created sqlite tables for my app, but now I want to add a new column in table to the database. ALTER TABLE will help me in this problem but first i want to check the database version. i am using PRAGMA user_version to check the user version and update the user_version but it always returning user_version as 0.
var database: FMDatabase? = nil
class func getInstance() -> ModelManager{
if(sharedInstance.database == nil){
sharedInstance.database = FMDatabase(path: Util.getPath("XXXX.sqlite"))
}
return sharedInstance
}
func userVersion(){
sharedInstance.database!.open()
var userVer = Int()
let resultSet = sharedInstance.database?.executeQuery("pragma user_version", withArgumentsInArray: nil)
userVer = Int(resultSet!.intForColumn("user_version"))
print("user version : ",userVer)
sharedInstance.database!.close()
}
func updateUserVersion(){
sharedInstance.database!.open()
sharedInstance.database?.executeUpdate("PRAGMA user_version=1", withArgumentsInArray: nil)
sharedInstance.database!.close()
}
Aucun commentaire:
Enregistrer un commentaire