Commit 5e6234bd authored by RAYMOND XIA's avatar RAYMOND XIA
Browse files

Merge branch 'master' of https://git.uwaterloo.ca/db4kim/356-project into master

parents 72c02ffd b183208a
import java.util.HashMap;
import java.util.HashSet;
import java.util.ArrayList;
import java.util.Scanner;
import java.rmi.server.SocketSecurityException;
import java.sql.*;
import java.text.SimpleDateFormat;
......@@ -175,12 +173,6 @@ public class ClientApplication {
String query = String.format(searchQueryString, keywords, sortString);
ResultSet rs = st.executeQuery(query);
printQueryResults(rs);
// Possible queries
// select * from ImdbMovies where name = '';
// select * from ImdbNames where name = '';
// categorize based on movie, person, genre
} catch (Exception e) {
System.out.println(e);
......@@ -950,40 +942,34 @@ public class ClientApplication {
case "c":
exitLoop = true;
try {
Statement idst = c.createStatement();
String idQuery = "select * from MaxIDs where entityName = 'person'";
ResultSet idrs = idst.executeQuery(idQuery);
PreparedStatement query = c.prepareStatement("select * from MaxIDs where entityName = 'person'");
ResultSet idrs = query.executeQuery();
int maxId = 0;
while (idrs.next()) {
maxId = Integer.parseInt(idrs.getString(2));
}
maxId++;
Statement updateId = c.createStatement();
String updateIdQuery = "update MaxIDs set entityNum = " + maxId + " where entityName = 'person'";
updateId.execute(updateIdQuery);
Statement st = c.createStatement();
String query = String.format("insert into People values ('%s', '%s', '%s', '%s', '%s', '%s', '%s')",
"nm" + maxId,
values.get(name),
values.get(birthName),
values.get(height),
values.get(biography),
values.get(birthDetails),
new java.sql.Timestamp(format.parse(values.get(dateOfBirth) + " 00:00:00").getTime())
);
st.execute(query);
query = c.prepareStatement("update MaxIDs set entityNum = ? where entityName = 'person'");
query.executeUpdate();
query = c.prepareStatement("insert into People values (?, ?, ?, ?, ?, ?, ?)");
query.setString(1, "nm" + maxId);
query.setString(2, values.get(name));
query.setString(3, values.get(birthName));
query.setInt(4, Integer.parseInt(values.get(height)));
query.setString(5, values.get(biography));
query.setString(6, values.get(birthDetails));
query.setTimestamp(7, values.containsKey(dateOfBirth) ? new java.sql.Timestamp(format.parse(values.get(dateOfBirth) + " 00:00:00").getTime()) : null);
query.execute();
if (values.containsKey(dateOfDeath) || values.containsKey(placeOfDeath) || values.containsKey(reasonOfDeath)) {
Statement st2 = c.createStatement();
String deathQuery = String.format("insert into DeadPeople values ('%s', '%s', '%s', '%s')",
"nm" + maxId,
new java.sql.Timestamp(format.parse(values.get(dateOfDeath) + " 00:00:00").getTime()),
values.get(placeOfDeath),
values.get(reasonOfDeath)
);
st2.execute(deathQuery);
query = c.prepareStatement("insert into DeadPeople values (?, ?, ?, ?)");
query.setString(1, "nm" + maxId);
query.setTimestamp(2, values.containsKey(dateOfDeath) ? new java.sql.Timestamp(format.parse(values.get(dateOfDeath) + " 00:00:00").getTime()) : null);
query.setString(3, values.get(placeOfDeath));
query.setString(4, values.get(reasonOfDeath));
query.execute();
}
} catch (Exception e) {
System.out.println(e);
......
......@@ -197,10 +197,11 @@ delimiter ;
call loadGenre();
-- country stuff
-- create table Countries (
-- country varchar(128) not null
-- );
-- alter table Countries add primary key (country);
create table Countries (
country varchar(128) not null
);
alter table Countries add primary key (country);
replace into Countries (country) select distinct country from ImdbMovies;
-- drop table if exists temp;
-- create table temp (val varchar(128));
......@@ -241,13 +242,14 @@ call loadGenre();
-- drop table if exists temp;
-- alter table Countries add index countryIndex(country);
-- create table CountriesInMovies (
-- movieID char(9) not null,
-- country varchar(64) not null
-- );
-- alter table CountriesInMovies add primary key (movieID, country);
-- alter table CountriesInMovies add foreign key (movieID) references Movies(movieID);
-- alter table CountriesInMovies add foreign key (country) references Countries(country);
create table CountriesInMovies (
movieID char(9) not null,
country varchar(128) not null
);
alter table CountriesInMovies add primary key (movieID, country);
alter table CountriesInMovies add foreign key (movieID) references Movies(movieID);
alter table CountriesInMovies add foreign key (country) references Countries(country);
replace into CountriesInMovies (movieID, country) select movieID, country from ImdbMovies;
-- drop procedure if exists loadCountry;
-- delimiter ;;
......@@ -286,10 +288,11 @@ call loadGenre();
-- call loadCountry();
-- language stuff
-- create table Languages (
-- language varchar(128) not null
-- );
-- alter table Languages add primary key (language);
create table Languages (
language varchar(128) not null
);
alter table Languages add primary key (language);
replace into Languages (language) select distinct language from ImdbMovies;
-- drop table if exists temp;
-- create table temp (val varchar(128));
......@@ -329,14 +332,14 @@ call loadGenre();
-- call parseLanguage();
-- alter table Languages add index languageIndex(language);
-- create table LanguagesInMovies (
-- movieID char(9) not null,
-- language varchar(128) not null
-- );
-- alter table LanguagesInMovies add primary key (movieID, language);
-- alter table LanguagesInMovies add foreign key (movieID) references Movies(movieID);
-- alter table LanguagesInMovies add foreign key (language) references Languages(language);
create table LanguagesInMovies (
movieID char(9) not null,
language varchar(128) not null
);
alter table LanguagesInMovies add primary key (movieID, language);
alter table LanguagesInMovies add foreign key (movieID) references Movies(movieID);
alter table LanguagesInMovies add foreign key (language) references Languages(language);
replace into LanguagesInMovies (movieID, language) select movieID, language from ImdbMovies;
-- drop procedure if exists loadLanguage;
-- delimiter ;;
-- create procedure loadLanguage() begin
......@@ -378,7 +381,7 @@ create table ProductionCompany (
productionCompany varchar(128) not null
);
alter table ProductionCompany add primary key (productionCompany);
replace into ProductionCompany (productionCompany) select productionCompany from ImdbMovies;
replace into ProductionCompany (productionCompany) select distinct productionCompany from ImdbMovies;
alter table ProductionCompany add index productionCompanyIndex(productionCompany);
create table ProductionCompaniesInMovies (
......
......@@ -23,9 +23,10 @@ create table ImdbMovies (
userScore float,
criticScore float
);
load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/IMDb movies.csv' ignore into table ImdbMovies
load data infile '/var/lib/mysql-files/03-Movies/IMDb movies.csv' ignore into table ImdbMovies
fields terminated by ','
enclosed by '"'
escaped by ''
lines terminated by '\n'
ignore 1 lines;
update ImdbMovies set releaseDate = null where cast(releaseDate as char(20)) = '0000-00-00 00:00:00';
......@@ -52,7 +53,7 @@ create table ImdbNames (
spousesWithChildren int,
children int
);
load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/IMDb names.csv' ignore into table ImdbNames
load data infile '/var/lib/mysql-files/03-Movies/IMDb names.csv' ignore into table ImdbNames
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
......@@ -82,7 +83,7 @@ create table ImdbTitlePrincipals (
job varchar(256),
characters varchar(512)
);
load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/IMDb title_principals.csv' ignore into table ImdbTitlePrincipals
load data infile '/var/lib/mysql-files/03-Movies/IMDb title_principals.csv' ignore into table ImdbTitlePrincipals
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
......@@ -114,7 +115,7 @@ create table MojoBudgetData (
genre4 varchar(16),
link varchar(64)
);
load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/Mojo_budget_data.csv' ignore into table MojoBudgetData
load data infile '/var/lib/mysql-files/03-Movies/Mojo_budget_data.csv' ignore into table MojoBudgetData
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
......@@ -149,7 +150,7 @@ create table MojoBudgetUpdate (
genre4 varchar(16),
html varchar(64)
);
load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/Mojo_budget_update.csv' ignore into table MojoBudgetUpdate
load data infile '/var/lib/mysql-files/03-Movies/Mojo_budget_update.csv' ignore into table MojoBudgetUpdate
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
......@@ -183,7 +184,7 @@ create table MoviesMetadata (
score float,
votes int
);
load data infile 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/movies_metadata.csv' ignore into table MoviesMetadata
load data infile '/var/lib/mysql-files/03-Movies/movies_metadata.csv' ignore into table MoviesMetadata
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment