setReadFormat:
) and the INSERT and UPDATE statement formats to "salary / 12" (setWriteFormat:
). Thus, whenever your application retrieves values for the salary attribute they're multiplied by 12, and when it writes values back to the database they're divided by 12.
Your application can use any legal SQL value expression in a format string, and can even access server-specific features such as functions and stored procedures (see EOEntity's setStoredProcedure:forOperation:
method description for more information). Accessing server-specific features can offer your application great flexibility in dealing with its server, but does limit its portability. You're responsible for ensuring that your SQL is well-formed and will be understood by the database server.
Format strings for the setReadFormat:
and setWriteFormat:
methods should use "%P" as the substitution character for the value that is being formatted. "%@" will not work. For example:
[myAttribute setReadFormat:@"TO_UPPER(%P)"];
[myAttribute setWriteFormat:@"TO_LOWER(%P)"];
Instead of setting the read and write formats programmatically, you can set them in EOModeler, which is more common. For more information, see the chapter "Using EOModeler" in WebObjects Tools and Techniques.