[chronojump/optional_foreign_keys] Adds more referential integrity relations in the sqlite database.



commit f9668dc904dfd3637dda634c44d221c3f61e1411
Author: Carles Pina i Estany <carles pina cat>
Date:   Sun Aug 21 15:35:55 2016 +0200

    Adds more referential integrity relations in the sqlite database.
    
    So far is only for just created databases.

 src/sqlite/encoder.cs      |   10 ++++++++--
 src/sqlite/jump.cs         |    3 ++-
 src/sqlite/jumpRj.cs       |    4 +++-
 src/sqlite/pulse.cs        |    3 ++-
 src/sqlite/reactionTime.cs |    3 ++-
 src/sqlite/run.cs          |    4 +++-
 src/sqlite/runInterval.cs  |    4 +++-
 src/sqlite/server.cs       |    3 ++-
 src/sqlite/speciallity.cs  |    3 ++-
 9 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index a413dce..090e974 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -61,7 +61,11 @@ class SqliteEncoder : Sqlite
                        "future1 TEXT, " +      //Since 1.4.4 (DB 1.06) this stores last meanPower detected 
on a curve 
                                                //(as string with '.' because future1 was created as TEXT)
                        "future2 TEXT, " + 
-                       "future3 TEXT )";
+                       "future3 TEXT, " +
+                       "FOREIGN KEY (exerciseID) REFERENCES Encoder1RM(exerciseID), " +
+                       "FOREIGN KEY (personID) REFERENCES Person77(uniqueID), " +
+                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID), " +
+                       "FOREIGN KEY (exerciseID) REFERENCES EncoderExercise(uniqueID))";
                dbcmd.ExecuteNonQuery();
        }
        
@@ -889,7 +893,9 @@ class SqliteEncoder : Sqlite
                        "load1RM FLOAT, " +
                        "future1 TEXT, " +      
                        "future2 TEXT, " +
-                       "future3 TEXT )";
+                       "future3 TEXT, " +
+                       "FOREIGN KEY (personID) REFERENCES Person77(uniqueID), " +
+                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID))";
                dbcmd.ExecuteNonQuery();
        }
        
diff --git a/src/sqlite/jump.cs b/src/sqlite/jump.cs
index 8f8e2af..4154bc7 100644
--- a/src/sqlite/jump.cs
+++ b/src/sqlite/jump.cs
@@ -56,7 +56,8 @@ class SqliteJump : Sqlite
                                                //positive numbers represent the serverUniqueID
                                                //the simulated has two purposes, but it's logical because 
                                                //only real tests can be uploaded
-                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID))";
+                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID), " +
+                       "FOREIGN KEY (type) REFERENCES JumpType(name))";
                dbcmd.ExecuteNonQuery();
        }
        
diff --git a/src/sqlite/jumpRj.cs b/src/sqlite/jumpRj.cs
index 62d43ef..33ec354 100644
--- a/src/sqlite/jumpRj.cs
+++ b/src/sqlite/jumpRj.cs
@@ -55,7 +55,9 @@ class SqliteJumpRj : SqliteJump
                        "limited TEXT, " + //for RJ, "11J" or "11S" (11 Jumps, 11 seconds)
                        "angleString TEXT, " + //"-1" if undef
                        "simulated INT, " +
-                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID))";
+                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID), " + 
+                       "FOREIGN KEY (type) REFERENCES JumpRjType(name), " +
+                       "FOREIGN KEY (personID) REFERENCES Person77(uniqueID))";
                dbcmd.ExecuteNonQuery();
        }
 
diff --git a/src/sqlite/pulse.cs b/src/sqlite/pulse.cs
index ab866c3..574757a 100644
--- a/src/sqlite/pulse.cs
+++ b/src/sqlite/pulse.cs
@@ -49,7 +49,8 @@ class SqlitePulse : Sqlite
                        "timeString TEXT, " +
                        "description TEXT, " +
                        "simulated INT, " +
-                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID))";
+                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID), " +
+                       "FOREIGN KEY (type) REFERENCES PulseType(name))";
                dbcmd.ExecuteNonQuery();
        }
        
diff --git a/src/sqlite/reactionTime.cs b/src/sqlite/reactionTime.cs
index 337fa2b..0e4652b 100644
--- a/src/sqlite/reactionTime.cs
+++ b/src/sqlite/reactionTime.cs
@@ -47,7 +47,8 @@ class SqliteReactionTime : Sqlite
                        "time FLOAT, " +
                        "description TEXT, " +
                        "simulated INT, " +
-                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID))";
+                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID), " + 
+                       "FOREIGN KEY (personID) REFERENCES Person77(uniqueID))";
                dbcmd.ExecuteNonQuery();
        }
        
diff --git a/src/sqlite/run.cs b/src/sqlite/run.cs
index b5060f9..89b607b 100644
--- a/src/sqlite/run.cs
+++ b/src/sqlite/run.cs
@@ -49,7 +49,9 @@ class SqliteRun : Sqlite
                        "description TEXT, " +
                        "simulated INT, " +
                        "initialSpeed INT, " +
-                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID))";
+                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID), " +
+                       "FOREIGN KEY (type) REFERENCES RunType(name), " +
+                       "FOREIGN KEY (personId) REFERENCES Person77(uniqueID))";
                dbcmd.ExecuteNonQuery();
        }
        
diff --git a/src/sqlite/runInterval.cs b/src/sqlite/runInterval.cs
index 79b3775..9ce97dd 100644
--- a/src/sqlite/runInterval.cs
+++ b/src/sqlite/runInterval.cs
@@ -51,7 +51,9 @@ class SqliteRunInterval : SqliteRun
                        "limited TEXT, " +
                        "simulated INT, " +
                        "initialSpeed INT, " +
-                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID))";
+                       "FOREIGN KEY (sessionID) REFERENCES Session(uniqueID), " +
+                       "FOREIGN KEY (personID) REFERENCES Person77(uniqueID), " + 
+                       "FOREIGN KEY (type) REFERENCES RunIntervalType(name))";
                dbcmd.ExecuteNonQuery();
        }
 
diff --git a/src/sqlite/server.cs b/src/sqlite/server.cs
index 744d984..2b98e7a 100644
--- a/src/sqlite/server.cs
+++ b/src/sqlite/server.cs
@@ -59,7 +59,8 @@ class SqliteServer : Sqlite
                        "chronometer TEXT, " +
                        "device TEXT, " +
                        "comments TEXT, " +
-                       "confiable INT ) "; //bool
+                       "confiable INT, " + // bool
+                       "FOREIGN KEY (countryID) REFERENCES Country(uniqueID)) ";
                dbcmd.ExecuteNonQuery();
         }
 
diff --git a/src/sqlite/speciallity.cs b/src/sqlite/speciallity.cs
index f2c9b78..b8aa5c8 100644
--- a/src/sqlite/speciallity.cs
+++ b/src/sqlite/speciallity.cs
@@ -36,7 +36,8 @@ class SqliteSpeciallity : Sqlite
                        "CREATE TABLE " + Constants.SpeciallityTable + " ( " +
                        "uniqueID INTEGER PRIMARY KEY, " +
                        "sportID INT, " +
-                       "name TEXT )";
+                       "name TEXT, " +
+                       "FOREIGN KEY (sportId) REFERENCES Sport(uniqueID))";
                dbcmd.ExecuteNonQuery();
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]