Research has shown that the type values correspond to various types of message, as you might expect. For simplicity we will deal with just three of the 61 = ‘Text Message’, 53 = ‘Contact Blocked’ and 30 = ‘Start Voice Call’. So back to our SQL CASE expression.
The SQLite user manual shows that a case expression has the following form:
CASE expr WHEN expr THEN expr WHEN expr ELSE expr END
A real-world example will hopefully make this clearer
CASE Messages.type WHEN 53 THEN ‘Contact Blocked’ WHEN 61 THEN ‘Text Message’ WHEN 30 THEN ‘Start Voice call’ ELSE Messages.type END AS MsgType,
The example above compares the Messages.Type field to each of the three supplied values in the WHEN part of the expression and if they match then they are replaced by the value in the THEN part of the expression which in our case are quoted string values. So 53 will be replaced by ‘Contact blocked’ 61 by ‘Text Message’ etc. (*you can supply more than 3 WHEN expressions).
The final ELSE part of the expression is important as it instructs SQLite what to do if a type value is found which isn’t coded into our expression. We could use ELSE ‘Unknown’ which would display unknown for every type value that isn’t 53, 61 or 30 but this potentially hides evidence so by using table.fieldname again we can display the actual value. The table below shows this more clearly.