in framework/resources/Functional/odbcTest.py [0:0]
def GetJSONFileAndExecSingleQuery(queryDir, singleFile):
# find the json file for the query file
json_files = glob.glob("%s/*.json" % queryDir)
if not json_files:
# look in parent directory for a json file
updir = ""
while not json_files:
updir = "%s/.." % updir
json_files = glob.glob("%s%s/*.json" % (queryDir, updir))
for json_file in json_files:
queryFile, queryFileExt, expectedFile, expectedFileExt, schema, \
outputFileExt = ParseJSONFile(json_file)
# execute query file
if queryFileExt:
# get query files that match query file extension
if fnmatch.fnmatch(singleFile, '*%s' % queryFileExt):
# execute SQL statement to "use" the schema specified by
# the JSON file
try:
value = cursor.execute("use `%s`" % schema)
except:
print "execute error for schema"
raise RuntimeError('cannot use schema %s' % schema)
#extract query file name from singleFile, which has absolute path
queryFileRegex = re.compile(".*/(.*)$")
queryFileRegexSearch = queryFileRegex.search(singleFile)
queryFile = queryFileRegexSearch.group(1)
ExecuteQuery(queryDir, queryFile, outputFileExt, resultFileCreated)
else:
# if there is no query file extension, then there is a specific
# query file specified in the json file. check if file specified in json
# file matches the file requested by user. if so, then execute the requested
# file using the information in this json file
if singleFile == '%s/%s' % (queryDir,queryFile):
# execute SQL statement to "use" the schema specified by
# the JSON file
try:
value = cursor.execute("use `%s`" % schema)
except:
print "execute error for schema"
raise RuntimeError('cannot use schema %s' % schema)
ExecuteQuery(queryDir, queryFile, outputFileExt, resultFileCreated)