Changeset: c0805482b9b2 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c0805482b9b2 Modified Files: Branch: default Log Message:
Merged from Dec2011 diffs (truncated from 393 to 300 lines): diff --git a/java/ChangeLog.Dec2011 b/java/ChangeLog.Dec2011 --- a/java/ChangeLog.Dec2011 +++ b/java/ChangeLog.Dec2011 @@ -1,6 +1,9 @@ # ChangeLog file for java # This file is updated with Maddlog +* Wed Dec 21 2011 Fabian Groffen <[email protected]> +- Fixed overflow error when batching large statements, bug #2952 + * Tue Dec 20 2011 Fabian Groffen <[email protected]> - Resolved a concurrency problem where ResultSet's date-related getters could cause odd stack traces when used by multiple threads at the diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java b/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java @@ -1329,8 +1329,8 @@ public class MonetPreparedStatement default: throw new SQLException("Conversion not allowed", "M1M05"); } - } else if (x instanceof Number) { - Number num = (Number)x; + } else if (x instanceof BigDecimal) { + BigDecimal num = (BigDecimal)x; switch (targetSqlType) { case Types.TINYINT: setByte(parameterIndex, num.byteValue()); @@ -1342,11 +1342,7 @@ public class MonetPreparedStatement setInt(parameterIndex, num.intValue()); break; case Types.BIGINT: - if (x instanceof BigDecimal) { - setLong(parameterIndex, ((BigDecimal)x).setScale(scale, BigDecimal.ROUND_HALF_UP).longValue()); - } else { - setLong(parameterIndex, num.longValue()); - } + setLong(parameterIndex, num.setScale(scale, BigDecimal.ROUND_HALF_UP).longValue()); break; case Types.REAL: setFloat(parameterIndex, num.floatValue()); @@ -1357,33 +1353,7 @@ public class MonetPreparedStatement break; case Types.DECIMAL: case Types.NUMERIC: - if (x instanceof BigDecimal) { - setBigDecimal(parameterIndex, (BigDecimal)x); - } else if (x instanceof BigInteger) { - BigDecimal val; - try { - val = new BigDecimal((BigInteger)x, scale); - } catch (NumberFormatException e) { - try { - val = new BigDecimal(0.0); - } catch (NumberFormatException ex) { - throw new SQLException("Internal error: unable to create template BigDecimal: " + ex.getMessage(), "M0M03"); - } - } - setBigDecimal(parameterIndex, val); - } else { - BigDecimal val; - try { - val = new BigDecimal(num.doubleValue()); - } catch (NumberFormatException e) { - try { - val = new BigDecimal(0.0); - } catch (NumberFormatException ex) { - throw new SQLException("Internal error: unable to create template BigDecimal: " + ex.getMessage(), "M0M03"); - } - } - setBigDecimal(parameterIndex, val); - } + setBigDecimal(parameterIndex, num); break; case Types.BIT: case Types.BOOLEAN: @@ -1401,6 +1371,20 @@ public class MonetPreparedStatement default: throw new SQLException("Conversion not allowed", "M1M05"); } + } else if (x instanceof BigInteger) { + BigInteger num = (BigInteger)x; + switch (targetSqlType) { + case Types.BIGINT: + setLong(parameterIndex, num.longValue()); + break; + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + setString(parameterIndex, x.toString()); + break; + default: + throw new SQLException("Conversion not allowed", "M1M05"); + } } else if (x instanceof Boolean) { boolean val = ((Boolean)x).booleanValue(); switch (targetSqlType) { @@ -1458,7 +1442,9 @@ public class MonetPreparedStatement } } else if (x instanceof java.sql.Date || x instanceof Timestamp || - x instanceof Time) + x instanceof Time || + x instanceof Calendar || + x instanceof java.util.Date) { switch (targetSqlType) { case Types.CHAR: @@ -1473,6 +1459,12 @@ public class MonetPreparedStatement setDate(parameterIndex, (java.sql.Date)x); } else if (x instanceof Timestamp) { setDate(parameterIndex, new java.sql.Date(((Timestamp)x).getTime())); + } else if (x instanceof java.util.Date) { + setDate(parameterIndex, new java.sql.Date( + ((java.util.Date)x).getTime())); + } else if (x instanceof Calendar) { + setDate(parameterIndex, new java.sql.Date( + ((Calendar)x).getTimeInMillis())); } break; case Types.TIME: @@ -1482,6 +1474,12 @@ public class MonetPreparedStatement throw new SQLException("Conversion not allowed", "M1M05"); } else if (x instanceof Timestamp) { setTime(parameterIndex, new Time(((Timestamp)x).getTime())); + } else if (x instanceof java.util.Date) { + setTime(parameterIndex, new java.sql.Time( + ((java.util.Date)x).getTime())); + } else if (x instanceof Calendar) { + setTime(parameterIndex, new java.sql.Time( + ((Calendar)x).getTimeInMillis())); } break; case Types.TIMESTAMP: @@ -1491,6 +1489,12 @@ public class MonetPreparedStatement setTimestamp(parameterIndex, new Timestamp(((java.sql.Date)x).getTime())); } else if (x instanceof Timestamp) { setTimestamp(parameterIndex, (Timestamp)x); + } else if (x instanceof java.util.Date) { + setTimestamp(parameterIndex, new java.sql.Timestamp( + ((java.util.Date)x).getTime())); + } else if (x instanceof Calendar) { + setTimestamp(parameterIndex, new java.sql.Timestamp( + ((Calendar)x).getTimeInMillis())); } break; default: diff --git a/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java b/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java --- a/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java +++ b/java/src/nl/cwi/monetdb/jdbc/MonetStatement.java @@ -215,7 +215,7 @@ public class MonetStatement extends Mone tmpBatch.append(sep); tmpBatch.append(tmp); // send and receive - error |= internalBatch(tmpBatch.toString(), counts, offset, i, e); + error |= internalBatch(tmpBatch.toString(), counts, offset, i + 1, e); offset = i; tmpBatch.delete(0, tmpBatch.length()); first = true; @@ -223,7 +223,7 @@ public class MonetStatement extends Mone } if (tmpBatch.length() + sep.length() + tmp.length() >= MapiSocket.BLOCK) { // send and receive - error |= internalBatch(tmpBatch.toString(), counts, offset, i, e); + error |= internalBatch(tmpBatch.toString(), counts, offset, i + 1, e); offset = i; tmpBatch.delete(0, tmpBatch.length()); first = true; diff --git a/java/tests/Test_PSlargebatchval.java b/java/tests/Test_PSlargebatchval.java new file mode 100644 --- /dev/null +++ b/java/tests/Test_PSlargebatchval.java @@ -0,0 +1,62 @@ +/* + * The contents of this file are subject to the MonetDB Public License + * Version 1.1 (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.monetdb.org/Legal/MonetDBLicense + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is the MonetDB Database System. + * + * The Initial Developer of the Original Code is CWI. + * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. + * Copyright August 2008-2011 MonetDB B.V. + * All Rights Reserved. + */ + +import java.sql.*; +import java.util.*; +import java.nio.charset.Charset; + +public class Test_PSlargebatchval { + public static void main(String[] args) throws Exception { + Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); + Connection con = DriverManager.getConnection(args[0]); + Statement stmt = con.createStatement(); + PreparedStatement pstmt; + + // >> true: auto commit should be on + System.out.println("0. true\t" + con.getAutoCommit()); + + byte[] errorBytes = new byte[] { (byte) 0xe2, (byte) 0x80, (byte) 0xa7 }; + String errorStr = new String(errorBytes, Charset.forName("UTF-8")); + StringBuilder repeatedErrorStr = new StringBuilder(); + for (int i = 0; i < 8170;i++) { + repeatedErrorStr.append(errorStr); + } + + try { + stmt.execute("CREATE TABLE x (c INT, a CLOB, b DOUBLE)"); + pstmt = con.prepareStatement("INSERT INTO x VALUES (?,?,?)"); + pstmt.setLong(1, 1); + pstmt.setString(2, repeatedErrorStr.toString()); + pstmt.setDouble(3, 1.0); + pstmt.addBatch(); + pstmt.executeBatch(); + stmt.execute("DROP TABLE x"); + + pstmt.close(); + stmt.close(); + } catch (SQLException e) { + System.out.println("FAILED :( "+ e.getMessage()); + while ((e = e.getNextException()) != null) + System.out.println("FAILED :( " + e.getMessage()); + System.out.println("ABORTING TEST!!!"); + } + + con.close(); + } +} diff --git a/java/tests/build.xml b/java/tests/build.xml --- a/java/tests/build.xml +++ b/java/tests/build.xml @@ -112,6 +112,7 @@ All Rights Reserved. <antcall target="Test_PSgeneratedkeys" /> <antcall target="Test_PSlargeresponse" /> <antcall target="Test_PSlargeamount" /> + <antcall target="Test_PSlargebatchval" /> <antcall target="Test_PStimedate" /> <antcall target="Test_PStimezone" /> <antcall target="Test_PStypes" /> @@ -218,6 +219,12 @@ All Rights Reserved. </antcall> </target> + <target name="Test_PSlargebatchval"> + <antcall target="test_class"> + <param name="test.class" value="Test_PSlargebatchval" /> + </antcall> + </target> + <target name="Test_PStimedate"> <antcall target="test_class"> <param name="test.class" value="Test_PStimedate" /> diff --git a/sql/jdbc/tests/Tests/All b/sql/jdbc/tests/Tests/All --- a/sql/jdbc/tests/Tests/All +++ b/sql/jdbc/tests/Tests/All @@ -7,6 +7,7 @@ HAVE_JDBCTESTS?Test_Ctransaction HAVE_JDBCTESTS?Test_Dobjects HAVE_JDBCTESTS?Test_PSgeneratedkeys HAVE_JDBCTESTS?Test_PSlargeamount +HAVE_JDBCTESTS?Test_PSlargebatchval HAVE_JDBCTESTS?Test_PStimedate HAVE_JDBCTESTS?Test_PStimezone HAVE_JDBCTESTS?Test_PStypes diff --git a/sql/jdbc/tests/Tests/Test_PSlargebatchval.SQL.bat b/sql/jdbc/tests/Tests/Test_PSlargebatchval.SQL.bat new file mode 100755 --- /dev/null +++ b/sql/jdbc/tests/Tests/Test_PSlargebatchval.SQL.bat @@ -0,0 +1,1 @@ +@call "%TSTSRCDIR%\Test.SQL.bat" %* diff --git a/sql/jdbc/tests/Tests/Test_PSlargebatchval.SQL.sh b/sql/jdbc/tests/Tests/Test_PSlargebatchval.SQL.sh new file mode 100755 --- /dev/null +++ b/sql/jdbc/tests/Tests/Test_PSlargebatchval.SQL.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +$TSTSRCDIR/Test.SQL.sh $* diff --git a/sql/jdbc/tests/Tests/Test_PSlargebatchval.stable.err b/sql/jdbc/tests/Tests/Test_PSlargebatchval.stable.err new file mode 100644 --- /dev/null +++ b/sql/jdbc/tests/Tests/Test_PSlargebatchval.stable.err @@ -0,0 +1,42 @@ +stderr of test 'Test_PSlargebatchval` in directory 'jdbc/tests` itself: + + +# 12:20:02 > +# 12:20:02 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "gdk_dbfarm=/net/sofia.ins.cwi.nl/export/scratch1/fabian/tmp/mtest-Dec2011-sofia.ins.cwi.nl/sql/dbfarm" "--set" "mapi_open=true" "--set" "mapi_port=31048" "--set" "monet_prompt=" "--trace" "--forcemito" "--set" "mal_listing=2" "--dbname=mTests_jdbc_tests" "--set" "mal_listing=0" +# 12:20:02 > + +# builtin opt gdk_dbname = demo +# builtin opt gdk_dbfarm = /ufs/fabian/scratch/ssd/monetdb/Dec2011/program-x86_64/var/lib/monetdb5/dbfarm +# builtin opt gdk_debug = 0 +# builtin opt gdk_alloc_map = no +# builtin opt gdk_vmtrim = yes _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
