private PcdbFile(string path, PcdbGameVersion gameVersion) { FileName = path; database = new SQLiteDatabase(FileName); database.BeginTransaction(); { database.ExecuteNonQuery(new[] {"PRAGMA encoding = 'UTF-8'", "PRAGMA foreign_keys = ON"}); switch (gameVersion) { case PcdbGameVersion.Unknown: database.RollBackTransaction(); database.Close(); throw new NotSupportedException("Unknown game version."); case PcdbGameVersion.SHOC: database.RollBackTransaction(); database.Close(); throw new NotSupportedException("S.T.A.L.K.E.R.: Shadow of Chernobyl is not supported."); case PcdbGameVersion.CS: database.ExecuteNonQuery(new[] { "CREATE TABLE DBVERSION (VERSION INTEGER UNSIGNED NOT NULL)", "INSERT INTO DBVERSION VALUES ('" + (int)SupportedRevision + "')", "CREATE TABLE DBTYPE (TYPEID TINYINT UNSIGNED NOT NULL)", "INSERT INTO DBTYPE VALUES ('2')", "CREATE TABLE HASHES (HASH CHAR(32) NOT NULL PRIMARY KEY, INFO TINYTEXT NULL)", "CREATE TABLE NAMES (HASH CHAR(32) NOT NULL, NAME TINYTEXT NOT NULL, " + "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " + "PRIMARY KEY (HASH, NAME))", "CREATE TABLE IPS (HASH CHAR(32) NOT NULL, IP TINYTEXT NOT NULL, " + "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " + "PRIMARY KEY (HASH, IP))" }); break; case PcdbGameVersion.COP: database.ExecuteNonQuery(new[] { "CREATE TABLE DBVERSION (VERSION INTEGER UNSIGNED NOT NULL)", "INSERT INTO DBVERSION VALUES ('" + (int)SupportedRevision + "')", "CREATE TABLE DBTYPE (TYPEID TINYINT UNSIGNED NOT NULL)", "INSERT INTO DBTYPE VALUES ('3')", "CREATE TABLE HASHES (HASH CHAR(32) NOT NULL PRIMARY KEY, INFO TINYTEXT NULL)", "CREATE TABLE NAMES (HASH CHAR(32) NOT NULL, NAME TINYTEXT NOT NULL, " + "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " + "PRIMARY KEY (HASH, NAME))", "CREATE TABLE IPS (HASH CHAR(32) NOT NULL, IP TINYTEXT NOT NULL, " + "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " + "PRIMARY KEY (HASH, IP))", "CREATE TABLE GSIDS (HASH CHAR(32) NOT NULL, GSID INT UNSIGNED NOT NULL, " + "DATEINFO TIMESTAMP NULL, FOREIGN KEY (HASH) REFERENCES HASHES(HASH), " + "PRIMARY KEY (HASH, GSID))" }); break; } } database.CommitTransaction(); database.Close(); Revision = (int)SupportedRevision; }
public int PropagationHorizonDeleteAll(ELEVATIONMODEL model) { System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model); lock (db.DBCommand) { db.DBCommand.CommandText = "DELETE FROM " + PropagationHorizonDesignator.TableName; db.DBCommand.Parameters.Clear(); return(db.ExecuteNonQuery(db.DBCommand)); } }
public int PropagationHorizonDelete(PropagationHorizonDesignator hor, ELEVATIONMODEL model) { System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model); lock (db.DBCommand) { db.DBCommand.CommandText = "DELETE FROM " + PropagationHorizonDesignator.TableName + " WHERE Lat = @Lat AND Lon = @Lon AND h = @h AND Dist = @Dist AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth"; db.DBCommand.Parameters.Clear(); db.DBCommand.Parameters.Add(hor.AsDouble("Lat")); db.DBCommand.Parameters.Add(hor.AsDouble("Lon")); db.DBCommand.Parameters.Add(hor.AsDouble("h")); db.DBCommand.Parameters.Add(hor.AsDouble("Dist")); db.DBCommand.Parameters.Add(hor.AsDouble("QRG")); db.DBCommand.Parameters.Add(hor.AsDouble("Radius")); db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance")); db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth")); return(db.ExecuteNonQuery(db.DBCommand)); } }
public int PropagationHorizonUpdate(PropagationHorizonDesignator hor, ELEVATIONMODEL model) { System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model); lock (db.DBCommand) { db.DBCommand.CommandText = "UPDATE " + PropagationHorizonDesignator.TableName + " SET Lat = @Lat, Lon = @Lon, h = @h, Dist = @Dist, QRG = @QRG, Radius = @Radius, F1_Clearance = @F1_Clearance, @StepWidth = @StepWidth, Horizon = @Horizon, LastUpdated = @LastUpdated WHERE Lat = @Lat AND Lon = @Lon AND h = @h AND Dist = @Dist AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth"; db.DBCommand.Parameters.Clear(); db.DBCommand.Parameters.Add(hor.AsDouble("Lat")); db.DBCommand.Parameters.Add(hor.AsDouble("Lon")); db.DBCommand.Parameters.Add(hor.AsDouble("h")); db.DBCommand.Parameters.Add(hor.AsDouble("Dist")); db.DBCommand.Parameters.Add(hor.AsDouble("QRG")); db.DBCommand.Parameters.Add(hor.AsDouble("Radius")); db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance")); db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth")); db.DBCommand.Parameters.Add(hor.AsBinary("Horizon")); db.DBCommand.Parameters.Add(hor.AsUNIXTime("LastUpdated")); return(db.ExecuteNonQuery(db.DBCommand)); } }
public int PropagationHorizonInsert(PropagationHorizonDesignator hor, ELEVATIONMODEL model) { System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model); lock (db.DBCommand) { db.DBCommand.CommandText = "INSERT INTO " + PropagationHorizonDesignator.TableName + " (Lat, Lon, h, Dist, QRG, Radius, F1_Clearance, StepWidth, Horizon, LastUpdated) VALUES (@Lat, @Lon, @h, @Dist, @QRG, @Radius, @F1_Clearance, @StepWidth, @Horizon, @LastUpdated)"; db.DBCommand.Parameters.Clear(); db.DBCommand.Parameters.Add(hor.AsDouble("Lat")); db.DBCommand.Parameters.Add(hor.AsDouble("Lon")); db.DBCommand.Parameters.Add(hor.AsDouble("h")); db.DBCommand.Parameters.Add(hor.AsDouble("Dist")); db.DBCommand.Parameters.Add(hor.AsDouble("QRG")); db.DBCommand.Parameters.Add(hor.AsDouble("Radius")); db.DBCommand.Parameters.Add(hor.AsDouble("F1_Clearance")); db.DBCommand.Parameters.Add(hor.AsDouble("StepWidth")); db.DBCommand.Parameters.Add(hor.AsBinary("Horizon")); db.DBCommand.Parameters.Add(hor.AsUNIXTime("LastUpdated")); return(db.ExecuteNonQuery(db.DBCommand)); } }
public int PropagationPathDelete(PropagationPathDesignator path, ELEVATIONMODEL model) { System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model); lock (db.DBCommand) { db.DBCommand.CommandText = "DELETE FROM " + PropagationPathDesignator.TableName + " WHERE Lat1 = @Lat1 AND Lon1 = @Lon1 AND h1 = @h1 AND Lat2 = @Lat2 AND Lon2 = @Lon2 AND h2 = @h2 AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth"; db.DBCommand.Parameters.Clear(); db.DBCommand.Parameters.Add(path.AsDouble("Lat1")); db.DBCommand.Parameters.Add(path.AsDouble("Lon1")); db.DBCommand.Parameters.Add(path.AsDouble("h1")); db.DBCommand.Parameters.Add(path.AsDouble("Lat2")); db.DBCommand.Parameters.Add(path.AsDouble("Lon2")); db.DBCommand.Parameters.Add(path.AsDouble("h2")); db.DBCommand.Parameters.Add(path.AsDouble("QRG")); db.DBCommand.Parameters.Add(path.AsDouble("Radius")); db.DBCommand.Parameters.Add(path.AsDouble("F1_Clearance")); db.DBCommand.Parameters.Add(path.AsDouble("StepWidth")); return(db.ExecuteNonQuery(db.DBCommand)); } }
public int PropagationPathUpdate(PropagationPathDesignator path, ELEVATIONMODEL model) { System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model); lock (db.DBCommand) { db.DBCommand.CommandText = "UPDATE " + PropagationPathDesignator.TableName + " SET Lat1 = @Lat1, Lon1 = @Lon1, h1 = @h1, Lat2 = @Lat2, Lon2 = @Lon2, h2 = @h2, QRG = @QRG, Radius = @Radius, F1_Clearance = @F1_Clearance, @StepWidth = @StepWidth, Eps1_Min = @Eps1_Min, Eps2_Min = @Eps2_Min, LastUpdated = @LastUpdated WHERE Lat1 = @Lat1 AND Lon1 = @Lon1 AND h1 = @h1 AND Lat2 = @Lat2 AND Lon2 = @Lon2 AND h2 = @h2 AND QRG = @QRG AND Radius = @Radius AND F1_Clearance = @F1_Clearance AND StepWidth = @StepWidth"; db.DBCommand.Parameters.Clear(); db.DBCommand.Parameters.Add(path.AsDouble("Lat1")); db.DBCommand.Parameters.Add(path.AsDouble("Lon1")); db.DBCommand.Parameters.Add(path.AsDouble("h1")); db.DBCommand.Parameters.Add(path.AsDouble("Lat2")); db.DBCommand.Parameters.Add(path.AsDouble("Lon2")); db.DBCommand.Parameters.Add(path.AsDouble("h2")); db.DBCommand.Parameters.Add(path.AsDouble("QRG")); db.DBCommand.Parameters.Add(path.AsDouble("Radius")); db.DBCommand.Parameters.Add(path.AsDouble("F1_Clearance")); db.DBCommand.Parameters.Add(path.AsDouble("StepWidth")); db.DBCommand.Parameters.Add(path.AsDouble("Eps1_Min")); db.DBCommand.Parameters.Add(path.AsDouble("Eps2_Min")); db.DBCommand.Parameters.Add(path.AsUNIXTime("LastUpdated")); return(db.ExecuteNonQuery(db.DBCommand)); } }
public int PropagationPathInsert(PropagationPathDesignator path, ELEVATIONMODEL model) { System.Data.SQLite.SQLiteDatabase db = GetPropagationDatabase(model); lock (db.DBCommand) { db.DBCommand.CommandText = "INSERT INTO " + PropagationPathDesignator.TableName + " (Lat1, Lon1, h1, Lat2, Lon2, h2, QRG, Radius, F1_Clearance, StepWidth, Eps1_Min, Eps2_Min, LastUpdated) VALUES (@Lat1, @Lon1, @h1, @Lat2, @Lon2, @h2, @QRG, @Radius, @F1_Clearance, @StepWidth, @Eps1_Min, @Eps2_Min, @LastUpdated)"; db.DBCommand.Parameters.Clear(); db.DBCommand.Parameters.Add(path.AsDouble("Lat1")); db.DBCommand.Parameters.Add(path.AsDouble("Lon1")); db.DBCommand.Parameters.Add(path.AsDouble("h1")); db.DBCommand.Parameters.Add(path.AsDouble("Lat2")); db.DBCommand.Parameters.Add(path.AsDouble("Lon2")); db.DBCommand.Parameters.Add(path.AsDouble("h2")); db.DBCommand.Parameters.Add(path.AsDouble("QRG")); db.DBCommand.Parameters.Add(path.AsDouble("Radius")); db.DBCommand.Parameters.Add(path.AsDouble("F1_Clearance")); db.DBCommand.Parameters.Add(path.AsDouble("StepWidth")); db.DBCommand.Parameters.Add(path.AsDouble("Eps1_Min")); db.DBCommand.Parameters.Add(path.AsDouble("Eps2_Min")); db.DBCommand.Parameters.Add(path.AsUNIXTime("LastUpdated")); return(db.ExecuteNonQuery(db.DBCommand)); } }