Commit dd091e72 authored by Robert's avatar Robert
Browse files

stock delete

parent d6e99e64
......@@ -11,6 +11,7 @@ COMMAND_INDIVIDUAL_ARTICLE = "article "
COMMAND_INDIVIDUAL_COMMENT = "comment "
COMMAND_INDIVIDUAL_BACK = "back"
COMMAND_INDIVIDUAL_HELP = "help"
COMMAND_INDIVIDUAL_DELETE_STOCK = "delete stock"
INDIVIDUAL_NEXT_COMMAND = "Continue, update, or delete (c/u/d): "
INDIVIDUAL_NEXT_COMMAND_MULTI = "Continue, update or delete a specific entry (c/u/d ['n']): "
......
......@@ -3,7 +3,6 @@ from search_queries import *
from insert_queries import *
from common_functions import *
def individual(db, cursor):
print(SEPARATOR + "\nEntered individual mode\nType \"help\" for additional instructions\n" + SEPARATOR)
active_ticker = None
......@@ -92,6 +91,13 @@ def individual(db, cursor):
print(SEPARATOR + "\nLeaving \"individual\" mode\n" + SEPARATOR)
break
elif user_input == COMMAND_INDIVIDUAL_DELETE_STOCK:
if active_ticker is None:
print(INDIVIDUAL_MISSING_TICKER)
else:
delete_stock_query(db, cursor, active_ticker)
active_ticker = None
else:
print("Unknown command, type \"help\" for instructions")
......
......@@ -14,7 +14,7 @@ def insert_stock_query(db, cursor):
print(INSERT_DATA)
# Inser a row into the stock price table
# Insert a row into the stock price table
def insert_price_query(user_input, db, cursor, active_ticker):
val = (active_ticker,) + collect_price_input()
......@@ -77,4 +77,17 @@ def insert_article_query(user_input, db, cursor, active_ticker):
cursor.execute(sql, val)
db.commit()
print(INSERT_DATA)
\ No newline at end of file
print(INSERT_DATA)
# Delete all data for a given stock
def delete_stock_query(db, cursor, active_ticker):
cursor.execute("delete from StockComment where symbol = '" + active_ticker + "'")
cursor.execute("delete from StockPrice where symbol = '" + active_ticker + "'")
cursor.execute("delete from IPODetails where symbol = '" + active_ticker + "'")
cursor.execute("delete from Financials where symbol = '" + active_ticker + "'")
cursor.execute("delete from Article where symbol = '" + active_ticker + "'")
cursor.execute("delete from Stock where symbol = '" + active_ticker + "'")
db.commit()
print(INDIVIDUAL_DELETE_COMPLETE)
\ No newline at end of file
......@@ -296,8 +296,6 @@ select id, author
from ArticleTemp
where type = 0;
truncate table ArticleTemp;
/* Load the partner articles */
load data infile '/var/lib/mysql-files/18-Stocks/raw_partner_headlines.csv' ignore into table ArticleTemp
fields terminated by ','
......@@ -338,9 +336,9 @@ add foreign key (symbol) references Stock(symbol),
modify articleID int auto_increment;
alter table AnalystArticle
add foreign key (articleID) references Article(articleID);
add foreign key (articleID) references Article(articleID) on delete cascade;
alter table PartnerArticle
add foreign key (articleID) references Article(articleID);
add foreign key (articleID) references Article(articleID) on delete cascade;
/* Drop the temp table as we no longer need it */
drop table ArticleTemp;
......
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