/// <summary> /// delete tables of old versions and recreate it /// </summary> public void VerDbVersions() { //to do - a version table for VERSIONDB too? for the insert of new tables _ = RunSqliteCommand("create table if not exists VERSIONDB (Key integer, USER integer,BOOK integer);"); // DbVersions dbVersions; using (SqliteDataReader Retorno = Task.Run(async() => await RunSqliteCommand("select USER,BOOK from VERSIONDB")).Result) { _ = Retorno.Read(); if (Retorno.HasRows) { dbVersions = new DbVersions() { USER = Retorno.GetWithNullableInt(0), BOOK = Retorno.GetWithNullableInt(1) }; } else { dbVersions = new DbVersions() { USER = 0, BOOK = 0 }; AddorUpdateVersionDb(false, dbVersions); } } bool updateVersionDb = false; if ((dbVersions.BOOK < ActualDbVersions.BOOK) || (dbVersions.USER < ActualDbVersions.USER)) { _ = RunSqliteCommand("drop table if exists USER"); updateVersionDb = true; } if (dbVersions.BOOK < ActualDbVersions.BOOK) { _ = RunSqliteCommand("drop table if exists BOOK"); _ = RunSqliteCommand("drop table if exists BOOKRATING"); updateVersionDb = true; } if (updateVersionDb) { AddorUpdateVersionDb(true, ActualDbVersions); } }
private void AddorUpdateVersionDb(bool isUpdate, DbVersions dbVersions) { string command; if (!isUpdate) { command = "insert into Versiondb(key,USER,BOOK) values ('1',@USER,@BOOK)"; } else { command = "update Versiondb set USER = @USER,BOOK = @BOOK where key = '1'"; } List <SqliteParameter> parameters = new List <SqliteParameter>() { new SqliteParameter("@USER", dbVersions.USER), new SqliteParameter("@BOOK", dbVersions.BOOK) }; _ = RunSqliteCommand(command, parameters); }