From fea143f2def4257f40ecdb0d1a0d922a123cf16d Mon Sep 17 00:00:00 2001 From: 0ceanSlim <89587889+0ceanSlim@users.noreply.github.com> Date: Mon, 4 Sep 2023 15:20:09 -0400 Subject: [PATCH] update.py script working, pulls in data from csv in data folder --- Database/items.db | Bin 77824 -> 77824 bytes Database/update.py | 19 ++++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Database/items.db b/Database/items.db index 7be37b7d3b79090b71b31bb22f237b24f816373e..c66e664c003dd9c52939398f07cd198806accd29 100644 GIT binary patch delta 448 zcmX|+O)LXJ6vua`O=xRo)Gr) zNH!r633tgRB;p{Fx^U#+&Kn1F`TgH7Gw;1QsCf@+-f~#Z9!JLH>_zUBM=7mJ{DD{b z9?$SF`((H5h%K`|Ceue+r6*28S)qEsRRYrgF-nz8K#IlXI-idit_B6wByI$1nnBz! zG^#?sVa--iH(_@i(ug8$N4=el+7f@|m;8_~@-!#xiJh^1HqT=8i{4V3+Dr^nVZ%&fJpm)B7WnB2VIGHTQ@j~NCpZd< z)rA~^vK54^CGHHvU8)y3gide}Zma}yzgLY+>n^gpoc_)iVYBBOoo*=Eu$O9xrCntzYFmg{8lmxLjCUeRNFmge~IVK0l2{3X_ z_K?wI z3UR!XA82qf@=t!KFTZ)MtsxVWJmcnv`icTv9~qeVZ!q#d=fAO;$Kf=;h6pb+vpi!_ jYEFJ)N@iZV1qTzeC}U!7ZoUx%0|Or?Tw?Qof5ry@Y06P% diff --git a/Database/update.py b/Database/update.py index 912eeb9c..440b4a85 100644 --- a/Database/update.py +++ b/Database/update.py @@ -1,6 +1,6 @@ -import sqlite3 import csv import os +import sqlite3 # Connect to the SQLite database conn = sqlite3.connect("items.db") @@ -17,6 +17,10 @@ csv_file_ammo = "ammo.csv" # Change this to your new_table CSV file name csv_path_reloading = os.path.join(csv_directory, csv_file_reloading) csv_path_ammo = os.path.join(csv_directory, csv_file_ammo) +# Define the starting ID values for each table +starting_id_reloading = 20000 # Replace with your desired starting value +starting_id_ammo = 10000 # Replace with your desired starting value + # Define the table schema for reloading cursor.execute( """ @@ -52,9 +56,22 @@ cursor.execute( """ ) +# Set the starting ID values for each table using INSERT statements +cursor.execute(f"INSERT INTO reloading (id) VALUES ({starting_id_reloading})") + +# Reset the ammo table's id sequence +cursor.execute(f"DELETE FROM SQLITE_SEQUENCE WHERE name='ammo'") +cursor.execute( + f"INSERT INTO SQLITE_SEQUENCE (name, seq) VALUES ('ammo', {starting_id_ammo})" +) + # Function to load data from a CSV file into a table def load_csv_data(csv_path, table_name, cursor): + # Delete existing data in the table + delete_query = f"DELETE FROM {table_name}" + cursor.execute(delete_query) + with open(csv_path, newline="") as csvfile: csv_reader = csv.reader(csvfile) next(csv_reader) # Skip the header row if it exists in the CSV