1 | /* |
---|
2 | Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved. |
---|
3 | |
---|
4 | |
---|
5 | The MySQL Connector/J is licensed under the terms of the GPLv2 |
---|
6 | <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors. |
---|
7 | There are special exceptions to the terms and conditions of the GPLv2 as it is applied to |
---|
8 | this software, see the FLOSS License Exception |
---|
9 | <http://www.mysql.com/about/legal/licensing/foss-exception.html>. |
---|
10 | |
---|
11 | This program is free software; you can redistribute it and/or modify it under the terms |
---|
12 | of the GNU General Public License as published by the Free Software Foundation; version 2 |
---|
13 | of the License. |
---|
14 | |
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
---|
16 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
---|
17 | See the GNU General Public License for more details. |
---|
18 | |
---|
19 | You should have received a copy of the GNU General Public License along with this |
---|
20 | program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth |
---|
21 | Floor, Boston, MA 02110-1301 USA |
---|
22 | |
---|
23 | */ |
---|
24 | |
---|
25 | package com.mysql.jdbc; |
---|
26 | |
---|
27 | import java.io.Reader; |
---|
28 | import java.sql.NClob; |
---|
29 | import java.sql.RowId; |
---|
30 | import java.sql.SQLXML; |
---|
31 | import java.sql.SQLException; |
---|
32 | |
---|
33 | import com.mysql.jdbc.Connection; |
---|
34 | import com.mysql.jdbc.MysqlDefs; |
---|
35 | import com.mysql.jdbc.SQLError; |
---|
36 | import com.mysql.jdbc.ServerPreparedStatement; |
---|
37 | import com.mysql.jdbc.ServerPreparedStatement.BindValue; |
---|
38 | |
---|
39 | public class JDBC4ServerPreparedStatement extends ServerPreparedStatement { |
---|
40 | |
---|
41 | public JDBC4ServerPreparedStatement(MySQLConnection conn, String sql, |
---|
42 | String catalog, int resultSetType, int resultSetConcurrency) |
---|
43 | throws SQLException { |
---|
44 | super(conn, sql, catalog, resultSetType, resultSetConcurrency); |
---|
45 | // TODO Auto-generated constructor stub |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * @see java.sql.PreparedStatement#setNCharacterStream(int, java.io.Reader, |
---|
50 | * long) |
---|
51 | */ |
---|
52 | public void setNCharacterStream(int parameterIndex, Reader reader, |
---|
53 | long length) throws SQLException { |
---|
54 | // can't take if characterEncoding isn't utf8 |
---|
55 | if (!this.charEncoding.equalsIgnoreCase("UTF-8") |
---|
56 | && !this.charEncoding.equalsIgnoreCase("utf8")) { |
---|
57 | throw SQLError |
---|
58 | .createSQLException("Can not call setNCharacterStream() when connection character set isn't UTF-8", getExceptionInterceptor()); |
---|
59 | } |
---|
60 | |
---|
61 | checkClosed(); |
---|
62 | |
---|
63 | if (reader == null) { |
---|
64 | setNull(parameterIndex, java.sql.Types.BINARY); |
---|
65 | } else { |
---|
66 | BindValue binding = getBinding(parameterIndex, true); |
---|
67 | setType(binding, MysqlDefs.FIELD_TYPE_BLOB); |
---|
68 | |
---|
69 | binding.value = reader; |
---|
70 | binding.isNull = false; |
---|
71 | binding.isLongData = true; |
---|
72 | |
---|
73 | if (this.connection.getUseStreamLengthsInPrepStmts()) { |
---|
74 | binding.bindLength = length; |
---|
75 | } else { |
---|
76 | binding.bindLength = -1; |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * @see java.sql.PreparedStatement#setNClob(int, java.sql.NClob) |
---|
83 | */ |
---|
84 | public void setNClob(int parameterIndex, NClob x) throws SQLException { |
---|
85 | setNClob(parameterIndex, x.getCharacterStream(), this.connection |
---|
86 | .getUseStreamLengthsInPrepStmts() ? x.length() : -1); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * JDBC 4.0 Set a NCLOB parameter. |
---|
91 | * |
---|
92 | * @param parameterIndex |
---|
93 | * the first parameter is 1, the second is 2, ... |
---|
94 | * @param reader |
---|
95 | * the java reader which contains the UNICODE data |
---|
96 | * @param length |
---|
97 | * the number of characters in the stream |
---|
98 | * |
---|
99 | * @throws SQLException |
---|
100 | * if a database error occurs |
---|
101 | */ |
---|
102 | public void setNClob(int parameterIndex, Reader reader, long length) |
---|
103 | throws SQLException { |
---|
104 | // can't take if characterEncoding isn't utf8 |
---|
105 | if (!this.charEncoding.equalsIgnoreCase("UTF-8") |
---|
106 | && !this.charEncoding.equalsIgnoreCase("utf8")) { |
---|
107 | throw SQLError |
---|
108 | .createSQLException("Can not call setNClob() when connection character set isn't UTF-8", getExceptionInterceptor()); |
---|
109 | } |
---|
110 | |
---|
111 | checkClosed(); |
---|
112 | |
---|
113 | if (reader == null) { |
---|
114 | setNull(parameterIndex, java.sql.Types.NCLOB); |
---|
115 | } else { |
---|
116 | BindValue binding = getBinding(parameterIndex, true); |
---|
117 | setType(binding, MysqlDefs.FIELD_TYPE_BLOB); |
---|
118 | |
---|
119 | binding.value = reader; |
---|
120 | binding.isNull = false; |
---|
121 | binding.isLongData = true; |
---|
122 | |
---|
123 | if (this.connection.getUseStreamLengthsInPrepStmts()) { |
---|
124 | binding.bindLength = length; |
---|
125 | } else { |
---|
126 | binding.bindLength = -1; |
---|
127 | } |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | /** |
---|
132 | * @see java.sql.PreparedStatement#setNString(int, java.lang.String) |
---|
133 | */ |
---|
134 | public void setNString(int parameterIndex, String x) throws SQLException { |
---|
135 | if (this.charEncoding.equalsIgnoreCase("UTF-8") |
---|
136 | || this.charEncoding.equalsIgnoreCase("utf8")) { |
---|
137 | setString(parameterIndex, x); |
---|
138 | } else { |
---|
139 | throw SQLError |
---|
140 | .createSQLException("Can not call setNString() when connection character set isn't UTF-8", getExceptionInterceptor()); |
---|
141 | } |
---|
142 | } |
---|
143 | |
---|
144 | public void setRowId(int parameterIndex, RowId x) throws SQLException { |
---|
145 | JDBC4PreparedStatementHelper.setRowId(this, parameterIndex, x); |
---|
146 | } |
---|
147 | |
---|
148 | public void setSQLXML(int parameterIndex, SQLXML xmlObject) |
---|
149 | throws SQLException { |
---|
150 | JDBC4PreparedStatementHelper.setSQLXML(this, parameterIndex, xmlObject); |
---|
151 | } |
---|
152 | } |
---|