425
425
def get_problem_problemid(self, exercisename, dry=False):
426
426
"""Given an exercise name, returns the associated problemID.
428
Raises a DBException if the login is not found in the DB.
427
If the exercise name is NOT in the database, it inserts it and returns
428
the new problemID. Hence this may mutate the DB, but is idempotent.
430
d = self.get_single({"identifier": exercisename}, "problem",
431
['problemid'], frozenset(["identifier"]),
432
error_notfound="get_problem_problemid: No exercise with that name",
435
return d # Query string
431
d = self.get_single({"identifier": exercisename}, "problem",
432
['problemid'], frozenset(["identifier"]),
435
return d # Query string
438
# Shouldn't try again, must have failed for some other reason
440
# if we failed to get a problemid, it was probably because
441
# the exercise wasn't in the db. So lets insert it!
443
# The insert can fail if someone else simultaneously does
444
# the insert, so if the insert fails, we ignore the problem.
446
self.insert({'identifier': exercisename}, "problem",
447
frozenset(['identifier']))
451
# Assuming the insert succeeded, we should be able to get the
453
d = self.get_single({"identifier": exercisename}, "problem",
454
['problemid'], frozenset(["identifier"]))
436
456
return d['problemid']
438
def insert_problem(self, exercisename, dry=False):
439
"""Inserts a new problem in the problem table, with the given
442
return self.insert({'identifier': exercisename}, "problem",
443
frozenset(['identifier']), dry=dry)
445
458
def insert_problem_attempt(self, problemid, loginid, date, complete,
446
459
attempt, dry=False):
447
460
"""Inserts the details of a problem attempt into the database.