Source Code Cross Referenced for Tds5Test.java in  » Database-JDBC-Connection-Pool » jTDS » net » sourceforge » jtds » test » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database JDBC Connection Pool » jTDS » net.sourceforge.jtds.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jtds.test;
002:
003:        import java.sql.Date;
004:        import java.sql.PreparedStatement;
005:        import java.sql.ResultSet;
006:        import java.sql.ResultSetMetaData;
007:        import java.sql.Statement;
008:        import java.sql.Time;
009:        import java.sql.Types;
010:        import java.io.ByteArrayInputStream;
011:        import java.io.CharArrayReader;
012:        import java.math.BigDecimal;
013:
014:        import junit.framework.Test;
015:        import junit.framework.TestSuite;
016:
017:        import net.sourceforge.jtds.jdbc.DefaultProperties;
018:        import net.sourceforge.jtds.jdbc.Messages;
019:        import net.sourceforge.jtds.jdbc.Driver;
020:
021:        /**
022:         * Test case to illustrate use of TDS 5 support.
023:         *
024:         * @version 1.0
025:         * @author Mike Hutchinson
026:         */
027:        public class Tds5Test extends TestBase {
028:
029:            public static Test suite() {
030:
031:                if (!DefaultProperties.TDS_VERSION_50.equals(props
032:                        .getProperty(Messages.get(Driver.TDS)))) {
033:
034:                    return new TestSuite();
035:                }
036:
037:                return new TestSuite(Tds5Test.class);
038:            }
039:
040:            public Tds5Test(String name) {
041:                super (name);
042:            }
043:
044:            /**
045:             * Test the new column meta data made available in Sybase 12
046:             * @throws Exception
047:             */
048:            public void testColMetaData() throws Exception {
049:                if (!isVersion12orHigher()) {
050:                    return;
051:                }
052:                Statement stmt = con.createStatement();
053:                stmt
054:                        .execute("CREATE TABLE #TESTMD (id numeric(10,0) identity primary key not null, data unichar null)");
055:                ResultSetMetaData rsmd = stmt.executeQuery(
056:                        "SELECT id, data as aliasname FROM #TESTMD")
057:                        .getMetaData();
058:                assertEquals(2, rsmd.getColumnCount());
059:                assertEquals("tempdb", rsmd.getCatalogName(1));
060:                assertEquals("guest", rsmd.getSchemaName(1));
061:                assertEquals("#TESTMD", rsmd.getTableName(1));
062:                assertEquals("id", rsmd.getColumnName(1));
063:                assertEquals("aliasname", rsmd.getColumnName(2));
064:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
065:                        .isNullable(1));
066:                assertEquals(ResultSetMetaData.columnNullable, rsmd
067:                        .isNullable(2));
068:                assertEquals("numeric identity", rsmd.getColumnTypeName(1));
069:                assertEquals("unichar", rsmd.getColumnTypeName(2));
070:                assertTrue(rsmd.isAutoIncrement(1));
071:                assertFalse(rsmd.isAutoIncrement(2));
072:                stmt.close();
073:            }
074:
075:            /**
076:             * Test the new date and time data types in Sybase 12+
077:             * @throws Exception
078:             */
079:            public void testDateTime() throws Exception {
080:                if (!isVersion12orHigher()) {
081:                    return;
082:                }
083:                String testDate = "1997-08-31";
084:                String testTime = "23:59:59";
085:                Statement stmt = con.createStatement();
086:                stmt
087:                        .execute("CREATE TABLE #TESTDT (id int, d1 date, d2 date, t1 time, t2 time)");
088:                stmt.close();
089:                PreparedStatement pstmt = con
090:                        .prepareStatement("INSERT INTO #TESTDT VALUES(1, {d "
091:                                + testDate + "}, ?, {t " + testTime + "}, ?)");
092:                pstmt.setDate(1, Date.valueOf(testDate));
093:                pstmt.setTime(2, Time.valueOf(testTime));
094:                assertEquals(1, pstmt.executeUpdate());
095:                pstmt.close();
096:                stmt = con.createStatement();
097:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TESTDT");
098:                assertTrue(rs.next());
099:                assertEquals(testDate, rs.getDate(2).toString());
100:                assertEquals(testDate, rs.getDate(3).toString());
101:                assertEquals(testTime, rs.getTime(4).toString());
102:                assertEquals(testTime, rs.getTime(5).toString());
103:                stmt.close();
104:            }
105:
106:            /**
107:             * Test varchar and varbinary fields longer than 255 bytes.
108:             * Test univarchar columns as well.
109:             * @throws Exception
110:             */
111:            public void testLongData() throws Exception {
112:                if (!isVersion12orHigher()) {
113:                    return;
114:                }
115:                StringBuffer buf = new StringBuffer(300);
116:                for (int i = 0; i < 300; i++) {
117:                    if (i == 0) {
118:                        buf.append('<');
119:                    } else if (i == 299) {
120:                        buf.append('>');
121:                    } else {
122:                        buf.append('X');
123:                    }
124:                }
125:                String longString = buf.toString();
126:                byte longBytes[] = longString.getBytes();
127:                String unichar = "This is a unicode string \u0441\u043b\u043e\u0432\u043e";
128:                Statement stmt = con.createStatement();
129:                stmt
130:                        .execute("CREATE TABLE #TESTLD (id int, vc varchar(300), vb varbinary(300), vu univarchar(300))");
131:                stmt.close();
132:                PreparedStatement pstmt = con
133:                        .prepareStatement("INSERT INTO #TESTLD VALUES(1, ?, ?, ?)");
134:                pstmt.setString(1, longString);
135:                pstmt.setBytes(2, longBytes);
136:                pstmt.setString(3, unichar);
137:                assertEquals(1, pstmt.executeUpdate());
138:                pstmt.close();
139:                stmt = con.createStatement();
140:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TESTLD");
141:                assertTrue(rs.next());
142:                assertEquals(longString, rs.getString(2));
143:                assertEquals(longString, new String(rs.getBytes(3)));
144:                assertEquals(unichar, rs.getString(4));
145:                stmt.close();
146:            }
147:
148:            /**
149:             * Test for bug [1161609]  Text or image data truncated on Sybase 12.5
150:             * @throws Exception
151:             */
152:            public void testImageText() throws Exception {
153:                if (!isVersion12orHigher()) {
154:                    return;
155:                }
156:                Statement stmt = con.createStatement();
157:                stmt
158:                        .execute("CREATE TABLE #TESTIT (id int, txt text, img image)");
159:                StringBuffer data = new StringBuffer(20000);
160:                for (int i = 0; i < 20000; i++) {
161:                    data.append((char) ('A' + (i % 10)));
162:                }
163:                PreparedStatement pstmt = con
164:                        .prepareStatement("INSERT INTO #TESTIT VALUES(?,?,?)");
165:                pstmt.setInt(1, 1);
166:                pstmt.setString(2, data.toString());
167:                pstmt.setBytes(3, data.toString().getBytes());
168:                assertEquals(1, pstmt.executeUpdate());
169:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TESTIT");
170:                assertNotNull(rs);
171:                assertTrue(rs.next());
172:                assertEquals(data.length(), rs.getString(2).length());
173:                assertEquals(data.length(), rs.getBytes(3).length);
174:                pstmt.close();
175:                stmt.close();
176:            }
177:
178:            /**
179:             * Test writing image data from InputStream
180:             * @throws Exception
181:             */
182:            public void testStreamImage() throws Exception {
183:                Statement stmt = con.createStatement();
184:                stmt.execute("CREATE TABLE #TESTIS (id int, img image)");
185:                byte data[] = new byte[20000];
186:                for (int i = 0; i < data.length; i++) {
187:                    data[i] = (byte) ('A' + (i % 10));
188:                }
189:                PreparedStatement pstmt = con
190:                        .prepareStatement("INSERT INTO #TESTIS VALUES(?,?)");
191:                pstmt.setInt(1, 1);
192:                pstmt.setBinaryStream(2, new ByteArrayInputStream(data),
193:                        data.length);
194:                assertEquals(1, pstmt.executeUpdate());
195:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TESTIS");
196:                assertNotNull(rs);
197:                assertTrue(rs.next());
198:                assertEquals(new String(data), new String(rs.getBytes(2)));
199:                pstmt.close();
200:                stmt.close();
201:            }
202:
203:            /**
204:             * Test writing text data from Reader
205:             * @throws Exception
206:             */
207:            public void testStreamText() throws Exception {
208:                Statement stmt = con.createStatement();
209:                stmt.execute("CREATE TABLE #TESTTR (id int, txt text)");
210:                char data[] = new char[20000];
211:                for (int i = 0; i < data.length; i++) {
212:                    data[i] = (char) ('A' + (i % 10));
213:                }
214:                PreparedStatement pstmt = con
215:                        .prepareStatement("INSERT INTO #TESTTR VALUES(?,?)");
216:                pstmt.setInt(1, 1);
217:                pstmt.setCharacterStream(2, new CharArrayReader(data),
218:                        data.length);
219:                assertEquals(1, pstmt.executeUpdate());
220:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TESTTR");
221:                assertNotNull(rs);
222:                assertTrue(rs.next());
223:                assertEquals(new String(data), rs.getString(2));
224:                pstmt.close();
225:                stmt.close();
226:            }
227:
228:            /**
229:             * Test writing unitext data from Reader
230:             */
231:            public void testStreamUniText() throws Exception {
232:                if (!isVersion15orHigher()) {
233:                    return;
234:                }
235:                Statement stmt = con.createStatement();
236:                stmt.execute("CREATE TABLE #TESTTR (id int, txt unitext)");
237:                char data[] = new char[20000];
238:                for (int i = 0; i < data.length; i++) {
239:                    data[i] = (char) ('A' + (i % 10));
240:                }
241:                data[data.length - 1] = '\u0441'; // Force unicode
242:                PreparedStatement pstmt = con
243:                        .prepareStatement("INSERT INTO #TESTTR VALUES(?,?)");
244:                pstmt.setInt(1, 1);
245:                pstmt.setCharacterStream(2, new CharArrayReader(data),
246:                        data.length);
247:                assertEquals(1, pstmt.executeUpdate());
248:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TESTTR");
249:                assertNotNull(rs);
250:                assertTrue(rs.next());
251:                assertEquals(new String(data), rs.getString(2));
252:                pstmt.close();
253:                stmt.close();
254:            }
255:
256:            /**
257:             * Test writing unitext data from memory
258:             * @throws Exception
259:             */
260:            public void testUniText() throws Exception {
261:                if (!isVersion15orHigher()) {
262:                    return;
263:                }
264:                Statement stmt = con.createStatement();
265:                stmt.execute("CREATE TABLE #TESTTR (id int, txt unitext)");
266:                char data[] = new char[20000];
267:                for (int i = 0; i < data.length; i++) {
268:                    data[i] = (char) ('A' + (i % 10));
269:                }
270:                data[data.length - 1] = '\u0441'; // Force unicode
271:                PreparedStatement pstmt = con
272:                        .prepareStatement("INSERT INTO #TESTTR VALUES(?,?)");
273:                pstmt.setInt(1, 1);
274:                pstmt.setString(2, new String(data));
275:                assertEquals(1, pstmt.executeUpdate());
276:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TESTTR");
277:                assertNotNull(rs);
278:                assertTrue(rs.next());
279:                assertEquals(new String(data), rs.getString(2));
280:                ResultSetMetaData rsmd = rs.getMetaData();
281:                assertEquals("unitext", rsmd.getColumnTypeName(2));
282:                assertEquals(Types.CLOB, rsmd.getColumnType(2));
283:                pstmt.close();
284:                stmt.close();
285:            }
286:
287:            /*
288:             * Check that unitext fields that have once been set to a non
289:             * null value return null when updated to null.
290:             * Fix bug [1774322] Sybase nulled text fields return not null.
291:             */
292:            public void testNullUniText() throws Exception {
293:                if (!isVersion15orHigher()) {
294:                    return;
295:                }
296:                Statement stmt = con.createStatement();
297:                stmt
298:                        .execute("CREATE TABLE #TEST (id int primary key not null, txt unitext null)");
299:                stmt.executeUpdate("INSERT INTO #TEST VALUES (1, null)");
300:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
301:                rs.next();
302:                assertTrue(rs.getString(2) == null);
303:                stmt.executeUpdate("UPDATE #TEST SET txt = ' ' WHERE id = 1");
304:                rs = stmt.executeQuery("SELECT * FROM #TEST");
305:                rs.next();
306:                assertTrue(rs.getString(2) != null);
307:                stmt.executeUpdate("UPDATE #TEST SET txt = null WHERE id = 1");
308:                rs = stmt.executeQuery("SELECT * FROM #TEST");
309:                rs.next();
310:                assertTrue(rs.getString(2) == null);
311:                stmt.close();
312:            }
313:
314:            /**
315:             * Test Sybase ASE 15+ bigint data type.
316:             * @throws Exception
317:             */
318:            public void testBigint() throws Exception {
319:                if (!isVersion15orHigher()) {
320:                    return;
321:                }
322:                Statement stmt = con.createStatement();
323:                stmt
324:                        .execute("CREATE TABLE #TEST (val bigint primary key, val2 bigint null)");
325:                PreparedStatement pstmt = con
326:                        .prepareStatement("INSERT INTO #TEST VALUES(?,?)");
327:                pstmt.setLong(1, Long.MAX_VALUE);
328:                pstmt.setLong(2, Long.MIN_VALUE);
329:                pstmt.executeUpdate();
330:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
331:                rs.next();
332:                assertEquals(Long.MAX_VALUE, rs.getLong(1));
333:                assertEquals(Long.MIN_VALUE, rs.getLong(2));
334:                ResultSetMetaData rsmd = rs.getMetaData();
335:                assertEquals("bigint", rsmd.getColumnTypeName(1));
336:                assertEquals("bigint", rsmd.getColumnTypeName(2));
337:                assertEquals(Types.BIGINT, rsmd.getColumnType(1));
338:                assertEquals(Types.BIGINT, rsmd.getColumnType(2));
339:            }
340:
341:            /**
342:             * Test Sybase ASE 15+ unsigned smallint data type.
343:             * @throws Exception
344:             */
345:            public void testUnsignedSmallInt() throws Exception {
346:                if (!isVersion15orHigher()) {
347:                    return;
348:                }
349:                Statement stmt = con.createStatement();
350:                stmt
351:                        .execute("CREATE TABLE #TEST (val unsigned smallint primary key, val2 unsigned smallint null)");
352:                PreparedStatement pstmt = con
353:                        .prepareStatement("INSERT INTO #TEST VALUES(?,?)");
354:                pstmt.setInt(1, 65535);
355:                pstmt.setInt(2, 65535);
356:                pstmt.executeUpdate();
357:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
358:                rs.next();
359:                assertEquals(65535, rs.getInt(1));
360:                assertEquals(65535, rs.getInt(2));
361:                ResultSetMetaData rsmd = rs.getMetaData();
362:                assertEquals("unsigned smallint", rsmd.getColumnTypeName(1));
363:                assertEquals("unsigned smallint", rsmd.getColumnTypeName(2));
364:                assertEquals(Types.INTEGER, rsmd.getColumnType(1));
365:                assertEquals(Types.INTEGER, rsmd.getColumnType(2));
366:            }
367:
368:            /**
369:             * Test Sybase ASE 15+ unsigned int data type.
370:             * @throws Exception
371:             */
372:            public void testUnsignedInt() throws Exception {
373:                if (!isVersion15orHigher()) {
374:                    return;
375:                }
376:                Statement stmt = con.createStatement();
377:                stmt
378:                        .execute("CREATE TABLE #TEST (val unsigned int primary key, val2 unsigned int null)");
379:                PreparedStatement pstmt = con
380:                        .prepareStatement("INSERT INTO #TEST VALUES(?,?)");
381:                pstmt.setLong(1, 4294967295L);
382:                pstmt.setLong(2, 4294967295L);
383:                pstmt.executeUpdate();
384:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
385:                rs.next();
386:                assertEquals(4294967295L, rs.getLong(1));
387:                assertEquals(4294967295L, rs.getLong(2));
388:                ResultSetMetaData rsmd = rs.getMetaData();
389:                assertEquals("unsigned int", rsmd.getColumnTypeName(1));
390:                assertEquals("unsigned int", rsmd.getColumnTypeName(2));
391:                assertEquals(Types.BIGINT, rsmd.getColumnType(1));
392:                assertEquals(Types.BIGINT, rsmd.getColumnType(2));
393:            }
394:
395:            /**
396:             * Test Sybase ASE 15+ unsigned bigint data type.
397:             * @throws Exception
398:             */
399:            public void testUnsignedBigInt() throws Exception {
400:                if (!isVersion15orHigher()) {
401:                    return;
402:                }
403:                Statement stmt = con.createStatement();
404:                stmt
405:                        .execute("CREATE TABLE #TEST (val unsigned bigint primary key, val2 unsigned bigint null)");
406:                PreparedStatement pstmt = con
407:                        .prepareStatement("INSERT INTO #TEST VALUES(?,?)");
408:                pstmt.setBigDecimal(1, new BigDecimal("18446744073709551615"));
409:                pstmt.setBigDecimal(2, new BigDecimal("18446744073709551615"));
410:                pstmt.executeUpdate();
411:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
412:                rs.next();
413:                assertEquals("18446744073709551615", rs.getString(1));
414:                assertEquals("18446744073709551615", rs.getString(2));
415:                ResultSetMetaData rsmd = rs.getMetaData();
416:                assertEquals("unsigned bigint", rsmd.getColumnTypeName(1));
417:                assertEquals("unsigned bigint", rsmd.getColumnTypeName(2));
418:                assertEquals(Types.DECIMAL, rsmd.getColumnType(1));
419:                assertEquals(Types.DECIMAL, rsmd.getColumnType(2));
420:            }
421:
422:            /**
423:             * Test that resultset meta data is correct for long varchar/varbinary types.
424:             * @throws Exception
425:             */
426:            public void testResultSetMetaData2() throws Exception {
427:                if (!isVersion12orHigher()) {
428:                    return;
429:                }
430:                Statement stmt = con.createStatement();
431:                stmt
432:                        .execute("CREATE TABLE #temp ("
433:                                + "c varchar(310) not null, c2 varchar(320) null, "
434:                                + "c3 char(330) not null, c4 char(340) null,"
435:                                + "c5 nvarchar(350) not null, c6 nvarchar(360) null, "
436:                                + "c7 nchar(370) not null, c8 nchar(380) null,"
437:                                + "c9 univarchar(390) not null, c10 univarchar(400) null,"
438:                                + "c11 unichar(410) not null, c12 unichar(420) null,"
439:                                + "c13 varbinary(430) not null, c14 varbinary(440) null,"
440:                                + "c15 binary(450) not null, c16 binary(460) null"
441:                                + ")");
442:                ResultSet rs = stmt.executeQuery("SELECT * FROM #temp");
443:                ResultSetMetaData rsmd = rs.getMetaData();
444:                assertEquals("varchar", rsmd.getColumnTypeName(1));
445:                assertEquals(Types.VARCHAR, rsmd.getColumnType(1));
446:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
447:                        .isNullable(1));
448:                assertEquals(310, rsmd.getColumnDisplaySize(1));
449:
450:                assertEquals("varchar", rsmd.getColumnTypeName(2));
451:                assertEquals(Types.VARCHAR, rsmd.getColumnType(2));
452:                assertEquals(ResultSetMetaData.columnNullable, rsmd
453:                        .isNullable(2));
454:                assertEquals(320, rsmd.getColumnDisplaySize(2));
455:
456:                assertEquals("char", rsmd.getColumnTypeName(3));
457:                assertEquals(Types.CHAR, rsmd.getColumnType(3));
458:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
459:                        .isNullable(3));
460:                assertEquals(330, rsmd.getColumnDisplaySize(3));
461:
462:                assertEquals("char", rsmd.getColumnTypeName(4));
463:                assertEquals(Types.CHAR, rsmd.getColumnType(4));
464:                assertEquals(ResultSetMetaData.columnNullable, rsmd
465:                        .isNullable(4));
466:                assertEquals(340, rsmd.getColumnDisplaySize(4));
467:
468:                assertEquals("nvarchar", rsmd.getColumnTypeName(5));
469:                assertEquals(Types.VARCHAR, rsmd.getColumnType(5));
470:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
471:                        .isNullable(5));
472:                assertEquals(350, rsmd.getColumnDisplaySize(5));
473:
474:                assertEquals("nvarchar", rsmd.getColumnTypeName(6));
475:                assertEquals(Types.VARCHAR, rsmd.getColumnType(6));
476:                assertEquals(ResultSetMetaData.columnNullable, rsmd
477:                        .isNullable(6));
478:                assertEquals(360, rsmd.getColumnDisplaySize(6));
479:
480:                assertEquals("nchar", rsmd.getColumnTypeName(7));
481:                assertEquals(Types.CHAR, rsmd.getColumnType(7));
482:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
483:                        .isNullable(7));
484:                assertEquals(370, rsmd.getColumnDisplaySize(7));
485:
486:                assertEquals("nchar", rsmd.getColumnTypeName(8));
487:                assertEquals(Types.CHAR, rsmd.getColumnType(8));
488:                assertEquals(ResultSetMetaData.columnNullable, rsmd
489:                        .isNullable(8));
490:                assertEquals(380, rsmd.getColumnDisplaySize(8));
491:
492:                assertEquals("univarchar", rsmd.getColumnTypeName(9));
493:                assertEquals(Types.VARCHAR, rsmd.getColumnType(9));
494:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
495:                        .isNullable(9));
496:                assertEquals(390, rsmd.getColumnDisplaySize(9));
497:
498:                assertEquals("univarchar", rsmd.getColumnTypeName(10));
499:                assertEquals(Types.VARCHAR, rsmd.getColumnType(10));
500:                assertEquals(ResultSetMetaData.columnNullable, rsmd
501:                        .isNullable(10));
502:                assertEquals(400, rsmd.getColumnDisplaySize(10));
503:
504:                assertEquals("unichar", rsmd.getColumnTypeName(11));
505:                assertEquals(Types.CHAR, rsmd.getColumnType(11));
506:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
507:                        .isNullable(11));
508:                assertEquals(410, rsmd.getColumnDisplaySize(11));
509:
510:                assertEquals("unichar", rsmd.getColumnTypeName(12));
511:                assertEquals(Types.CHAR, rsmd.getColumnType(12));
512:                assertEquals(ResultSetMetaData.columnNullable, rsmd
513:                        .isNullable(12));
514:                assertEquals(420, rsmd.getColumnDisplaySize(12));
515:
516:                assertEquals("varbinary", rsmd.getColumnTypeName(13));
517:                assertEquals(Types.VARBINARY, rsmd.getColumnType(13));
518:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
519:                        .isNullable(13));
520:                assertEquals(860, rsmd.getColumnDisplaySize(13));
521:
522:                assertEquals("varbinary", rsmd.getColumnTypeName(14));
523:                assertEquals(Types.VARBINARY, rsmd.getColumnType(14));
524:                assertEquals(ResultSetMetaData.columnNullable, rsmd
525:                        .isNullable(14));
526:                assertEquals(880, rsmd.getColumnDisplaySize(14));
527:
528:                assertEquals("binary", rsmd.getColumnTypeName(15));
529:                assertEquals(Types.BINARY, rsmd.getColumnType(15));
530:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
531:                        .isNullable(15));
532:                assertEquals(900, rsmd.getColumnDisplaySize(15));
533:
534:                assertEquals("binary", rsmd.getColumnTypeName(16));
535:                assertEquals(Types.BINARY, rsmd.getColumnType(16));
536:                assertEquals(ResultSetMetaData.columnNullable, rsmd
537:                        .isNullable(16));
538:                assertEquals(920, rsmd.getColumnDisplaySize(16));
539:            }
540:
541:            /**
542:             * Test that resultset meta data is correct for short varchar/varbinary types.
543:             * Demonstrate fix to bug [1453552].
544:             * @throws Exception
545:             */
546:            public void testResultSetMetaData() throws Exception {
547:                Statement stmt = con.createStatement();
548:                stmt
549:                        .execute("CREATE TABLE #temp ("
550:                                + "c varchar(10) not null, c2 varchar(20) null, "
551:                                + "c3 char(30) not null, c4 char(40) null,"
552:                                + "c5 nvarchar(50) not null, c6 nvarchar(60) null, "
553:                                + "c7 nchar(70) not null, c8 nchar(80) null,"
554:                                + "c9 varbinary(90) not null, c10 varbinary(100) null, "
555:                                + "c11 binary(110) not null, c12 binary(120) null,"
556:                                + ")");
557:                ResultSet rs = stmt.executeQuery("SELECT * FROM #temp");
558:                ResultSetMetaData rsmd = rs.getMetaData();
559:                assertEquals("varchar", rsmd.getColumnTypeName(1));
560:                assertEquals(Types.VARCHAR, rsmd.getColumnType(1));
561:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
562:                        .isNullable(1));
563:                assertEquals(10, rsmd.getColumnDisplaySize(1));
564:
565:                assertEquals("varchar", rsmd.getColumnTypeName(2));
566:                assertEquals(Types.VARCHAR, rsmd.getColumnType(2));
567:                assertEquals(ResultSetMetaData.columnNullable, rsmd
568:                        .isNullable(2));
569:                assertEquals(20, rsmd.getColumnDisplaySize(2));
570:
571:                assertEquals("char", rsmd.getColumnTypeName(3));
572:                assertEquals(Types.CHAR, rsmd.getColumnType(3));
573:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
574:                        .isNullable(3));
575:                assertEquals(30, rsmd.getColumnDisplaySize(3));
576:
577:                assertEquals("char", rsmd.getColumnTypeName(4));
578:                assertEquals(Types.CHAR, rsmd.getColumnType(4));
579:                assertEquals(ResultSetMetaData.columnNullable, rsmd
580:                        .isNullable(4));
581:                assertEquals(40, rsmd.getColumnDisplaySize(4));
582:
583:                assertEquals("nvarchar", rsmd.getColumnTypeName(5));
584:                assertEquals(Types.VARCHAR, rsmd.getColumnType(5));
585:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
586:                        .isNullable(5));
587:                assertEquals(50, rsmd.getColumnDisplaySize(5));
588:
589:                assertEquals("nvarchar", rsmd.getColumnTypeName(6));
590:                assertEquals(Types.VARCHAR, rsmd.getColumnType(6));
591:                assertEquals(ResultSetMetaData.columnNullable, rsmd
592:                        .isNullable(6));
593:                assertEquals(60, rsmd.getColumnDisplaySize(6));
594:
595:                assertEquals("nchar", rsmd.getColumnTypeName(7));
596:                assertEquals(Types.CHAR, rsmd.getColumnType(7));
597:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
598:                        .isNullable(7));
599:                assertEquals(70, rsmd.getColumnDisplaySize(7));
600:
601:                assertEquals("nchar", rsmd.getColumnTypeName(8));
602:                assertEquals(Types.CHAR, rsmd.getColumnType(8));
603:                assertEquals(ResultSetMetaData.columnNullable, rsmd
604:                        .isNullable(8));
605:                assertEquals(80, rsmd.getColumnDisplaySize(8));
606:
607:                assertEquals("varbinary", rsmd.getColumnTypeName(9));
608:                assertEquals(Types.VARBINARY, rsmd.getColumnType(9));
609:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
610:                        .isNullable(9));
611:                assertEquals(180, rsmd.getColumnDisplaySize(9));
612:
613:                assertEquals("varbinary", rsmd.getColumnTypeName(10));
614:                assertEquals(Types.VARBINARY, rsmd.getColumnType(10));
615:                assertEquals(ResultSetMetaData.columnNullable, rsmd
616:                        .isNullable(10));
617:                assertEquals(200, rsmd.getColumnDisplaySize(10));
618:
619:                assertEquals("binary", rsmd.getColumnTypeName(11));
620:                assertEquals(Types.BINARY, rsmd.getColumnType(11));
621:                assertEquals(ResultSetMetaData.columnNoNulls, rsmd
622:                        .isNullable(11));
623:                assertEquals(220, rsmd.getColumnDisplaySize(11));
624:
625:                assertEquals("binary", rsmd.getColumnTypeName(12));
626:                assertEquals(Types.BINARY, rsmd.getColumnType(12));
627:                assertEquals(ResultSetMetaData.columnNullable, rsmd
628:                        .isNullable(12));
629:                assertEquals(240, rsmd.getColumnDisplaySize(12));
630:            }
631:
632:            /**
633:             * Test Sybase ASE misc data type metadata.
634:             * @throws Exception
635:             */
636:            public void testResultSetMetaData3() throws Exception {
637:                if (!isVersion15orHigher()) {
638:                    return;
639:                }
640:                Statement stmt = con.createStatement();
641:                stmt.execute("CREATE TABLE #TEST (ts timestamp, s sysname)");
642:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
643:                ResultSetMetaData rsmd = rs.getMetaData();
644:                assertEquals("timestamp", rsmd.getColumnTypeName(1));
645:                assertEquals(Types.VARBINARY, rsmd.getColumnType(1));
646:                assertEquals("sysname", rsmd.getColumnTypeName(2));
647:                assertEquals(Types.VARCHAR, rsmd.getColumnType(2));
648:            }
649:
650:            /**
651:             * Test Sybase ASE 15+ misc data type metadata.
652:             * @throws Exception
653:             */
654:            public void testResultSetMetaData4() throws Exception {
655:                if (!isVersion15orHigher()) {
656:                    return;
657:                }
658:                Statement stmt = con.createStatement();
659:                stmt.execute("CREATE TABLE #TEST (s longsysname)");
660:                ResultSet rs = stmt.executeQuery("SELECT * FROM #TEST");
661:                ResultSetMetaData rsmd = rs.getMetaData();
662:                assertEquals("longsysname", rsmd.getColumnTypeName(1));
663:                assertEquals(Types.VARCHAR, rsmd.getColumnType(1));
664:            }
665:
666:            private boolean isVersion12orHigher() throws Exception {
667:                if (con.getMetaData().getDatabaseProductVersion().startsWith(
668:                        "1.")) {
669:                    // 11.03 or 10.0
670:                    return false;
671:                }
672:                return Integer.parseInt(con.getMetaData()
673:                        .getDatabaseProductVersion().substring(0, 2)) >= 12;
674:            }
675:
676:            private boolean isVersion15orHigher() throws Exception {
677:                if (con.getMetaData().getDatabaseProductVersion().startsWith(
678:                        "1.")) {
679:                    // 11.03 or 10.0
680:                    return false;
681:                }
682:                return Integer.parseInt(con.getMetaData()
683:                        .getDatabaseProductVersion().substring(0, 2)) >= 15;
684:            }
685:
686:            public static void main(String[] args) {
687:                junit.textui.TestRunner.run(Tds5Test.class);
688:            }
689:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.