Solving the symbol-vs-number conundrum
Lassi Kortela 09 Aug 2020 21:29 UTC
We had the nice and simple (make-foreign-status 'symbol x 'number y)
SQLSTATE codes are almost numeric, but some have letters in addition to
digits. These codes are definitely not mnemonic: they look like a jumble
of arbitrary digits and letters. They would have to be represented as a
symbol (or string) in Scheme. But databases also give clear mnemonic
symbols corresponding to these codes: e.g. 'protocol_violation.
So we'd like to put
- the 5-character SQLSTATE jumble '|08P01| into one field
- the mnemonic 'protocol_violation into a second field
- the human-readable message as a string into a third field
SQLSTATE is the only letter/digit code I've found so far; all other
error codes are just integers. (Usually nonnegative; some are negative.)
Since we have only one exception, maybe we should just have:
* 'symbol (mmenonic identifier, always a Scheme symbol)
* 'number (error code, always an exact integer)
* 'sqlstate (special property for SQLSTATE as a Scheme symbol or string)
For SQL errors, the 'number property would simply be #f or missing.
'symbol would be something like 'protocol_violation.