Developers Manual 1.20

4. Customising ReStore for Individual Databases

4.5 Other Customisations

There are a number of other customisation options available via SSWSQLDialect. Some of these are essential to allow certain databases to operate correctly, others provide optional behaviour which allow you to tune exactly how ReStore relates to your database. You may change these options either by directly modifying the configuration initialization method, or by setting them manually in your application code after login, e.g.

reStore dsn: 'MyDatabase'.
reStore connect.
reStore sqlDialect
        trueObject: 'Y';
        falseObject: 'N'

Some of the more significant customisations are discussed below; browse the accessing method category of SSWSQLDialect for more. Should you have any specific queries about using any of the available customisations, please contact us for further information. 

 

nameTransformer
By default, when translating a class name to an instance variable name ReStore performs translations as follows:

Smalltalk Name Database Name
Customer CUSTOMER
        surname SURNAME
        firstName FIRST_NAME
StockItem STOCK_ITEM
        title TITLE
        numberInStock NUMBER_IN_STOCK

This translation is controlled by the SSWSQLDialect instance variable nameTransformer which stores a monadic valuable (a one-argument block or a unary message) that is evaluated with the class or instance variable name (a Symbol). In the standard configuration, this is set to send the unary message sswInUnderscoreFormat. You may want or need to change this behaviour for your own database - for example, PostgreSQL prefers lowercase names. By changing the value of nameTransformer any reasonable translation can be accomplished - some possibilities are shown below:

nameTransformer Smalltalk Name Database Name
Message selector: #asString Customer Customer
  firstName firstName
Message selector: #asUppercase Customer CUSTOMER
  firstName FIRSTNAME
[ :name | name sswInUnderscoreFormat asLowercase] Customer customer
  firstName first_name

 

trueObject and falseObject
For most databases, whether they support an explicit BOOLEAN column type or use an INTEGER, the standard representation of Booleans is via numbers: 1 for true and 0 for false. The translation between Smalltalk Boolean objects and their database representation is defined by the SSWSQLDialect instance variables trueObject and falseObject - each holds the database representation of the corresponding Boolean. By replacing the default contents with another object, different objects can be used. For example, you may want/require to store Booleans in the database as Strings (say for better integration with a reporting tool) - 'Y' for true and 'N' for false. This can be easily accomplished by setting trueObject and falseObject accordingly, and changing the #boolean entry in the datatypes Dictionary to 'CHAR(1)'.

 

shouldMapEmptyStringsToNil
Certain databases (including MS Access) allow columns holding Strings to have a particular rule applied, governing whether an empty String is a valid object to be held in that column. Unfortunately, there is no standard way to change this rule via ODBC and SQL, hence if this rule is 'on' by default (as is the case with Access) this can lead to errors when using ReStore.

To overcome this, SSWSQLDialect provides the instance variable shouldMapEmptyStringsToNil. By default, this is set to false, and empty Strings are stored as empty Strings within the database. For databases with the 'Do not allow empty Strings' rule, you should set shouldMapEmptyStringsToNil to true - if this is the case, ReStore will automatically translate empty Strings to nil when committing your transaction, avoiding potential database errors. 


4. Customising ReStore for Individual Databases

© 2000-2003 Solutions Software Ltd.

Home | Index