moved scripts to database scripts
This commit is contained in:
30
py_app/app/db_create_scripts/delet scan1_orders values.py
Normal file
30
py_app/app/db_create_scripts/delet scan1_orders values.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import mariadb
|
||||
|
||||
# Database connection credentials
|
||||
def get_db_connection():
|
||||
return mariadb.connect(
|
||||
user="trasabilitate", # Replace with your username
|
||||
password="Initial01!", # Replace with your password
|
||||
host="localhost", # Replace with your host
|
||||
port=3306, # Default MariaDB port
|
||||
database="trasabilitate_database" # Replace with your database name
|
||||
)
|
||||
|
||||
try:
|
||||
# Connect to the database
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Delete query
|
||||
delete_query = "DELETE FROM scan1_orders"
|
||||
cursor.execute(delete_query)
|
||||
conn.commit()
|
||||
|
||||
print("All data from the 'scan1_orders' table has been deleted successfully.")
|
||||
|
||||
# Close the connection
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(f"Error deleting data: {e}")
|
||||
34
py_app/app/db_create_scripts/query.py
Normal file
34
py_app/app/db_create_scripts/query.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import mariadb
|
||||
|
||||
# Database connection credentials
|
||||
db_config = {
|
||||
"user": "trasabilitate",
|
||||
"password": "Initial01!",
|
||||
"host": "localhost",
|
||||
"database": "trasabilitate_database"
|
||||
}
|
||||
|
||||
try:
|
||||
# Connect to the database
|
||||
conn = mariadb.connect(**db_config)
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Query to fetch all records from the scan1 table
|
||||
query = "SELECT * FROM scan1_orders ORDER BY Id DESC LIMIT 15"
|
||||
cursor.execute(query)
|
||||
|
||||
# Fetch and print the results
|
||||
rows = cursor.fetchall()
|
||||
if rows:
|
||||
print("Records in the 'scan1_orders' table:")
|
||||
for row in rows:
|
||||
print(row)
|
||||
else:
|
||||
print("No records found in the 'scan1_orders' table.")
|
||||
|
||||
# Close the connection
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(f"Error connecting to the database: {e}")
|
||||
37
py_app/app/db_create_scripts/test.py
Normal file
37
py_app/app/db_create_scripts/test.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import mariadb
|
||||
|
||||
# Database connection credentials
|
||||
def get_db_connection():
|
||||
return mariadb.connect(
|
||||
user="trasabilitate", # Replace with your username
|
||||
password="Initial01!", # Replace with your password
|
||||
host="localhost", # Replace with your host
|
||||
port=3306, # Default MariaDB port
|
||||
database="trasabilitate_database" # Replace with your database name
|
||||
)
|
||||
|
||||
try:
|
||||
# Connect to the database
|
||||
conn = get_db_connection()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# Insert query
|
||||
insert_query = """
|
||||
INSERT INTO scan1_orders (operator_code, CP_full_code, OC1_code, OC2_code, quality_code, date, time)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)
|
||||
"""
|
||||
# Values to insert
|
||||
values = ('OP01', 'CP12345678-0002', 'OC11', 'OC22', 000, '2025-04-22', '14:30:00')
|
||||
|
||||
# Execute the query
|
||||
cursor.execute(insert_query, values)
|
||||
conn.commit()
|
||||
|
||||
print("Test data inserted successfully into scan1_orders.")
|
||||
|
||||
# Close the connection
|
||||
cursor.close()
|
||||
conn.close()
|
||||
|
||||
except mariadb.Error as e:
|
||||
print(f"Error inserting data: {e}")
|
||||
Reference in New Issue
Block a user