Re: SFieldBooleanChar doesn't seem to work with MySQL
Anthony & Melissa Berglas <[email protected]> Mon, 12 Jan 2009 10:59:30 +1000
| Newsgroups | gmane.comp.java.orm.simpleorm |
|---|---|
| Message-ID | <[email protected]> |
You found a bug.
The bug is that no max size is specified for that VARCHAR. Some dbs accept this with sensible defaults (no limit) others with stupid defaults (1 char) others reject. I have fixed it in the Subversion repostitory -- code below.
@Override
public String defaultSqlDataType() {
int size=TRUE_VALUE.length() > FALSE_VALUE.length() ? TRUE_VALUE.length() : FALSE_VALUE.length();
return "VARCHAR(" + size + ")";
}
SFieldBooleanFixedChar is not a good fix IMHO. CHAR is slightly more efficient on some dbs than VARCHAR for short strings, but it also causes compatibility problems that I would prefer to avoid.
(Actually, your max code is slightly neater now I look at it again.)
Thanks for pointing this out.
Anthony
At 03:48 PM 29/12/2008, you wrote:
>SFieldBooleanChar's defaultSqlDataType() method returns "VARCHAR",
>which doesn't work with MySQL when creating a table.
>
>I'm using this as a workaround:
>
>class SFieldBooleanFixedChar extends SFieldBooleanChar {
>private int length;
>
>public SFieldBooleanFixedChar(SRecordMeta<?> meta, String colName,
>String tval, String fval, SFieldFlags... flags) {
>super(meta, colName, tval, fval);
>length = Math.max(tval.length(), fval.length());
>}
>
>@Override
>public String defaultSqlDataType() {
>return String.format("CHAR(%d)", length);
>}
>}
>
>Is this a bug, or should I be doing something differently? Please advise.
>
>Congratulations on SimpleORM, I'm liking it very much so far.
>
>Best regards,
>Frederic Daoud
>Author, "Stripes ...and Java Web Development is Fun Again"
><http://www.pragprog.com/titles/fdstr>http://www.pragprog.com/titles/fdstr
>
>
Spreadsheet Detective,
Southern Cross Software Queensland Pty Limited
54 Gerler Street
Bardon, Queensland 4065, Australia.
Email: [email protected]
www.SpreadsheetDetective.com
Ph: +61 427 830248 (Australian Eastern Standard Time)
"If the model seems correct only because the numbers look right,
then why build the model in the first place?"
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/SimpleORM/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/SimpleORM/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[email protected]
mailto:[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
558fcf9f.jpg
(image/jpeg, 3.3 KB) - not displayed