Guest User

Untitled

a guest
Apr 24th, 2018
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. # the python we used to create sql requests for inserting sample data into the tables
  2.  
  3. import sqlite3
  4. connection = sqlite3.connect("phase2.db")
  5.  
  6. cursor = connection.cursor()
  7.  
  8. # inserting customers
  9.  
  10. customer_data = [ (666666660, "john@aol.com", "John Smith", "123 lake drive", "123 lake drive", 8041230000, 1),
  11. (666666661, "sam@aol.com", "Sam Smith", "124 lake drive", "124 lake drive", 8041231000, 1),
  12. (666666662, "tim@aol.com", "Tim Smith", "125 lake drive", "125 lake drive", 8041232000, 1),
  13. (666666663, "ray@aol.com", "Ray Smith", "126 lake drive", "126 lake drive", 8041233000, 1),
  14. (666666664, "carl@aol.com", "Carl Smith", "127 lake drive", "127 lake drive", 8041234000, 1) ]
  15.  
  16. for p in customer_data:
  17. format_str = """INSERT INTO Customer (Customer_Id, Email, Name, BillingAddress, ShippingAddress, PhoneNumber, TotalOrders)
  18. VALUES ("{id}", "{email}", "{name}", "{billing}", "{shipping}", "{phone}", "{totalorders}");"""
  19.  
  20. sql_command = format_str.format(id=p[0], email=p[1], name=p[2], billing = p[3], shipping = p[4], phone = p[5], totalorders = p[6])
  21. cursor.execute(sql_command)
  22.  
  23. # inserting suppliers
  24. supplier_data = [ (6660, "ABC games", "123 green st", 7176661000, 1),
  25. (6661, "GameEmporium", "124 green st", 7176662000, 1),
  26. (6662, "SplendidGames", "125 green st", 7176663000, 1),
  27. (6663, "XYZ games", "126 green st", 7176664000, 1),
  28. (6664, "Games Deluxe", "127 green st", 7176665000, 1) ]
  29.  
  30. for p in supplier_data:
  31. format_str = """INSERT INTO Supplier (Supplier_Id, SupplierName, Address, PhoneNumber, TotalProducts)
  32. VALUES ("{id}", "{name}", "{address}", "{phone}", "{totalproducts}");"""
  33.  
  34. sql_command = format_str.format(id=p[0], name=p[1], address=p[2], phone = p[3], totalproducts = p[4])
  35. cursor.execute(sql_command)
  36.  
  37. # inserting games
  38.  
  39. game_data = [ (11110, "War 3", 19.80, "Action", "ABC Studios", 7176661000),
  40. (11111, "Fifa 18", 59.99, "Sports", "XYZ Studios", 7176662000),
  41. (11112, "Madden 18", 59.99, "Sports", "ABC Studios", 7176663000),
  42. (11113, "COD 4", 49.99, "FPS", "456 Studios", 7176664000),
  43. (11114, "Far Cry 3", 25.99, "Shooter", "XYZ Studios", 7176665000) ]
  44.  
  45. for p in game_data:
  46. format_str = """INSERT INTO Game (Game_Id, Title, Price, Genre, DeveloperName, Supplier_Id)
  47. VALUES ("{id}", "{title}", "{price}", "{genre}", "{devname}", "{sid}");"""
  48.  
  49. sql_command = format_str.format(id=p[0], title=p[1], price=p[2], genre=p[3], devname=p[4], sid=p[5])
  50. cursor.execute(sql_command)
  51.  
  52.  
  53. # inserting products
  54.  
  55. product_data = [ (111110, 19.80, 11110),
  56. (111111, 59.99, 11111),
  57. (111112, 59.99, 11112),
  58. (111113, 49.99, 11113),
  59. (111114, 25.99, 11114) ]
  60.  
  61. for p in product_data:
  62. format_str = """INSERT INTO Product (Product_Id, Price, Game_Id)
  63. VALUES ("{id}", "{price}", "{gid}");"""
  64.  
  65. sql_command = format_str.format(id=p[0], price=p[1], gid=p[2])
  66. cursor.execute(sql_command)
  67.  
  68. # inserting payments
  69.  
  70. payment_data = [ (1000000, 59.99, "Paypal", "Complete", 666666660),
  71. (1000001, 159.99, "Debit", "Complete", 666666661),
  72. (1000002, 29.99, "Paypal", "Refunded", 666666662),
  73. (1000003, 25.99, "Credit", "Complete", 666666663),
  74. (1000004, 99.99, "Bitcoin", "Complete", 666666664)]
  75.  
  76. for p in payment_data:
  77. format_str = """INSERT INTO Payment (Payment_Id, Price, PaymentMethod, Payment_Status, Customer_Id)
  78. VALUES ("{id}", "{price}", "{method}", "{status}", "{cid}");"""
  79.  
  80. sql_command = format_str.format(id=p[0], price=p[1], method=p[2], status=p[3], cid=p[4])
  81. cursor.execute(sql_command)
  82.  
  83. #inserting orders
  84.  
  85. order_data = [ (100000, 59.99, 1, "2018-04-21 12:30:37", "Shipped", 111111, 666666660, 1000000),
  86. (100001, 159.99, 3, "2018-02-21 04:30:37", "Shipped", 111111, 666666661, 1000001),
  87. (100002, 29.99, 1, "2018-01-21 06:30:37", "Shipped", 111112, 666666662, 1000002),
  88. (100003, 25.99, 1, "2018-04-10 06:30:37", "Not Shipped", 111114, 666666663, 1000003),
  89. (100004, 49.99, 1, "2018-03-12 16:20:37", "Shipped", 111113, 666666664, 1000004),
  90. (100005, 50.00, 1, "2018-04-12 16:20:37", "Shipped", 111113, 666666664, 1000004)]
  91.  
  92. for p in order_data:
  93. format_str = """INSERT INTO Orders (Order_Id, Price, Quantity, Order_DateTime, Fulfillment_Status, Product_Id, Customer_Id, Payment_Id)
  94. VALUES ("{id}", "{price}", "{quant}", "{time}", "{status}", "{pid}", "{cid}", "{payid}");"""
  95.  
  96. sql_command = format_str.format(id=p[0], price=p[1], quant=p[2], time=p[3], status=p[4], pid=p[5], cid=p[6], payid=p[7])
  97. cursor.execute(sql_command)
  98.  
  99.  
  100. # inserting Carts
  101.  
  102. cart_data = [ (10000000, 49.99, 666666660),
  103. (10000001, 259.99, 666666661),
  104. (10000002, 19.99, 666666662),
  105. (10000003, 35.99, 666666661),
  106. (10000004, 99.99, 666666660)]
  107.  
  108. for p in cart_data:
  109. format_str = """INSERT INTO Cart (Cart_Id, TotalPrice, Customer_Id)
  110. VALUES ("{id}", "{price}", "{cid}");"""
  111.  
  112. sql_command = format_str.format(id=p[0], price=p[1], cid=p[2])
  113. cursor.execute(sql_command)
  114.  
  115. # inserting Line_Items
  116.  
  117. lineitem_data = [ (1000, 49.99, 1, 111113, 10000000),
  118. (1001, 259.99, 4, 111111, 10000001),
  119. (1002, 19.99, 1, 111110, 10000002),
  120. (1003, 35.99, 1, 111114, 10000003),
  121. (1004, 49.99, 1, 111113, 10000004),
  122. (1005, 49.99, 1, 111113, 10000004)]
  123.  
  124. for p in lineitem_data:
  125. format_str = """INSERT INTO Line_Item (SKU, Price, Quantity, Product_Id, Cart_Id)
  126. VALUES ("{sku}", "{price}", "{quant}", "{pid}", "{cid}" );"""
  127.  
  128. sql_command = format_str.format(sku=p[0], price=p[1], quant=p[2], pid=p[3], cid=p[4])
  129. cursor.execute(sql_command)
  130.  
  131.  
  132. connection.commit()
  133.  
  134. connection.close()
Add Comment
Please, Sign In to add comment