Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use LEN for String.length instead of CHAR_LENGTH for SQLServer. Fixes
- Loading branch information
1 parent
f57f6cc
commit 7f7fa34
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/main/java/org/datanucleus/store/rdbms/sql/method/StringLengthMethod4.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/********************************************************************** | ||
Copyright (c) 2016 Andy Jefferson and others. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
Contributors: | ||
... | ||
**********************************************************************/ | ||
package org.datanucleus.store.rdbms.sql.method; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.datanucleus.exceptions.NucleusException; | ||
import org.datanucleus.store.rdbms.mapping.java.JavaTypeMapping; | ||
import org.datanucleus.store.rdbms.sql.expression.IntegerLiteral; | ||
import org.datanucleus.store.rdbms.sql.expression.NumericExpression; | ||
import org.datanucleus.store.rdbms.sql.expression.ParameterLiteral; | ||
import org.datanucleus.store.rdbms.sql.expression.SQLExpression; | ||
import org.datanucleus.store.rdbms.sql.expression.StringExpression; | ||
import org.datanucleus.store.rdbms.sql.expression.StringLiteral; | ||
import org.datanucleus.util.Localiser; | ||
|
||
/** | ||
* Expression handler to evaluate {stringExpression}.length(). | ||
* Returns a NumericExpression <pre>LEN({stringExpr})</pre>. | ||
*/ | ||
public class StringLengthMethod4 extends AbstractSQLMethod | ||
{ | ||
/* (non-Javadoc) | ||
* @see org.datanucleus.store.rdbms.sql.method.SQLMethod#getExpression(org.datanucleus.store.rdbms.sql.expression.SQLExpression, java.util.List) | ||
*/ | ||
public SQLExpression getExpression(SQLExpression expr, List<SQLExpression> args) | ||
{ | ||
if (!expr.isParameter() && expr instanceof StringLiteral) | ||
{ | ||
JavaTypeMapping m = exprFactory.getMappingForType(int.class, false); | ||
String val = (String)((StringLiteral)expr).getValue(); | ||
return new IntegerLiteral(stmt, m, Integer.valueOf(val.length()), null); | ||
} | ||
else if (expr instanceof StringExpression || expr instanceof ParameterLiteral) | ||
{ | ||
ArrayList funcArgs = new ArrayList(); | ||
funcArgs.add(expr); | ||
return new NumericExpression(stmt, getMappingForClass(int.class), "LEN", funcArgs); | ||
} | ||
else | ||
{ | ||
throw new NucleusException(Localiser.msg("060001", "length", expr)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7f7fa34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you watching my build output? 😆
I just wanted to report that issue. Are you testing MSSQL support currently? I got some other issues if you want. Just tell me and I'll write up an email or create separate issues if you want.
7f7fa34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Not aware of your build output, where is it?
I had it reported a couple of weeks ago by a user, but haven't been able to do it til this weekend. Not aware of anything else on SQLServer so if you have problems, report them. But be aware that I don't have that database so cannot test it ;-)
7f7fa34
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well you should try out the linux docker image for SQL Server 2016. Good enough for testing.
I will create issues but here is the output if you are interested: https://travis-ci.org/Blazebit/blaze-persistence/jobs/179432801