working python scripts for adding new tables and items to database
This commit is contained in:
parent
052cdbadd6
commit
2ac0f307dd
54
Database/ammo.py
Normal file
54
Database/ammo.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# Connect to the SQLite database
|
||||||
|
conn = sqlite3.connect("items.db")
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Drop the existing reloading table if it exists
|
||||||
|
cursor.execute("DROP TABLE IF EXISTS ammo")
|
||||||
|
|
||||||
|
# Create the reloading table with an auto-incremented primary key
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE ammo (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
stack INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
gunpowder INTEGER
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
# id TEXT PRIMARY KEY, type TEXT, name TEXT, rarity INTEGER, weight REAL, width INTEGER, height INTEGER, value INTEGER, stack INTEGER
|
||||||
|
|
||||||
|
# Define your data to insert
|
||||||
|
data_to_insert = [
|
||||||
|
("rifle_ammo", "5.56x45 AP", 4, 0.02646, 1, 1, 7500, 30, 15),
|
||||||
|
("rifle_ammo", "5.56x45 FMJ", 1, 0.02646, 1, 1, 2500, 30, 10),
|
||||||
|
("rifle_ammo", "5.56x45 HP", 2, 0.02646, 1, 1, 5000, 30, 10),
|
||||||
|
("pistol_ammo", "9mm AP", 3, 0.01984, 1, 1, 5000, 45, 12),
|
||||||
|
("pistol_ammo", "9mm FMJ", 1, 0.01984, 1, 1, 2000, 45, 6),
|
||||||
|
("pistol_ammo", "9mm HP", 2, 0.01984, 1, 1, 4000, 45, 6),
|
||||||
|
("pistol_ammo", ".40 S&W AP", 3, 0.01984, 1, 1, 5500, 45, 13),
|
||||||
|
("pistol_ammo", ".40 S&W FMJ", 1, 0.01984, 1, 1, 3000, 45, 7),
|
||||||
|
("pistol_ammo", ".40 S&W HP", 2, 0.01984, 1, 1, 4500, 45, 7),
|
||||||
|
("rifle_ammo", "7.62x39 AP", 4, 0.02646, 1, 1, 5200, 30, 15),
|
||||||
|
("rifle_ammo", "7.62x39 FMJ", 1, 0.02646, 1, 1, 1800, 30, 10),
|
||||||
|
("rifle_ammo", "7.62x39 HP", 2, 0.02646, 1, 1, 3600, 30, 10),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Insert data into the table without specifying the 'id' column
|
||||||
|
for row in data_to_insert:
|
||||||
|
cursor.execute(
|
||||||
|
"INSERT INTO ammo (type, name, rarity, weight, width, height, stack, value, gunpowder) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
row,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Commit the changes and close the connection
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
BIN
Database/items.db
Normal file
BIN
Database/items.db
Normal file
Binary file not shown.
54
Database/reloading.py
Normal file
54
Database/reloading.py
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import sqlite3
|
||||||
|
|
||||||
|
# Connect to the SQLite database
|
||||||
|
conn = sqlite3.connect("items.db")
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Drop the existing reloading table if it exists
|
||||||
|
cursor.execute("DROP TABLE IF EXISTS reloading")
|
||||||
|
|
||||||
|
# Create the reloading table with an auto-incremented primary key
|
||||||
|
cursor.execute(
|
||||||
|
"""
|
||||||
|
CREATE TABLE reloading (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
stack INTEGER,
|
||||||
|
value INTEGER
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
# Define your data to insert
|
||||||
|
data_to_insert = [
|
||||||
|
("misc", "Primer", 1, 0.00496, 1, 1, 100, 300),
|
||||||
|
("misc", "Gunpowder", 1, 0.00044, 1, 2, 500, 50),
|
||||||
|
("bullet", "5.56 AP Bullet", 4, 0.00992, 1, 1, 60, 5000),
|
||||||
|
("bullet", "5.56 FMJ Bullet", 1, 0.00992, 1, 1, 60, 750),
|
||||||
|
("bullet", "5.56 HP Bullet", 2, 0.00992, 1, 1, 60, 1800),
|
||||||
|
("casing", "5.56 Casing", 1, 0.00469, 1, 1, 30, 1000),
|
||||||
|
("bullet", "9mm AP Bullet", 3, 0.00992, 1, 1, 60, 4000),
|
||||||
|
("bullet", "9mm FMJ Bullet", 1, 0.00992, 1, 1, 60, 400),
|
||||||
|
("bullet", "9mm HP Bullet", 2, 0.00992, 1, 1, 60, 1500),
|
||||||
|
("casing", "9mm Casing", 1, 0.00469, 1, 1, 30, 750),
|
||||||
|
("bullet", "7.62x39 AP Bullet", 4, 0.00992, 1, 1, 60, 3500),
|
||||||
|
("bullet", "7.62x39 FMJ Bullet", 1, 0.00992, 1, 1, 60, 525),
|
||||||
|
("bullet", "7.62x39 HP Bullet", 2, 0.00992, 1, 1, 60, 1260),
|
||||||
|
("casing", "7.62x39 Casing", 1, 0.00469, 1, 1, 30, 500),
|
||||||
|
]
|
||||||
|
|
||||||
|
# Insert data into the table without specifying the 'id' column
|
||||||
|
for row in data_to_insert:
|
||||||
|
cursor.execute(
|
||||||
|
"INSERT INTO reloading (type, name, rarity, weight, width, height, stack, value) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
|
row,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Commit the changes and close the connection
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
147
Database/tables.py
Normal file
147
Database/tables.py
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Define the database file name
|
||||||
|
db_file = "items.db"
|
||||||
|
|
||||||
|
# Check if the database file exists, and delete it if it does
|
||||||
|
if os.path.exists(db_file):
|
||||||
|
os.remove(db_file)
|
||||||
|
|
||||||
|
# Connect to the SQLite database (create a new one since the old one was deleted)
|
||||||
|
conn = sqlite3.connect(db_file)
|
||||||
|
|
||||||
|
# Create a cursor object to interact with the database
|
||||||
|
cursor = conn.cursor()
|
||||||
|
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS ammo (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS reloading (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS consumable (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS craft (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS gear (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS parts (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS guns (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS medicine (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
# Execute the SQL command to create the table
|
||||||
|
cursor.execute(
|
||||||
|
"""CREATE TABLE IF NOT EXISTS miscelaneous (
|
||||||
|
id TEXT PRIMARY KEY,
|
||||||
|
type TEXT,
|
||||||
|
name TEXT,
|
||||||
|
rarity INTEGER,
|
||||||
|
weight REAL,
|
||||||
|
width INTEGER,
|
||||||
|
height INTEGER,
|
||||||
|
value INTEGER,
|
||||||
|
stack INTEGER
|
||||||
|
)"""
|
||||||
|
)
|
||||||
|
# Commit the changes and close the database connection
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
Loading…
Reference in New Issue
Block a user