From 965e5a484d19fa4c798e30c0ed1e6afc41d5fdef Mon Sep 17 00:00:00 2001 From: sascha Date: Wed, 13 Mar 2024 07:39:43 +0000 Subject: [PATCH] wildcard in gremlin --- gremlin/.venv/pyvenv.cfg | 2 +- gremlin/gremlin.py | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/gremlin/.venv/pyvenv.cfg b/gremlin/.venv/pyvenv.cfg index e5dd695..0537ffc 100644 --- a/gremlin/.venv/pyvenv.cfg +++ b/gremlin/.venv/pyvenv.cfg @@ -1,3 +1,3 @@ -home = /home/sascha/cs50/froshims/.venv/bin +home = /usr/bin include-system-site-packages = false version = 3.10.12 diff --git a/gremlin/gremlin.py b/gremlin/gremlin.py index dfd2302..f8a0875 100644 --- a/gremlin/gremlin.py +++ b/gremlin/gremlin.py @@ -1,26 +1,24 @@ import mysql.connector -# Establish a connection to the database connection = mysql.connector.connect( host="server1.home", user="sascha", password="mgltoJtmmDnKJ86LltsGdw", database="regulus" ) - -# Create a cursor object to execute SQL queries db = connection.cursor() -# Example query -db.execute('SELECT AccountName,Street,City,ZIP FROM Accounts LIMIT 100') +while True: + account_search = input("AccountName?: ") + if account_search == "": break + + query = 'SELECT AccountName,Street,City,ZIP FROM Accounts WHERE AccountName LIKE "%' + account_search + '%";' -# Fetch the results -accounts = db.fetchall() + db.execute(query) + accounts = db.fetchall() -# Process the results -for account in accounts: - print(account) + for account in accounts: + print(account) -# Close the cursor and connection db.close() connection.close() \ No newline at end of file