def getAttrByID(attr: str, ID: int):
     '''
     Retrieves a specified attrubute from an entry of the scriptLog SQL table based on primary key - ID
     @param 
         attr - one of the columns of the scriptLog table
         ID - primary key of scriptLog
     @return 
         e - error created during execution of function or Success if no error occurs
         s - the specified attribute's value from the entry retrieved from the SQL table 
     '''
     val = None
     command = """SELECT (""" + attr + """) FROM sl WHERE ID = """ + str(
         ID) + """;"""
     e, slTuple = sqlFuncs.getRow(command, "getAttrByID", "ScriptLog")
     if (e == pref.getError(pref.ERROR_SUCCESS)):
         if (slTuple == None):
             e = pref.getError(pref.ERROR_SQL_RETURN_MISSING_ATTR,
                               args=("getAttrByID", "ScriptLog", 0, 1))
         elif (len(slTuple) != 1):
             e = pref.getError(pref.ERROR_SQL_RETURN_MISSING_ATTR,
                               args=("getAttrByID", "ScriptLog",
                                     len(slTuple), 1))
         else:
             val = slTuple[0]
     return e, val
    def editEntry(entry: ScriptLog):
        '''
        Updates a row in the scriptLog SQL table based on the entry object passed. 
        Overwrites all attributes of the row with the values of the entry object.
        Overwrites row based on the ID of the entry object.
        @param 
            entry: ScriptLog - ScriptLog object, must have ID != None or error will be thrown
        @return 
            e - most recent error when executing function or Success if no error occurs
            sl - ScriptLog object corresponding to row updated in SQL table. Should be the 
                same as entry passed to function if no error occured
        '''
        sl = entry

        if (entry.ID == None):
            e = pref.getError(pref.ERROR_NO_ID_PROVIDED,
                              args=("editEntry", "ScriptLog"))

        else:
            command = """UPDATE sl SET """
            for attr, value in entry.__dict__.items():
                if (attr == "ID"):
                    pass
                else:
                    command = command + str(attr)
                    if (value == None):
                        command = command + """ = NULL"""
                    elif attr[-4:] == "Time":
                        command = command + """ = """ + """\"""" + str(
                            value.strftime('%Y-%m-%d %H:%M:%S.%f')) + """\""""
                    elif isinstance(value, str):
                        command = command + """ = """ + """\"""" + str(
                            value) + """\""""
                    else:
                        command = command + """ = """ + str(value)
                    command = command + """, """
            command = command[:-2]  #remove last ' ,'
            command = command + """ WHERE ID = """ + str(entry.ID) + """;"""

            e = sqlFuncs.exeCommand(command, "editEntry", "ScriptLog")

            if (e == pref.getError(pref.ERROR_SUCCESS)):
                command2 = """SELECT * FROM sl WHERE ID = """ + str(
                    entry.ID) + """;"""
                e, row = sqlFuncs.getRow(command2, "editEntry", "ScriptLog")
                if (e == pref.getError(pref.ERROR_SUCCESS)):
                    e, sl = tupleToScriptLog(row, "editEntry")

        return e, sl
Exemple #3
0
 def getByID(ID: int):
     '''
     Retrieves an entry from the computer SQL table based on primary key - ID
     @param 
         ID - primary key of computer
     @return 
         e - error created during execution of function or Success if no error occurs
         s - the entry retrieved from the SQL table as a Computer object
     '''
     c = None
     command = """SELECT * FROM c WHERE ID = """ + str(ID) + """;"""
     e, cTuple = sqlFuncs.getRow(command, "getByID", "Computer")
     if(e == pref.getError(pref.ERROR_SUCCESS)):
         e, c = tupleToComputer(cTuple, "getByID")
     return e, c
 def getByID(ID: int):
     '''
     Retrieves an entry from the script SQL table based on primary key - ID
     @param 
         ID - primary key of script
     @return 
         e - error created during execution of function or Success if no error occurs
         s - the entry retrieved from the SQL table as a Script object
     '''
     command = """SELECT * FROM s WHERE ID = """ + str(ID) + """;"""
     s = None
     e, scriptTuple = sqlFuncs.getRow(command, "getByID", "Script") 
     if(e == pref.getError(pref.ERROR_SUCCESS)):
         e, s = tupleToScript(scriptTuple, "getByID")
     return e, s
 def getByID(ID: int):
     '''
     Retrieves an entry from the scriptLog SQL table based on primary key - ID
     @param 
         ID - primary key of scriptLog
     @return 
         e - error created during execution of function or Success if no error occurs
         s - the entry retrieved from the SQL table as a ScriptLog object
     '''
     sl = None
     command = """SELECT * FROM sl WHERE ID = """ + str(ID) + """;"""
     e, slTuple = sqlFuncs.getRow(command, "getByID", "ScriptLog")
     # Also check error is pref.success
     if (e == pref.getError(pref.ERROR_SUCCESS)):
         e, sl = tupleToScriptLog(slTuple, "getByID")
     return e, sl