Beispiel #1
0
def updateItem(table, index, dict, globals):
	'''
	Use the items in a dictionary to update an SQL table entry.
	'''
	fullDict = {}
	for k, v in dict.iteritems():
		fullDict[k.replace('-', '_')] = v	  
	row_id = sqlbackend.assignment_list(['row_id'], globals['backend'])
	l = sqlbackend.assignment_list(fullDict.keys(), globals['backend'])
	query = ', '.join(l)
	command = 'UPDATE %s SET %s WHERE %s' % (table, query, row_id[0])
	fullDict['row_id'] = index
	cursor = globals['cursor']
	cursor.execute(command, fullDict)
Beispiel #2
0
def getTableItem(table, idDict, globals):
	l = sqlbackend.assignment_list(idDict.keys(), globals['backend'])
	query = ' AND '.join(l)
	command = "SELECT * FROM %s WHERE %s" % (table, query)
	cursor = globals['cursor']
	cursor.execute(command, idDict)
	result = cursor.fetchone()
	if not result:
		return None
	desc = dtuple.TupleDescriptor(map(lambda x: (string.lower(x[0]),) + x[1:],
									  cursor.description))
	dt = dtuple.DatabaseTuple(desc, result)
	return dt