Beispiel #1
0
def index(request):
    #overview
    resultTitle=["enzymeId","substrateName","productName",]
    
    #fetch data
    import MySQLdb
    import util.dbOperator as dbor
    from properties import dbProperties
    dbConn = MySQLdb.connect(host=dbProperties["dbHost"],user=dbProperties["dbUser"],passwd=dbProperties["dbPw"],db="enzymetib",charset='utf8')
    dbCursor = dbConn.cursor()
    
    tableName="enzyme"
    fieldNameArray=resultTitle
    parameterDic={}
    sqlString="select distinct "+(",".join(fieldNameArray))+" from "+tableName
    if (parameterDic):
        parameterData=[]
        parameterTitle=[]
        for k,v in parameterDic.iteritems():
            parameterData.append(v)
            parameterTitle.append(k)
        sqlString=sqlString+" where ("+(",".join(parameterTitle))+")=('"+("','".join(parameterData))+"')"
    #logger.debug(sqlString)
    
    sqlResultData,sqlResultCount=dbor.sqlSelect(sqlString,dbCursor)
    #logger.debug(sqlResultCount)

    dbConn.close()
    #return sqlResultData,sqlResultCount

    resultData,resultCount=sqlResultData,sqlResultCount
    #resultData,resultCount=selectData("enzyme",resultTitle,{})
    
    return render(request, os.path.join(htmlFolderPath,'index.html').replace('\\', '/'),locals())
Beispiel #2
0
def selectData(tableName,fieldNameArray,parameterDic):
    #prepare db
    import util.dbOperator as dbor
    dbConn,dbCursor=dbor.prepareDb()
    
    #fetch data
    sqlString="select distinct "+(",".join(fieldNameArray))+" from "+tableName
    if (parameterDic):
        parameterData=[]
        parameterTitle=[]
        for k,v in parameterDic.iteritems():
            parameterData.append(v)
            parameterTitle.append(k)
        sqlString=sqlString+" where ("+(",".join(parameterTitle))+")=('"+("','".join(parameterData))+"')"
#     logger.debug(sqlString)
    
    sqlResultData,sqlResultCount=dbor.sqlSelect(sqlString,dbCursor)
#     logger.debug(sqlResultCount)
    #close
    dbConn.close()
    return sqlResultData,sqlResultCount