Hi,
One little change to avoid NullPointerException's.
Regards,
Fred
2015-03-10 9:24 GMT-03:00 Fred&Dani&Pandora&Aquiles <[email protected]>:
> Hi,
>
> Ok, my bad. One more careful read and I realized my mistake. Anyway, what
> you think of include a default type to the Parameter expression. So, the
> setLimit and setOffset methods could set explicitly the default type to an
> integer in this cases. Well, I'm not sure if the attached patch is the best
> option, but I thought that a change in the related files would be less
> invasive than a change in the Parser (I think).
>
> Regards,
>
> Fred
> Hi,
>
> I agree this is incorrect. A patch is welcome.
>
> However, could you explain what problem you want to solve?
>
> Regards,
> Thomas
>
>
> On Mon, Mar 9, 2015 at 11:20 AM, Vojtěch Hordějčuk <
> [email protected]> wrote:
>
>> update: the same behavior applies to OFFSET ?
>>
>> Dne pondělí 9. března 2015 10:43:32 UTC+1 Vojtěch Hordějčuk napsal(a):
>>
>>> Hi, is this a correct behavior?
>>>
>>> If I prepare statement with a limit statement, e.g. *SELECT * FROM
>>> system_range(1,10) LIMIT ?* and then get the parameter meta data, I
>>> would get VARCHAR as a data type of the limit related placeholder. I am
>>> expecting a numeric data type, because *LIMIT 'abc' *is not a valid
>>> call (AFAIK).
>>>
>>> This is a test case which fails for H2 1.3.171:
>>>
>>> public class BugDemo {
>>> public static void main(String[] args) throws SQLException {
>>> Connection conn = DriverManager.getConnection("jdbc:h2:mem:test");
>>> PreparedStatement stmt = conn.prepareStatement("SELECT * FROM
>>> system_range(1,10) LIMIT ?");
>>> ParameterMetaData pmd = stmt.getParameterMetaData();
>>> System.out.println("type = " + pmd.getParameterTypeName(1)); // =
>>> VARCHAR (expected numeric)
>>> conn.close();
>>> }
>>> }
>>>
>>>
>>>
>>> Workaround:
>>>
>>> just replace "LIMIT ?" with "LIMIT (select id FROM items WHERE id=?)"
>>> where id is INTEGER type
>>>
>>> Thank you for any help or better workaround.
>>> Vojta
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "H2 Database" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/h2-database.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/h2-database.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/fred/NetBeansProjects/h2-trunk/trunk/h2/src/main/org/h2
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: command/dml/Delete.java
--- command/dml/Delete.java Base (BASE)
+++ command/dml/Delete.java Modificado Localmente (Baseado em LOCAL)
@@ -12,6 +12,7 @@
import org.h2.engine.Session;
import org.h2.engine.UndoLogRecord;
import org.h2.expression.Expression;
+import org.h2.expression.Parameter;
import org.h2.result.ResultInterface;
import org.h2.result.Row;
import org.h2.result.RowList;
@@ -151,6 +152,9 @@
}
public void setLimit(Expression limit) {
+ if (limit != null && limit.getType() == Value.UNKNOWN){
+ ((Parameter)limit).setDefaultType(Value.INT);
+ }
this.limitExpr = limit;
}
Index: command/dml/Query.java
--- command/dml/Query.java Base (BASE)
+++ command/dml/Query.java Modificado Localmente (Baseado em LOCAL)
@@ -493,6 +493,9 @@
}
public void setOffset(Expression offset) {
+ if (offset != null && offset.getType() == Value.UNKNOWN){
+ ((Parameter)offset).setDefaultType(Value.INT);
+ }
this.offsetExpr = offset;
}
@@ -501,6 +504,9 @@
}
public void setLimit(Expression limit) {
+ if (limit != null && limit.getType() == Value.UNKNOWN){
+ ((Parameter)limit).setDefaultType(Value.INT);
+ }
this.limitExpr = limit;
}
Index: command/dml/Update.java
--- command/dml/Update.java Base (BASE)
+++ command/dml/Update.java Modificado Localmente (Baseado em LOCAL)
@@ -208,6 +208,9 @@
}
public void setLimit(Expression limit) {
+ if (limit != null && limit.getType() == Value.UNKNOWN){
+ ((Parameter)limit).setDefaultType(Value.INT);
+ }
this.limitExpr = limit;
}
Index: expression/Parameter.java
--- expression/Parameter.java Base (BASE)
+++ expression/Parameter.java Modificado Localmente (Baseado em LOCAL)
@@ -22,6 +22,7 @@
private Value value;
private Column column;
+ private int defaultType = Value.UNKNOWN;
private final int index;
public Parameter(int index) {
@@ -66,9 +67,13 @@
if (column != null) {
return column.getType();
}
- return Value.UNKNOWN;
+ return defaultType;
}
+ public void setDefaultType(int defaultType) {
+ this.defaultType = defaultType;
+ }
+
@Override
public void mapColumns(ColumnResolver resolver, int level) {
// can't map