|
4. Customising ReStore for Individual Databases
4.3 Messages and Functions
A powerful aspect of ReStore's querying functionality is the ability to substitute SQL functions for Smalltalk messages. Whilst it is not strictly necessary to implement any of these mappings, their availability does make querying more efficient, and so it is worthwhile reading up on the SQL functions supported by your database and how they may be related to base-class (String, Number, Date...) messages.
Defining Messages
An instance of SSWSQLDialect stores its message<>function mappings in a Dictionary, stored in the instance variable functions. This simply maps the Smalltalk message name (a Symbol) to the equivalent SQL function text (a String), e.g.functions
at: #asUppercase put: 'UPPER(%1)';
at: #, put: '(%1 || %2)';
at: #midString:from: put: 'SUBSTRING(%1 FROM %3 FOR %2)';The most important thing to note here is the use of parameter placeholders (%1, %2 etc.) in the SQL function text. The first parameter (%1) refers to the receiver of the Smalltalk message; %2 refers to the first argument, %3 to the second argument, and so on.
String Concatenation
A common message to make available in querying is , - the String concatenation message. Unfortunately there are at least three commonly-used but different SQL equivalents, and so this is a good place to begin customising messages for your database:"Default (ANSI standard)"
at: #, put: '(%1 || %2)'"MS Access"
at: #, put: '(%1 + %2)';"MySQL"
at: #, put: 'CONCAT (%1,%2)';"Another possibility"
at: #, put: 'CONCATENATE (%1,%2)';
Further messages
The best approach to adding further message<>function mappings is to take a look at the standard initialization and the supplied modification methods for Access and MySQL:
initializeStandard
modifyForAccess
modifyForMySQL
These encompass a range of String, Date and Number related messages.
4. Customising ReStore for Individual Databases