37 lines
925 B
Python
37 lines
925 B
Python
# Nick Alvarez, CS 657, PA2, Spring 21
|
|
# Python 3.7+ required.
|
|
|
|
# Utility file for input sanitizing, existence checks
|
|
|
|
import os
|
|
import shlex
|
|
import subprocess
|
|
|
|
def inputCleaner(wordToRemove, UserQuery): # Removes ; and command
|
|
query = UserQuery.replace(";", "")
|
|
return query.replace(wordToRemove, "")
|
|
|
|
def databaseExistenceCheck(db): # Checks if database exists
|
|
if db in subprocess.run(['ls', '|', 'grep', db], capture_output=True, text=True).stdout:
|
|
return 1
|
|
else:
|
|
return 0
|
|
|
|
def tableExistenceCheck(t, workingDB): # Checks if table exists
|
|
if t in subprocess.run(['ls', workingDB, '|', 'grep', t], capture_output=True, text=True).stdout:
|
|
return 1
|
|
else:
|
|
return 0
|
|
|
|
# Determines operand and assigns value
|
|
def getOperand(o):
|
|
operand = None
|
|
if (o == '='):
|
|
operand = 0
|
|
elif (o == '<'):
|
|
operand = -1
|
|
elif (o == '>'):
|
|
operand = 1
|
|
elif (o == '!='):
|
|
operand = -3
|
|
return operand |