-
-
- def insert(self, table, columns,values):
- """
- Inserts data (values) into the columns of the specified table.
-
- """
- mark = self.cursor()
- statement = "INSERT INTO " + table + \
- "(" + ",".join(columns) + ") " + \
- "VALUES(" + ", ".join(values) + ");"
-
- mark.execute(statement)
- self.connection.commit()
- mark.close()
- self.close()
- return
-
- #def insert_slab_slice(self, person_rec):
- #"""
- #Inserts information about a user and his slice into the slice table.
-
- #"""
- #sfatable = SfaTable()
- #keys = slice_table.keys()
-
- ##returns a list of records from the sfa table (dicts)
- ##the filters specified will return only one matching record, into a list of dicts
- ##Finds the slice associated with the user (Senslabs slices hrns contains the user hrn)
-
- #userrecord = sfatable.find({'hrn': person_rec['hrn'], 'type':'user'})
- #slicerec = sfatable.find({'hrn': person_rec['hrn']+'_slice', 'type':'slice'})
- #if slicerec :
- #if (isinstance (userrecord, list)):
- #userrecord = userrecord[0]
- #if (isinstance (slicerec, list)):
- #slicerec = slicerec[0]
-
- #oar_dflt_jobid = -1
- #values = [ str(oar_dflt_jobid), ' \''+ str(slicerec['hrn']) + '\'', str(userrecord['record_id']), str( slicerec['record_id'])]
-
- #self.insert('slice_senslab', keys, values)
- #else :
- #logger.error("Trying to import a not senslab slice")
- #return
-
-
- def update(self, table, column_names, values, whereclause, valueclause):
- """
- Updates a record in a given table.
-
- """
- #Creates the values string for the update SQL command
- vclause = valueclause
- if len(column_names) is not len(values):
- return
- else:
- valueslist = []
- valuesdict = dict(zip(column_names,values))
- for k in valuesdict.keys():
- valuesdict[k] = str(valuesdict[k])
- #v = ' \''+ str(k) + '\''+ '='+' \''+ valuesdict[k]+'\''
- v = str(k) + '=' + valuesdict[k]
- valueslist.append(v)
- if isinstance(vclause,str):
- vclause = '\''+ vclause + '\''
- statement = "UPDATE %s SET %s WHERE %s = %s" % \
- (table, ", ".join(valueslist), whereclause, vclause)
- print>>sys.stderr,"\r\n \r\n SLABPOSTGRES.PY update statement %s valuesdict %s valueslist %s" %(statement,valuesdict,valueslist)
- mark = self.cursor()
- mark.execute(statement)
- self.connection.commit()
- mark.close()
- self.close()
-
- return
-
- #def update_senslab_slice(self, slice_rec):
- #sfatable = SfaTable()
- #hrn = str(slice_rec['hrn'])
- #userhrn = hrn.rstrip('_slice')
- #userrecord = sfatable.find({'hrn': userhrn, 'type':'user'})
- #print>>sys.stderr, " \r\n \r\n \t SLABPOSTGRES.PY update_senslab_slice : userrecord %s slice_rec %s userhrn %s" %( userrecord, slice_rec, userhrn)
- #if (isinstance (userrecord, list)):
- #userrecord = userrecord[0]
- #columns = [ 'record_id_user', 'oar_job_id']
- #values = [slice_rec['record_id_user'],slice_rec['oar_job_id']]
- #self.update('slice',columns, values,'record_id_slice', slice_rec['record_id_slice'])
- #return
-
-
- def find(self, tablename,record_filter = None, columns=None):
- print>>sys.stderr, " \r\n \r\n \t SLABPOSTGRES.PY find : record_filter %s %s columns %s %s" %( record_filter , type(record_filter),columns , type(columns))
- if not columns:
- columns = "*"
- else:
- columns = ",".join(columns)
- sql = "SELECT %s FROM %s WHERE True " % (columns, tablename)