61
70
assertEquals(arr.getClass(), rs.getObject(3).getClass());
62
71
assertEquals(String.class, rs.getObject(4).getClass());
76
public void testCharacterStreamWithMultibyteCharacterAndLength() throws Exception {
77
connection.createStatement().execute("drop table if exists streamtest2");
78
connection.createStatement().execute("create table streamtest2 (id int primary key not null, strm text)");
79
PreparedStatement stmt = connection.prepareStatement("insert into streamtest2 (id, strm) values (?,?)");
81
String toInsert = "\u00D8abcdefgh\njklmn\"";
82
Reader reader = new StringReader(toInsert);
83
stmt.setCharacterStream(2, reader, 5);
85
ResultSet rs = connection.createStatement().executeQuery("select * from streamtest2");
87
Reader rdr = rs.getCharacterStream("strm");
88
StringBuilder sb = new StringBuilder();
90
while((ch = rdr.read()) != -1) {
93
assertEquals(toInsert.substring(0,5), sb.toString());
97
public void testCharacterStreamWithMultibyteCharacter() throws Exception {
98
connection.createStatement().execute("drop table if exists streamtest2");
99
connection.createStatement().execute("create table streamtest2 (id int primary key not null, strm text)");
100
PreparedStatement stmt = connection.prepareStatement("insert into streamtest2 (id, strm) values (?,?)");
102
String toInsert = "\u00D8abcdefgh\njklmn\"";
103
Reader reader = new StringReader(toInsert);
104
stmt.setCharacterStream(2, reader);
106
ResultSet rs = connection.createStatement().executeQuery("select * from streamtest2");
108
Reader rdr = rs.getCharacterStream("strm");
109
StringBuilder sb = new StringBuilder();
111
while((ch = rdr.read()) != -1) {
114
assertEquals(toInsert, sb.toString());
118
public void testClobWithLengthAndMultibyteCharacter() throws SQLException, IOException {
119
connection.createStatement().execute("drop table if exists clobtest");
120
connection.createStatement().execute("create table clobtest (id int not null primary key, strm text)");
121
PreparedStatement stmt = connection.prepareStatement("insert into clobtest (id, strm) values (?,?)");
122
String clob = "\u00D8clob";
124
stmt.setClob(2, new StringReader(clob));
126
ResultSet rs = connection.createStatement().executeQuery("select * from clobtest");
128
Reader readStuff = rs.getClob("strm").getCharacterStream();
129
char[] a = new char[5];
131
assertEquals(new String(a), clob);
135
public void testClob3() throws Exception {
136
connection.createStatement().execute("drop table if exists clobtest");
137
connection.createStatement().execute("create table clobtest (strm text)");
138
PreparedStatement stmt = connection.prepareStatement("insert into clobtest (strm) values (?)");
139
Clob clob = connection.createClob();
140
Writer writer = clob.setCharacterStream(1);
141
writer.write("\u00D8hello", 0, 6);
143
stmt.setClob(1,clob);
145
ResultSet rs = connection.createStatement().executeQuery("select * from clobtest");
147
Object o = rs.getObject(1);
148
assertTrue(o instanceof String);
149
String s = rs.getString(1);
150
assertEquals("\u00D8hello", s);
154
public void testBlob() throws SQLException, IOException {
155
connection.createStatement().execute("drop table if exists blobtest");
156
connection.createStatement().execute("create table blobtest (id int not null primary key, strm blob)");
157
PreparedStatement stmt = connection.prepareStatement("insert into blobtest (id, strm) values (?,?)");
158
byte [] theBlob = {1,2,3,4,5,6};
159
InputStream stream = new ByteArrayInputStream(theBlob);
161
stmt.setBlob(2,stream);
163
ResultSet rs = connection.createStatement().executeQuery("select * from blobtest");
165
InputStream readStuff = rs.getBlob("strm").getBinaryStream();
168
while((ch = readStuff.read())!=-1) {
169
assertEquals(theBlob[pos++],ch);
172
readStuff = rs.getBinaryStream("strm");
175
while((ch = readStuff.read())!=-1) {
176
assertEquals(theBlob[pos++],ch);
180
public void testBlobWithLength() throws SQLException, IOException {
181
connection.createStatement().execute("drop table if exists blobtest");
182
connection.createStatement().execute("create table blobtest (id int not null primary key, strm blob)");
183
PreparedStatement stmt = connection.prepareStatement("insert into blobtest (id, strm) values (?,?)");
184
byte [] theBlob = {1,2,3,4,5,6};
185
InputStream stream = new ByteArrayInputStream(theBlob);
187
stmt.setBlob(2,stream,4);
189
ResultSet rs = connection.createStatement().executeQuery("select * from blobtest");
191
InputStream readStuff = rs.getBlob("strm").getBinaryStream();
194
while((ch = readStuff.read())!=-1) {
195
assertEquals(theBlob[pos++],ch);
199
public void testClobWithLength() throws SQLException, IOException {
200
connection.createStatement().execute("drop table if exists clobtest");
201
connection.createStatement().execute("create table clobtest (id int not null primary key, strm text)");
202
PreparedStatement stmt = connection.prepareStatement("insert into clobtest (id, strm) values (?,?)");
203
String clob = "clob";
205
stmt.setClob(2, new StringReader(clob));
207
ResultSet rs = connection.createStatement().executeQuery("select * from clobtest");
209
Reader readStuff = rs.getClob("strm").getCharacterStream();
210
char[] a = new char[4];
212
Assert.assertEquals(new String(a), clob);
216
public void testClob2() throws SQLException, IOException {
217
connection.createStatement().execute("drop table if exists clobtest");
218
connection.createStatement().execute("create table clobtest (id int not null primary key, strm text)");
219
PreparedStatement stmt = connection.prepareStatement("insert into clobtest (id, strm) values (?,?)");
220
Clob clob = connection.createClob();
221
OutputStream ostream = clob.setAsciiStream(1);
222
byte[] bytes = "hello".getBytes();
223
ostream.write(bytes);
225
stmt.setClob(2,clob);
227
ResultSet rs = connection.createStatement().executeQuery("select * from clobtest");
229
Object o = rs.getObject(2);
230
assertTrue(o instanceof String);
231
String s = rs.getString(2);
232
assertTrue(s.equals("hello"));
66
235
public void blobSerialization() throws Exception {
67
236
Blob b = new MySQLBlob(new byte[]{1,2,3});