Thursday, May 9, 2013

9 May

Today is Victory Day in Russia, so we need to add some plot in the quiz.

Marshal Zhukov has a database that helps him to fight. It contains "tank_types" relation that looks like this:
 name | secret_name | ...
------+-------------+-----
 T-28 | UQCFIQUGCVA | ...
 T-34 | JBHVCAIOAOA | ...
 T-45 | NVFAFOEAGQF | ...
 ...  | ...         | ...
Of course both "name" and "secret name" are unique and have corresponding constraints.

Every day Stalin emails the list of new secret names for some tank types. All data in emails is always valid. Zhukov orders one of his officers to write a script that helps him renew data in the database according to daily emails.

The officer runs vim and write the following ruby script:
data = Email.new('...').get_data
data.each do |name, secret_name|
  query(
    'UPDATE tank_types SET secret_name = ? WHERE name = ?',
    secret_name, name
  )
end
Checking this script Zhukov immediately sees a problem that it may cause. What's a problem? How to fix that?

No comments:

Post a Comment