from .database_connector import DatabaseConnector


class Jobs(DatabaseConnector):
    WAITING = 0
    RUNNING = 1
    FINISHED = 2

    def update_output(self, jobid, stdout, stderr):
        self.cursor.execute('update jobs set stdout=%s, stderr=%s, status=2 where jobid=%s',
                            (stdout, stderr, str(jobid)))
        self.connect.commit()

    def insert_job(self, userid, filename):
        self.cursor.execute('insert into jobs (userid,filename,status) values (%s,%s,0)', (str(userid), filename))
        self.connect.commit()
        return self.cursor.lastrowid

    def jobs_of_userid(self, userid):
        self.cursor.execute('select * from jobs where userid=%s', (str(userid),))
        rows = self.cursor.fetchall()
        return rows

    def delete_job(self, jobid):
        self.cursor.execute('delete from jobs where jobid=%s', (str(jobid),))
        self.connect.commit()

    def status_of(self, jobid):
        self.cursor.execute('select status from jobs where jobid=%s limit 1', (str(jobid),))
        rows = self.cursor.fetchone()
        return rows[0]

    def fetch_job(self, jobid):
        self.cursor.execute('select * from jobs where jobid=%s limit 1', (str(jobid),))
        return self.cursor.fetchone()

    def start_job(self, jobid):
        self.cursor.execute('update jobs set status=1 where jobid=%s', (str(jobid),))

@@ -252,17 +252,18 @@
  status=
-2
+%25s
  where j
@@ -322,19 +322,29 @@
 r, s
-tr(
+elf.FINISHED, 
 jobid))
-)
 %0A   
@@ -505,28 +505,23 @@
 %25s,0)', 
-(str
 (userid
-)
 , filena
@@ -701,20 +701,15 @@
 s', 
-(str
 (userid
-)
 ,))%0A
@@ -859,35 +859,30 @@
  jobid=%25s', 
-(str
 (jobid
-)
 ,))%0A        
@@ -1010,35 +1010,30 @@
 s limit 1', 
-(str
 (jobid
-)
 ,))%0A        
@@ -1191,27 +1191,22 @@
 mit 1', 
-(str
 (jobid
-)
 ,))%0A    
@@ -1347,19 +1347,14 @@
 s', 
-(str
 (jobid
-)
 ,))%0A

Remove str