ich muss folgendes realisieren,
einen querypool der mir je nach argumenten die querys zusammenbaut.
Dies hab ich mit python geschrieben. Läuft auch ganz gut nun soll dieser pool auch über perl erreichbar sein, hab das mal über einen Aufruf der commandline gemacht, bin damit aber nocht nicht ganz zufrieden.
Hat jemand von euch eine Idee?
Code: Alles auswählen
import sys
class QueryPool:
"""
If u want to add an new query, just write the name to the caseDict{}
and add an function with self.getArgs(AmountofArgs)at the start
and add an return on the end.
"""
ArgList = []
callByPython = False
def __init__(self, callByPython= False):
"""
Look if sys.argv[1] exists, then call the function
"""
self.callByPython = callByPython
if not self.callByPython:
#sys.argv[1] is the first written argument:
caseDict = { 'test' : self.test }
#Call the Method
try:
query = caseDict[sys.argv[1]]()
print "[query]" +query + "[/query]"
except:
print "error no such query exists"
def getArgs(self, needAmount):
"""
args which wont give will set to None
"""
#called by command line with args
if not self.callByPython:
for i in range(len(sys.argv)):
if i >1:
self.ArgList.append(sys.argv[i])
#SEt the missing args with empty string
while len(self.ArgList)<needAmount:
self.ArgList.append("")
#-----------------------just queries down to this-----------------------
def test(self):
"""
Arg sequence: rows; table;
"""
#get the Args, argument is the maximum amount of used args
self.getArgs(2)
query = "select "+ self.ArgList[0] + " from " + self.ArgList[1]
return query
#called if there are arguments entered by command line
if len(sys.argv)>1:
QueryPool = QueryPool()
#-----------------------end of query class-----------------------
"""
sample how to call it from pyhton
QueryPool = QueryPool(True)
# Set the args in the right sequence, missing args would filled with an empty string
QueryPool.ArgList = ["arg01", "arg02"]
query = QueryPool.test()
print query
"""
"""
sample how to call it from command line
command: test2.py query arg1 arg2
output: [query]select arg1 from arg2 ...[/query]
You have only to split the string to get the query
"""