If the solution query fails, the result column can be set to NULL. When the column is NULL, the output message is NULL.
Our test files use the following to format the test message.
-- Update message for failed tests to give helpful information:
UPDATE tests
SET message = 'Result for "' || tests.moment || '" is "' || actual.result || '", but should be "' || tests.result || '"'
FROM (SELECT moment, result FROM gigasecond) AS actual
WHERE actual.moment = tests.moment AND tests.status = 'fail';
For example, with a NULL column:
sqlite> SELECT 'Result for "' || tests.moment || '" is "' || actual.result || '", but should be "' || tests.result || '"' FROM gigasecond AS actual INNER JOIN
tests WHERE tests.moment = actual.moment LIMIT 1;
| 'Result for "' || tests.moment || '" is "' || actual.result || '", but should be "' || tests.result || '"' |
|------------------------------------------------------------------------------------------------------------|
| |
Proposal: change NULL to "<NULL>":
UPDATE gigasecond SET result = '<NULL>' WHERE result IS NULL;
If we add something like that to our test files, then the formatting works.
sqlite> SELECT 'Result for "' || tests.moment || '" is "' || actual.result || '", but should be "' || tests.result || '"' FROM gigasecond AS actual INNER JOIN
tests WHERE tests.moment = actual.moment LIMIT 1;
| 'Result for "' || tests.moment || '" is "' || actual.result || '", but should be "' || tests.result || '"' |
|------------------------------------------------------------------------------------------------------------|
| Result for "2011-04-25" is "<NULL>", but should be "2043-01-01T01:46:40" |
One alternative would be to use a conditional IF result IS NULL but it is too late at night for me to figure out that syntax. Pros: doesn’t update the table. Cons: more complex.
Ah, I got the issue. So we update to <NULL> for display reasons.
I like it for readability. I am not sure if that would be confusing for “real sql” devs? Is there someone deep into the language who could drop in?
Opposed to using … "NULL" over "\<NULL\>" in the error message? Or opposed to using an empty string? Or sticking with an actual NULL value and not displaying anything?
I support the proposal, but I would like to hear someones opinion who actually works with SQL, as I am just a hack who made that language work with the Exercism test runner without every using it an a real context
… you realize that people who “really work with SQL” aren’t doing all the wacky things we do with it in Exercism, right? Is the concern that the string "\<NULL\>" would be confusing when the actually value is a NULL value?
It’s about 10am currently so … let’s not modify the student’s test results table
The reporting expression:
...
SET message = 'Result for "'
|| tests.moment
|| '" is "'
- || actual.result
+ || (CASE WHEN actual.result IS NULL THEN "<NULL>" ELSE actual.result END)
|| '", but should be "'
|| tests.result
|| '"' FROM gigasecond AS actual
INNER JOIN
tests WHERE tests.moment = actual.moment
...