· 9 years ago · Nov 14, 2016, 07:50 AM
1String CreateMovieTable = "Create Table IF NOT EXISTS Movie (MID Integer PRIMARY KEY, Title Text, Genre Text, Director Text, IMBDRating Text, MPAARating Text, Plot Text)";
2 SQLiteCommand command = new SQLiteCommand( CreateMovieTable, sqlConnection );
3 command.ExecuteNonQuery();
4
5 String CreateActorTable = "Create Table IF NOT EXISTS Actors( AID Integer PRIMARY KEY, Name Text)";
6 command = new SQLiteCommand( CreateActorTable, sqlConnection );
7 command.ExecuteNonQuery();
8
9 String CreateStarsInTable = "Create Table IF NOT EXISTS StarsIn (MID Integer, AID INTEGER, FOREIGN KEY(MID) REFERENCES Movie(MID), FOREIGN KEY(AID) REFERENCES Actors(AID), PRIMARY KEY( MID, AID ) )";
10 command = new SQLiteCommand( CreateStarsInTable, sqlConnection );
11 command.ExecuteNonQuery();
12
13 String CreateStrServiceTable = "Create Table IF NOT EXISTS StreamingService ( Name Text PRIMARY KEY, URL Text, Price TEXT )";
14 command = new SQLiteCommand( CreateStrServiceTable, sqlConnection );
15 command.ExecuteNonQuery();
16
17 String CreateStreamsOnTable = "Create Table IF NOT EXISTS StreamsOn ( MID Integer, Name Text, FOREIGN KEY(MID) REFERENCES Movie(Mid), FOREIGN KEY(Name) REFERENCES StreamingService(Name), PRIMARY KEY( MID, Name ))";
18 command = new SQLiteCommand( CreateStreamsOnTable, sqlConnection );
19 command.ExecuteNonQuery();
20
21 command.Dispose();
22}
23
24public void insertStreamsOn( int movieID, String name ) {
25
26
27
28 String insertIntoStreamsOn = "INSERT INTO StreamsOn VALUES ( @Name, @MID)";
29
30 try {
31 SQLiteCommand command = new SQLiteCommand( "PRAGMA foreign_keys = ON", sqlConnection );
32 command.ExecuteNonQuery();
33 command = command = new SQLiteCommand( insertIntoStreamsOn, sqlConnection );
34
35 command.Parameters.AddWithValue( "@MID", movieID );
36 command.Parameters.AddWithValue( "@Name", name );
37 //command.Parameters.AddWithValue( "@Link", link );
38
39 command.ExecuteNonQuery();
40 command.Dispose();