Пример #1
0
def evaluateQuery(query,cltAddr):#sumanth
	#evaluates a query supplied as a string in the format specified in the readme file
	try:
		global t_p
		global sFlag
		global clientAddr
		clientAddr = cltAddr
		t = []
		tableName = ""
		fileName = ""
		global prevTableName
		columnList = []
		operatorList = []
		valueList = []
		rs = []
		tp = tuple()
		d = []
		exceptionFileHandler = open("exceptionLog.txt","a")	
		tableName = parser.getTableName(query)
		dictionary.getClst(query,"dev_db_tables/"+tableName+".txt")
		t = parser.getColumnName(query)
		
		if tableName != None:
			fileName = "dev_db_tables/"+tableName+".txt"
			if t_p == () or prevTableName != tableName:
				prevTableName = tableName
				tp = dictionary.createTable(fileName)
				t_p = tp
				sFlag = True
			else:
				tp = t_p
			d = tp[0]
			if (t[1] != []) and (t[2] != []):
				columnList = t[0]
				operatorList = t[1]
				valueList = t[2]
				if parser.read == True and parser.select == False:
						rs = read(tableName, columnList, operatorList, valueList,d)
						rs = evalOpnd.eval(rs,query)
						if rs != []:
							dictionary.printTable(rs)
							return rs
						else:
							raise Exception("Null set")
				elif parser.read == True and parser.select == True:
						rs = read(tableName, columnList, operatorList, valueList,d)
						rs = evalOpnd.eval(rs,query)
						if rs != []:
							rs = dictionary.printSelect(query,rs)
							dictionary.printTable(rs)
							return rs
						else:
							raise Exception("Null set")

				elif parser.write == True:
						ret = write(tableName, columnList, operatorList, valueList,d,tp[1])
						if ret:
							return ret
				
				elif parser.delete == True:
						delete(tableName, columnList, operatorList, valueList,d,tp[1])
						
			elif parser.write == False and parser.delete == False:
				if d != []:
					d = evalOpnd.eliminateDuplicate(d)
					dictionary.printTable(d)
					return d
				elif sFlag == False:
					dictionary.printSchema(tp[1])
				elif sFlag == True:
					print "New table created\n------------------"
					dictionary.printSchema(tp[1])
					sFlag = False
			else:
				raise Exception("error: Invalid syntax for (write|delete)")

	except IOError as e:
			exceptionFileHandler.write(time.ctime()+",FROM = "+str(clientAddr)+","+"query = "+query+",\t"+tableName+".txt: no such file found to load the table from\n")
			print "error: No such table found"
			return 'error: No such table found'
	except Exception as e:
			exceptionFileHandler.write(time.ctime()+",FROM = "+str(clientAddr)+","+"query = "+query+",\t"+str(e)+"\n")
			print e
			return str(e)
def evaluateQuery(query):
	#evaluates a query supplied as a string in the format specified in the readme file
	try:
		global t_p
		t = []
		tableName = ""
		fileName = ""
		global prevTableName
		columnList = []
		operatorList = []
		valueList = []
		rs = []
		tp = tuple()
		d = []
		tableName = parser.getTableName(query)
		dictionary.getClst(query,tableName+".txt")
		t = parser.getColumnName(query)
		
		if tableName != None:
			fileName = tableName+".txt"
			if t_p == () or prevTableName != tableName:
				prevTableName = tableName
				tp = dictionary.createTable(fileName)
				t_p = tp
			else:
				tp = t_p
			d = tp[0]
			if (t[1] != []) and (t[2] != []):
				columnList = t[0]
				operatorList = t[1]
				valueList = t[2]
				if parser.read == True and parser.select == False:
						rs = read(tableName, columnList, operatorList, valueList,d)
						rs = evalOpnd.eval(rs,query)
						if rs != []:
							dictionary.printTable(rs)
							return rs
						else:
							raise Exception("Null set")
				elif parser.read == True and parser.select == True:
						rs = read(tableName, columnList, operatorList, valueList,d)
						rs = evalOpnd.eval(rs,query)
						if rs != []:
							dictionary.printSelect(query,rs)
							return rs
						else:
							raise Exception("Null set")

				elif parser.write == True:
						write(tableName, columnList, operatorList, valueList,d,tp[1])
				
				elif parser.delete == True:
						delete(tableName, columnList, operatorList, valueList,d,tp[1])
						
			elif parser.write == False and parser.delete == False:
				if d != []:
					dictionary.printTable(evalOpnd.eliminateDuplicate(d))
				else:
					print "New table created\n------------------"
					dictionary.printSchema(tp[1])

			else:
				raise Exception("error: Invalid syntax for (write|delete)")

	except IOError as e:
			print "error: No such table found"
			exceptionFileHandler = open("exceptionLog.txt","a")
			exceptionFileHandler.write(time.asctime()+","+str(e)+"\n")	#fatal exception being printed to a separate file
			exceptionFileHandler.close()
	except Exception as e:
			print e
			exceptionFileHandler = open("exceptionLog.txt","a")
			exceptionFileHandler.write(time.asctime()+","+str(e)+"\n")	#fatal exception being printed to a separate file
			exceptionFileHandler.close()
Пример #3
0
def evaluateQuery(query):
    #evaluates a query supplied as a string in the format specified in the readme file
    try:
        global t_p
        t = []
        tableName = ""
        fileName = ""
        global prevTableName
        columnList = []
        operatorList = []
        valueList = []
        rs = []
        tp = tuple()
        d = []
        tableName = parser.getTableName(query)
        dictionary.getClst(query, tableName + ".txt")
        t = parser.getColumnName(query)

        if tableName != None:
            fileName = tableName + ".txt"
            if t_p == () or prevTableName != tableName:
                prevTableName = tableName
                tp = dictionary.createTable(fileName)
                t_p = tp
            else:
                tp = t_p
            d = tp[0]
            if (t[1] != []) and (t[2] != []):
                columnList = t[0]
                operatorList = t[1]
                valueList = t[2]
                if parser.read == True and parser.select == False:
                    rs = read(tableName, columnList, operatorList, valueList,
                              d)
                    rs = evalOpnd.eval(rs, query)
                    if rs != []:
                        dictionary.printTable(rs)
                        return rs
                    else:
                        raise Exception("Null set")
                elif parser.read == True and parser.select == True:
                    rs = read(tableName, columnList, operatorList, valueList,
                              d)
                    rs = evalOpnd.eval(rs, query)
                    if rs != []:
                        dictionary.printSelect(query, rs)
                        return rs
                    else:
                        raise Exception("Null set")

                elif parser.write == True:
                    write(tableName, columnList, operatorList, valueList, d,
                          tp[1])

                elif parser.delete == True:
                    delete(tableName, columnList, operatorList, valueList, d,
                           tp[1])

            elif parser.write == False and parser.delete == False:
                if d != []:
                    dictionary.printTable(evalOpnd.eliminateDuplicate(d))
                else:
                    print "New table created\n------------------"
                    dictionary.printSchema(tp[1])

            else:
                raise Exception("error: Invalid syntax for (write|delete)")

    except IOError as e:
        print "error: No such table found"
        exceptionFileHandler = open("exceptionLog.txt", "a")
        exceptionFileHandler.write(
            time.asctime() + "," + str(e) +
            "\n")  #fatal exception being printed to a separate file
        exceptionFileHandler.close()
    except Exception as e:
        print e
        exceptionFileHandler = open("exceptionLog.txt", "a")
        exceptionFileHandler.write(
            time.asctime() + "," + str(e) +
            "\n")  #fatal exception being printed to a separate file
        exceptionFileHandler.close()