From a4dc9860de1a423f0c376a24e59164310dd2547e Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Wed, 8 Apr 2009 18:52:08 +0000 Subject: [PATCH] Fix index creation for MySQL. --- .../com/samskivert/depot/impl/BuildVisitor.java | 13 ++++++++++--- .../com/samskivert/depot/impl/MySQLBuilder.java | 7 +++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/java/com/samskivert/depot/impl/BuildVisitor.java b/src/java/com/samskivert/depot/impl/BuildVisitor.java index e6688a4..1a05696 100644 --- a/src/java/com/samskivert/depot/impl/BuildVisitor.java +++ b/src/java/com/samskivert/depot/impl/BuildVisitor.java @@ -545,9 +545,7 @@ public abstract class BuildVisitor implements ExpressionVisitor } comma = true; - _builder.append("("); - field.left.accept(this); - _builder.append(")"); + appendIndexComponent(field.left); if (field.right == Order.DESC) { // ascending is default, print nothing unless explicitly descending _builder.append(" desc"); @@ -704,6 +702,15 @@ public abstract class BuildVisitor implements ExpressionVisitor "Persistent field has no definition [class=" + type + ", field=" + field + "]"); } + // output one of potentially many fields in an index expression + protected void appendIndexComponent (SQLExpression expression) + { + // the standard builder wraps each field in its own parens + _builder.append("("); + expression.accept(this); + _builder.append(")"); + } + protected BuildVisitor (DepotTypes types) { _types = types; diff --git a/src/java/com/samskivert/depot/impl/MySQLBuilder.java b/src/java/com/samskivert/depot/impl/MySQLBuilder.java index 153a4c6..e9088af 100644 --- a/src/java/com/samskivert/depot/impl/MySQLBuilder.java +++ b/src/java/com/samskivert/depot/impl/MySQLBuilder.java @@ -140,6 +140,13 @@ public class MySQLBuilder _builder.append(field); } + @Override + protected void appendIndexComponent (SQLExpression expression) + { + // MySQL is never given complex expressions and hates parens, so just recurse + expression.accept(this); + } + protected void renderMatch (FullText fullText) { _builder.append("match(");