Guest User

Creating Databases for Drop Logger

a guest
Jan 25th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.73 KB | None | 0 0
  1. #Made by Matt (Ambler3) -
  2. #RUNNING THIS PROGRAM ONCE IS REQUIRED
  3. #BEFORE YOU START USING THE DROP LOGGER
  4. #IT WILL NOT WORK WITHOUT IT!
  5. import sqlite3
  6.  
  7.  
  8. def create_table(db_name,table_name,sql):
  9.     with sqlite3.connect(db_name) as db:
  10.         cursor = db.cursor()
  11.         cursor.execute("select name from sqlite_master where name=?",(table_name,))
  12.         result = cursor.fetchall()
  13.         keep_table = True
  14.         if len(result) == 1:
  15.             response = input('The table {0} already exists, do you wish to recreate it (y/n): '.format(table_name))
  16.             if response == 'y':
  17.                 keep_table = False
  18.                 print("The {0} table will be recreated - all existing data will be lost".format(table_name))
  19.                 cursor.execute("drop table if exists {0}".format(table_name))
  20.                 db.commit()
  21.             else:
  22.                 print("The existing table was kept")
  23.         else:
  24.             keep_table = False
  25.         if not keep_table:
  26.             cursor.execute(sql)
  27.             db.commit()
  28. #Creates the pre-set drop tables.
  29. def aa():
  30.     sql = """create table SecondaryDrops
  31.           (SecondaryDropID integer,
  32.           SecondaryDropName text,
  33.           SecondaryDropImage text,
  34.           primary key(SecondaryDropID))"""
  35.     create_table(db_name,"SecondaryDrops",sql)
  36.  
  37. def bb():
  38.     sql = """create table Barrows2Drops
  39.           (Barrows2DropID integer,
  40.           Barrows2DropName text,
  41.           Barrows2DropImage text,
  42.           primary key(Barrows2DropID))"""
  43.     create_table(db_name, "Barrows2Drops", sql)
  44.  
  45. def cc():
  46.     sql = """create table KKDrops
  47.           (KKDropID integer,
  48.           KKDropName text,
  49.           KKDropImage text,
  50.           primary key(KKDropID))"""
  51.     create_table(db_name, "KKDrops", sql)
  52.  
  53. def dd():
  54.     sql = """create table NexDrops
  55.           (NexDropID integer,
  56.           NexDropName text,
  57.           NexDropImage text,
  58.           primary key(NexDropID))"""
  59.     create_table(db_name, "NexDrops", sql)
  60.  
  61. def ee():
  62.     sql = """create table QBDDrops
  63.           (QBDDropID integer,
  64.           QBDDropName text,
  65.           QBDDropImage text,
  66.           primary key(QBDDropID))"""
  67.     create_table(db_name,"QBDDrops" ,sql)
  68.  
  69. def ff():
  70.     sql = """create table VoragoDrops
  71.           (VoragoDropID integer,
  72.           VoragoDropName text,
  73.           VoragoDropImage text,
  74.           primary key(VoragoDropID))"""
  75.     create_table(db_name, "VoragoDrops", sql)
  76.  
  77. #Creates the tables for the drop logs.
  78.  
  79. def gg():
  80.     sql = """create table Barrows2Loots
  81.           (Barrows2LootID integer,
  82.           Barrows2DropName text,
  83.           Barrows2DropImage text,
  84.           SecondaryDropName text,
  85.           SecondaryDropImage text,
  86.           primary key(Barrows2LootID)
  87.           foreign key(Barrows2DropName) references Barrows2Drops(Barrows2DropName)
  88.           foreign key(Barrows2DropImage) references Barrows2Drops(Barrows2DropImage)
  89.           foreign key(SecondaryDropName) references SecondaryDrops(SecondaryDropName)
  90.           foreign key(SecondaryDropImage) references SecondaryDrops(SecondaryDropImage))"""
  91.     create_table(db_name, "Barrows2Loots", sql)
  92.  
  93. def hh():
  94.     sql = """create table KKLoots
  95.           (KKLootID integer,
  96.           KKDropName text,
  97.           KKDropImage text,
  98.           SecondaryDropName text,
  99.           SecondaryDropImage text,
  100.           primary key(KKLootID)
  101.           foreign key(KKDropName) references KKDrops(KKDropName)
  102.           foreign key(KKDropImage) references KK(KKDropImage)
  103.           foreign key(SecondaryDropName) references SecondaryDrops(SecondaryDropName)
  104.           foreign key(SecondaryDropImage) references SecondaryDrops(SecondaryDropImage))"""
  105.     create_table(db_name, "KKLoots", sql)
  106.  
  107. def ii():
  108.     sql = """create table NexLoots
  109.           (NexLootID integer,
  110.           NexDropName text,
  111.           NexDropImage text,
  112.           SecondaryDropName text,
  113.           SecondaryDropImage text,
  114.           primary key(NexLootID)
  115.           foreign key(NexDropName) references NexDrops(NexDropName)
  116.           foreign key(NexDropImage) references Nex(NexDropImage)
  117.           foreign key(SecondaryDropName) references SecondaryDrops(SecondaryDropName)
  118.           foreign key(SecondaryDropImage) references SecondaryDrops(SecondaryDropImage))"""
  119.     create_table(db_name, "NexLoots", sql)
  120.  
  121. def jj():
  122.     sql = """create table QBDLoots
  123.           (QBDLootID integer,
  124.           QBDDropName text,
  125.           QBDDropImage text,
  126.           SecondaryDropName text,
  127.           SecondaryDropImage text,
  128.           primary key(QBDLootID)
  129.           foreign key(QBDDropName) references QBDDrops(QBDDropName)
  130.           foreign key(QBDDropImage) references QBDDrops(QBDDropImage)
  131.           foreign key(SecondaryDropName) references SecondaryDrops(SecondaryDropName)
  132.           foreign key(SecondaryDropImage) references SecondaryDrops(SecondaryDropImage))"""
  133.     create_table(db_name, "QBDLoots", sql)
  134.  
  135. def kk():
  136.     sql = """create table VoragoLoots
  137.           (VoragoLootID integer,
  138.           VoragoDropName text,
  139.           VoragoDropImage text,
  140.           SecondaryDropName text,
  141.           SecondaryDropImage text,
  142.           primary key(VoragoLootID)
  143.           foreign key(VoragoDropName) references VoragoDrops(VoragoDropName)
  144.           foreign key(VoragoDropImage) references VoragoDrops(VoragoDropImage)
  145.           foreign key(SecondaryDropName) references SecondaryDrops(SecondaryDropName)
  146.           foreign key(SecondaryDropImage) references SecondaryDrops(SecondaryDropImage))"""
  147.     create_table(db_name, "VoragoLoots", sql)
  148.  
  149.  
  150.  
  151. #If you wish to add a custom boss, please fill fill in this code with the correct boss names, if you want any additional bosses, just change the lettering (so def mm(): ... etc and add the relevant information in, you will also need to add to the main program to change stuff aswell.#
  152.  
  153.  
  154. #def ll():
  155. #   sql = """create table BOSSNAMEDrops
  156. #         (BOSSNAMEDropID integer,
  157. #         BOSSNAMEDropName text,
  158. #         BOSSNAMEDropImage text,
  159. #         primary key(BOSSNAMEDropID))"""
  160. #   create_table(db_name, "BOSSNAMEDrops", sql)
  161.  
  162.  
  163. #def mm():
  164. #   sql = """create table BOSSNAMELoots
  165. #         (BOSSNAMELootID integer,
  166. #         BOSSNAMEDropName text,
  167. #         BOSSNAMEDropImage text,
  168. #         SecondaryDropName text,
  169. #         SecondaryDropImage text,
  170. #         primary key(BOSSNAMELootID)
  171. #         foreign key(BOSSNAMEDropName) references BOSSNAMEDrops(BOSSNAMEDropName)
  172. #         foreign key(BOSSNAMEDropImage) references BOSSNAMEDrops(BOSSNAMEDropImage)
  173. #         foreign key(SecondaryDropName) references SecondaryDrops(SecondaryDropName)
  174. #         foreign key(SecondaryDropImage) references SecondaryDrops(SecondaryDropImage))"""
  175. #   create_table(db_name, "BOSSNAMELoots", sql)
  176.  
  177.  
  178.  
  179. if __name__ == '__main__':
  180.     print('This will create a blank database for you')
  181.     print("This program should only be run ONCE")
  182.     print("before using the drop logger, if you have")
  183.     print("already got a 'DropTables.db' file, close this now!")
  184.     print("You could overwrite all of your logs if you continue!")
  185.     print("Input 'Y' to continue, any other input will close the program")
  186.     input = input(">> ")
  187.     if input == 'Y' or input == 'y':
  188.         db_name = "DropTables.db"
  189.         aa()
  190.         bb()
  191.         cc()
  192.         dd()
  193.         ee()
  194.         ff()
  195.         gg()
  196.         hh()
  197.         ii()
  198.         jj()
  199.         kk()
  200.         #if you wish to add your own sections, please fill in the template above
  201.         #add extra functions as needed, though more functions = larger database! :)
  202.         #ll()
  203.         #mm()
  204.     else:
  205.         print("Exiting.")
Advertisement
Add Comment
Please, Sign In to add comment