KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > test > db > TestCases


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.test.db;
6
7 import java.io.File JavaDoc;
8 import java.io.StringReader JavaDoc;
9 import java.sql.Connection JavaDoc;
10 import java.sql.Date JavaDoc;
11 import java.sql.PreparedStatement JavaDoc;
12 import java.sql.ResultSet JavaDoc;
13 import java.sql.SQLException JavaDoc;
14 import java.sql.Statement JavaDoc;
15 import java.sql.Time JavaDoc;
16 import java.sql.Timestamp JavaDoc;
17 import java.util.Random JavaDoc;
18
19 import org.h2.test.TestBase;
20
21 public class TestCases extends TestBase {
22
23     
24     public void test() throws Exception JavaDoc {
25         testDisconnect();
26         testExecuteTrace();
27         if(config.memory || config.logMode == 0) {
28             return;
29         }
30         testSpecialSQL();
31         testUpperCaseLowerCaseDatabase();
32         testManualCommitSet();
33         testSchemaIdentityReconnect();
34         testAlterTableReconnect();
35         testPersistentSettings();
36         testInsertSelectUnion();
37         testViewReconnect();
38         testDefaultQueryReconnect();
39         testBigString();
40         testRenameReconnect();
41         testAllSizes();
42         testCreateDrop();
43         testPolePos();
44         testQuick();
45         testMutableObjects();
46         testSelectForUpdate();
47         testDoubleRecovery();
48         testConstraintReconnect();
49         testCollation();
50     }
51
52     private void testSpecialSQL() throws Exception JavaDoc {
53         deleteDb("cases");
54         Connection JavaDoc conn=getConnection("cases");
55         Statement JavaDoc stat = conn.createStatement();
56         stat.execute("SET AUTOCOMMIT OFF; \n//create sequence if not exists object_id;\n");
57         stat.execute("SET AUTOCOMMIT OFF;\n//create sequence if not exists object_id;\n");
58         stat.execute("SET AUTOCOMMIT OFF; //create sequence if not exists object_id;");
59         stat.execute("SET AUTOCOMMIT OFF;//create sequence if not exists object_id;");
60         stat.execute("SET AUTOCOMMIT OFF \n//create sequence if not exists object_id;");
61         stat.execute("SET AUTOCOMMIT OFF\n//create sequence if not exists object_id;");
62         stat.execute("SET AUTOCOMMIT OFF //create sequence if not exists object_id;");
63         stat.execute("SET AUTOCOMMIT OFF//create sequence if not exists object_id;");
64         stat.execute("SET AUTOCOMMIT OFF; \n///create sequence if not exists object_id;");
65         stat.execute("SET AUTOCOMMIT OFF;\n///create sequence if not exists object_id;");
66         stat.execute("SET AUTOCOMMIT OFF; ///create sequence if not exists object_id;");
67         stat.execute("SET AUTOCOMMIT OFF;///create sequence if not exists object_id;");
68         stat.execute("SET AUTOCOMMIT OFF \n///create sequence if not exists object_id;");
69         stat.execute("SET AUTOCOMMIT OFF\n///create sequence if not exists object_id;");
70         stat.execute("SET AUTOCOMMIT OFF ///create sequence if not exists object_id;");
71         stat.execute("SET AUTOCOMMIT OFF///create sequence if not exists object_id;");
72         conn.close();
73     }
74     
75     private void testUpperCaseLowerCaseDatabase() throws Exception JavaDoc {
76         if(File.separatorChar != '\\') {
77             return;
78         }
79         deleteDb("cases");
80         deleteDb("CaSeS");
81         Connection JavaDoc conn, conn2;
82         ResultSet JavaDoc rs;
83         conn=getConnection("cases");
84         Statement JavaDoc stat = conn.createStatement();
85         stat.execute("CHECKPOINT");
86         stat.execute("CREATE TABLE TEST(ID INT)");
87         stat.execute("INSERT INTO TEST VALUES(1)");
88         stat.execute("CHECKPOINT");
89
90         conn2=getConnection("CaSeS");
91         rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
92         check(rs.next());
93         conn2.close();
94         
95         conn.close();
96
97         conn=getConnection("cases");
98         rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
99         check(rs.next());
100         conn.close();
101
102         conn=getConnection("CaSeS");
103         rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
104         check(rs.next());
105         conn.close();
106         
107         deleteDb("cases");
108         deleteDb("CaSeS");
109         
110     }
111
112     private void testManualCommitSet() throws Exception JavaDoc {
113         deleteDb("cases");
114         Connection JavaDoc conn=getConnection("cases");
115         Connection JavaDoc conn2=getConnection("cases");
116         conn.setAutoCommit(false);
117         conn2.setAutoCommit(false);
118         conn.createStatement().execute("SET MODE REGULAR");
119         conn2.createStatement().execute("SET MODE REGULAR");
120         conn.close();
121         conn2.close();
122     }
123     
124     private void testSchemaIdentityReconnect() throws Exception JavaDoc {
125         deleteDb("cases");
126         Connection JavaDoc conn=getConnection("cases");
127         Statement JavaDoc stat = conn.createStatement();
128         stat.execute("create schema s authorization sa");
129         stat.execute("create table s.test(id identity)");
130         conn.close();
131         conn=getConnection("cases");
132         ResultSet JavaDoc rs = conn.createStatement().executeQuery("SELECT * FROM S.TEST");
133         while(rs.next()) {
134             // ignore
135
}
136         conn.close();
137     }
138     
139     private void testDisconnect() throws Exception JavaDoc {
140         if(config.networked) {
141             return;
142         }
143         deleteDb("cases");
144         Connection JavaDoc conn=getConnection("cases");
145         final Statement JavaDoc stat = conn.createStatement();
146         stat.execute("CREATE TABLE TEST(ID IDENTITY)");
147         for(int i=0; i<1000; i++) {
148             stat.execute("INSERT INTO TEST() VALUES()");
149         }
150         final SQLException JavaDoc[] stopped = new SQLException JavaDoc[1];
151         Thread JavaDoc t = new Thread JavaDoc(new Runnable JavaDoc() {
152             public void run() {
153                 try {
154                     long time = System.currentTimeMillis();
155                     ResultSet JavaDoc rs = stat.executeQuery("SELECT MAX(T.ID) FROM TEST T, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST, TEST");
156                     rs.next();
157                     time = System.currentTimeMillis() - time;
158                     TestBase.logError("query was too quick; result: " + rs.getInt(1) + " time:" + time, null);
159                 } catch(SQLException JavaDoc e) {
160                     stopped[0] = e;
161                     // ok
162
}
163             }
164         });
165         t.start();
166         Thread.sleep(500);
167         long time = System.currentTimeMillis();
168         conn.close();
169         t.join(5000);
170         if(stopped[0] == null) {
171             error("query still running");
172         } else {
173             checkNotGeneralException(stopped[0]);
174         }
175         time = System.currentTimeMillis() - time;
176         if(time > 5000) {
177             error("closing took " + time);
178         }
179         deleteDb("cases");
180     }
181     
182     private void testExecuteTrace() throws Exception JavaDoc {
183         deleteDb("cases");
184         Connection JavaDoc conn=getConnection("cases");
185         Statement JavaDoc stat = conn.createStatement();
186         ResultSet JavaDoc rs = stat.executeQuery("SELECT ? FROM DUAL {1: 'Hello'}");
187         rs.next();
188         check("Hello", rs.getString(1));
189         checkFalse(rs.next());
190         rs = stat.executeQuery("SELECT ? FROM DUAL UNION ALL SELECT ? FROM DUAL {1: 'Hello', 2:'World' }");
191         rs.next();
192         check("Hello", rs.getString(1));
193         rs.next();
194         check("World", rs.getString(1));
195         checkFalse(rs.next());
196         conn.close();
197     }
198     
199     private void testAlterTableReconnect() throws Exception JavaDoc {
200         deleteDb("cases");
201         Connection JavaDoc conn=getConnection("cases");
202         Statement JavaDoc stat = conn.createStatement();
203         stat.execute("create table test(id identity);");
204         stat.execute("insert into test values(1);");
205         try {
206             stat.execute("alter table test add column name varchar not null;");
207             error("shouldn't work");
208         } catch(SQLException JavaDoc e) {
209             checkNotGeneralException(e);
210         }
211         conn.close();
212         conn=getConnection("cases");
213         ResultSet JavaDoc rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
214         rs.next();
215         check(rs.getString(1), "1");
216         checkFalse(rs.next());
217         stat = conn.createStatement();
218         stat.execute("drop table test");
219         stat.execute("create table test(id identity)");
220         stat.execute("insert into test values(1)");
221         stat.execute("alter table test alter column id set default 'x'");
222         conn.close();
223         conn=getConnection("cases");
224         stat = conn.createStatement();
225         rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
226         rs.next();
227         check(rs.getString(1), "1");
228         checkFalse(rs.next());
229         stat.execute("drop table test");
230         stat.execute("create table test(id identity)");
231         stat.execute("insert into test values(1)");
232         try {
233             stat.execute("alter table test alter column id date");
234             error("shouldn't work");
235         } catch(SQLException JavaDoc e) {
236             checkNotGeneralException(e);
237         }
238         conn.close();
239         conn=getConnection("cases");
240         rs = conn.createStatement().executeQuery("SELECT * FROM TEST");
241         rs.next();
242         check(rs.getString(1), "1");
243         checkFalse(rs.next());
244         conn.close();
245     }
246     
247     private void testCollation() throws Exception JavaDoc {
248         deleteDb("cases");
249         Connection JavaDoc conn=getConnection("cases");
250         Statement JavaDoc stat = conn.createStatement();
251         stat.execute("SET COLLATION ENGLISH STRENGTH PRIMARY");
252         stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
253         stat.execute("INSERT INTO TEST VALUES(1, 'Hello'), (2, 'World'), (3, 'WORLD'), (4, 'HELLO')");
254         stat.execute("create index idxname on test(name)");
255         ResultSet JavaDoc rs;
256         rs = stat.executeQuery("select name from test order by name");
257         rs.next();
258         check(rs.getString(1), "Hello");
259         rs.next();
260         check(rs.getString(1), "HELLO");
261         rs.next();
262         check(rs.getString(1), "World");
263         rs.next();
264         check(rs.getString(1), "WORLD");
265         rs = stat.executeQuery("select name from test where name like 'He%'");
266         rs.next();
267         check(rs.getString(1), "Hello");
268         rs.next();
269         check(rs.getString(1), "HELLO");
270         conn.close();
271     }
272     
273     private void testPersistentSettings() throws Exception JavaDoc {
274         deleteDb("cases");
275         Connection JavaDoc conn=getConnection("cases");
276         Statement JavaDoc stat = conn.createStatement();
277         stat.execute("SET COLLATION de_DE");
278         stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR)");
279         stat.execute("CREATE INDEX IDXNAME ON TEST(NAME)");
280         // \u00f6 = oe
281
stat.execute("INSERT INTO TEST VALUES(1, 'B\u00f6hlen'), (2, 'Bach'), (3, 'Bucher')");
282         conn.close();
283         conn=getConnection("cases");
284         ResultSet JavaDoc rs = conn.createStatement().executeQuery("SELECT NAME FROM TEST ORDER BY NAME");
285         rs.next();
286         check(rs.getString(1), "Bach");
287         rs.next();
288         check(rs.getString(1), "B\u00f6hlen");
289         rs.next();
290         check(rs.getString(1), "Bucher");
291         conn.close();
292     }
293     
294     private void testInsertSelectUnion() throws Exception JavaDoc {
295         deleteDb("cases");
296         Connection JavaDoc conn=getConnection("cases");
297         Statement JavaDoc stat = conn.createStatement();
298         stat.execute("CREATE TABLE TEST(ORDER_ID INT PRIMARY KEY, ORDER_DATE DATETIME, USER_ID INT ,"
299                 +"DESCRIPTION VARCHAR, STATE VARCHAR, TRACKING_ID VARCHAR)");
300         Timestamp JavaDoc orderDate = Timestamp.valueOf("2005-05-21 17:46:00");
301         String JavaDoc sql = "insert into TEST (ORDER_ID,ORDER_DATE,USER_ID,DESCRIPTION,STATE,TRACKING_ID) "
302             +"select cast(? as int),cast(? as date),cast(? as int),cast(? as varchar),cast(? as varchar),cast(? as varchar) union all select ?,?,?,?,?,?";
303         PreparedStatement JavaDoc ps = conn.prepareStatement(sql);
304         ps.setInt(1, 5555);
305         ps.setTimestamp(2, orderDate);
306         ps.setInt(3, 2222);
307         ps.setString(4, "test desc");
308         ps.setString(5, "teststate");
309         ps.setString(6, "testid");
310         ps.setInt(7, 5556);
311         ps.setTimestamp(8, orderDate);
312         ps.setInt(9, 2222);
313         ps.setString(10, "test desc");
314         ps.setString(11, "teststate");
315         ps.setString(12, "testid");
316         check(ps.executeUpdate(), 2);
317         ps.close();
318         conn.close();
319     }
320     
321     private void testViewReconnect() throws Exception JavaDoc {
322         trace("testViewReconnect");
323         deleteDb("cases");
324         Connection JavaDoc conn=getConnection("cases");
325         Statement JavaDoc stat = conn.createStatement();
326         stat.execute("create table test(id int)");
327         stat.execute("create view abc as select * from test");
328         stat.execute("drop table test");
329         conn.close();
330         conn = getConnection("cases");
331         stat = conn.createStatement();
332         try {
333             stat.execute("select * from abc");
334             error("abc should be deleted");
335         } catch(SQLException JavaDoc e) {
336             checkNotGeneralException(e);
337         }
338         conn.close();
339     }
340     
341     private void testDefaultQueryReconnect() throws Exception JavaDoc {
342         trace("testDefaultQueryReconnect");
343         deleteDb("cases");
344         Connection JavaDoc conn=getConnection("cases");
345         Statement JavaDoc stat = conn.createStatement();
346         stat.execute("create table parent(id int)");
347         stat.execute("insert into parent values(1)");
348         stat.execute("create table test(id int default (select max(id) from parent), name varchar)");
349         
350         conn.close();
351         conn = getConnection("cases");
352         stat = conn.createStatement();
353         conn.setAutoCommit(false);
354         stat.execute("insert into parent values(2)");
355         stat.execute("insert into test(name) values('test')");
356         ResultSet JavaDoc rs = stat.executeQuery("select * from test");
357         rs.next();
358         check(rs.getInt(1), 2);
359         checkFalse(rs.next());
360         conn.close();
361     }
362     
363     private void testBigString() throws Exception JavaDoc {
364         trace("testBigString");
365         deleteDb("cases");
366         Connection JavaDoc conn=getConnection("cases");
367         Statement JavaDoc stat = conn.createStatement();
368         stat.execute("DROP TABLE IF EXISTS TEST");
369         stat.execute("CREATE TABLE TEST(ID INT, TEXT VARCHAR, TEXT_C CLOB)");
370         PreparedStatement JavaDoc prep = conn.prepareStatement("INSERT INTO TEST VALUES(?, ?, ?)");
371         int len = getSize(1000, 66000);
372         char[] buff = new char[len];
373         
374         // The UCS code values 0xd800-0xdfff (UTF-16 surrogates)
375
// as well as 0xfffe and 0xffff (UCS non-characters)
376
// should not appear in conforming UTF-8 streams.
377
// (String.getBytes("UTF-8") only returns 1 byte for 0xd800-0xdfff)
378

379         Random JavaDoc random = new Random JavaDoc();
380         random.setSeed(1);
381         for(int i=0; i<len; i++) {
382             char c;
383             do {
384                 c = (char)random.nextInt();
385             } while(c >= 0xd800 && c <= 0xdfff);
386             buff[i] = c;
387         }
388         String JavaDoc big = new String JavaDoc(buff);
389         prep.setInt(1, 1);
390         prep.setString(2, big);
391         prep.setString(3, big);
392         prep.execute();
393         prep.setInt(1, 2);
394         prep.setCharacterStream(2, new StringReader JavaDoc(big), 0);
395         prep.setCharacterStream(3, new StringReader JavaDoc(big), 0);
396         prep.execute();
397         ResultSet JavaDoc rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
398         rs.next();
399         check(rs.getInt(1), 1);
400         check(rs.getString(2), big);
401         check(readString(rs.getCharacterStream(2)), big);
402         check(rs.getString(3), big);
403         check(readString(rs.getCharacterStream(3)), big);
404         rs.next();
405         check(rs.getInt(1), 2);
406         check(rs.getString(2), big);
407         check(readString(rs.getCharacterStream(2)), big);
408         check(rs.getString(3), big);
409         check(readString(rs.getCharacterStream(3)), big);
410         rs.next();
411         checkFalse(rs.next());
412         conn.close();
413     }
414     
415     private void testConstraintReconnect() throws Exception JavaDoc {
416         trace("testConstraintReconnect");
417         deleteDb("cases");
418         Connection JavaDoc conn=getConnection("cases");
419         Statement JavaDoc stat = conn.createStatement();
420         stat.execute("drop table if exists parent");
421         stat.execute("drop table if exists child");
422         stat.execute("create table parent(id int)");
423         stat.execute("create table child(c_id int, p_id int, foreign key(p_id) references parent(id))");
424         stat.execute("insert into parent values(1), (2)");
425         stat.execute("insert into child values(1, 1)");
426         stat.execute("insert into child values(2, 2)");
427         stat.execute("insert into child values(3, 2)");
428         stat.execute("delete from child");
429         conn.close();
430         conn=getConnection("cases");
431         conn.close();
432     }
433     
434     private void testDoubleRecovery() throws Exception JavaDoc {
435         if(config.networked) {
436             return;
437         }
438         trace("testDoubleRecovery");
439         deleteDb("cases");
440         Connection JavaDoc conn=getConnection("cases");
441         deleteDb("twoPhaseCommit");
442         Statement JavaDoc stat = conn.createStatement();
443         stat.execute("SET WRITE_DELAY 0");
444         stat.execute("DROP TABLE IF EXISTS TEST");
445         stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
446         stat.execute("INSERT INTO TEST VALUES(1, 'Hello')");
447         conn.setAutoCommit(false);
448         stat.execute("INSERT INTO TEST VALUES(2, 'World')");
449         crash(conn);
450         
451         conn=getConnection("cases");
452         stat = conn.createStatement();
453         stat.execute("SET WRITE_DELAY 0");
454         stat.execute("INSERT INTO TEST VALUES(3, 'Break')");
455         crash(conn);
456
457         conn=getConnection("cases");
458         stat = conn.createStatement();
459         ResultSet JavaDoc rs = stat.executeQuery("SELECT * FROM TEST ORDER BY ID");
460         rs.next();
461         check(rs.getInt(1), 1);
462         check(rs.getString(2), "Hello");
463         rs.next();
464         check(rs.getInt(1), 3);
465         check(rs.getString(2), "Break");
466         conn.close();
467     }
468     
469     private void testRenameReconnect() throws Exception JavaDoc {
470         trace("testRenameReconnect");
471         deleteDb("cases");
472         Connection JavaDoc conn=getConnection("cases");
473         conn.createStatement().execute("CREATE TABLE TEST_SEQ(ID INT IDENTITY, NAME VARCHAR(255))");
474         conn.createStatement().execute("CREATE TABLE TEST(ID INT PRIMARY KEY)");
475         conn.createStatement().execute("ALTER TABLE TEST RENAME TO TEST2");
476         conn.createStatement().execute("CREATE TABLE TEST_B(ID INT PRIMARY KEY, NAME VARCHAR, UNIQUE(NAME));");
477         conn.close();
478         conn=getConnection("cases");
479         conn.createStatement().execute("INSERT INTO TEST_SEQ(NAME) VALUES('Hi')");
480         ResultSet JavaDoc rs = conn.createStatement().executeQuery("CALL IDENTITY()");
481         rs.next();
482         check(rs.getInt(1), 1);
483         conn.createStatement().execute("SELECT * FROM TEST2");
484         conn.createStatement().execute("SELECT * FROM TEST_B");
485         conn.createStatement().execute("ALTER TABLE TEST_B RENAME TO TEST_B2");
486         conn.close();
487         conn=getConnection("cases");
488         conn.createStatement().execute("SELECT * FROM TEST_B2");
489         conn.createStatement().execute("INSERT INTO TEST_SEQ(NAME) VALUES('World')");
490         rs = conn.createStatement().executeQuery("CALL IDENTITY()");
491         rs.next();
492         check(rs.getInt(1), 2);
493         conn.close();
494     }
495     
496     private void testAllSizes() throws Exception JavaDoc {
497         trace("testAllSizes");
498         deleteDb("cases");
499         Connection JavaDoc conn=getConnection("cases");
500         Statement JavaDoc stat = conn.createStatement();
501         stat.execute("CREATE TABLE TEST(A INT, B INT, C INT, DATA VARCHAR)");
502         int increment = getSize(100, 1);
503         for(int i=1; i<500; i+=increment) {
504             StringBuffer JavaDoc buff = new StringBuffer JavaDoc();
505             buff.append("CREATE TABLE TEST");
506             for(int j=0; j<i; j++) {
507                 buff.append('a');
508             }
509             buff.append("(ID INT)");
510             String JavaDoc sql = buff.toString();
511             stat.execute(sql);
512             stat.execute("INSERT INTO TEST VALUES("+i+", 0, 0, '"+sql+"')");
513         }
514         conn.close();
515         conn=getConnection("cases");
516         stat = conn.createStatement();
517         ResultSet JavaDoc rs = stat.executeQuery("SELECT * FROM TEST");
518         while(rs.next()) {
519             int id=rs.getInt(1);
520             String JavaDoc s = rs.getString("DATA");
521             if(!s.endsWith(")")) {
522                 error("id="+id);
523             }
524         }
525         conn.close();
526     }
527     
528     private void testSelectForUpdate() throws Exception JavaDoc {
529         trace("testSelectForUpdate");
530         deleteDb("cases");
531         Connection JavaDoc conn1=getConnection("cases");
532         Statement JavaDoc stat1 = conn1.createStatement();
533         stat1.execute("CREATE TABLE TEST(ID INT)");
534         stat1.execute("INSERT INTO TEST VALUES(1)");
535         conn1.setAutoCommit(false);
536         stat1.execute("SELECT * FROM TEST FOR UPDATE");
537         Connection JavaDoc conn2=getConnection("cases");
538         Statement JavaDoc stat2 = conn2.createStatement();
539         try {
540             stat2.execute("UPDATE TEST SET ID=2");
541             error("must fail");
542         } catch(SQLException JavaDoc e) {
543             checkNotGeneralException(e);
544         }
545         conn1.commit();
546         stat2.execute("UPDATE TEST SET ID=2");
547         conn1.close();
548         conn2.close();
549     }
550     
551     private void testMutableObjects() throws Exception JavaDoc {
552         trace("testMutableObjects");
553         deleteDb("cases");
554         Connection JavaDoc conn=getConnection("cases");
555         Statement JavaDoc stat = conn.createStatement();
556         stat.execute("CREATE TABLE TEST(ID INT, D DATE, T TIME, TS TIMESTAMP)");
557         stat.execute("INSERT INTO TEST VALUES(1, '2001-01-01', '20:00:00', '2002-02-02 22:22:22.2')");
558         stat.execute("INSERT INTO TEST VALUES(1, '2001-01-01', '20:00:00', '2002-02-02 22:22:22.2')");
559         ResultSet JavaDoc rs = stat.executeQuery("SELECT * FROM TEST");
560         rs.next();
561         Date JavaDoc d1 = rs.getDate("D");
562         Time JavaDoc t1 = rs.getTime("T");
563         Timestamp JavaDoc ts1 = rs.getTimestamp("TS");
564         rs.next();
565         Date JavaDoc d2 = rs.getDate("D");
566         Time JavaDoc t2 = rs.getTime("T");
567         Timestamp JavaDoc ts2 = rs.getTimestamp("TS");
568         check(ts1 != ts2);
569         check(d1 != d2);
570         check(t1 != t2);
571         check(t2 != rs.getObject("T"));
572         check(d2 != rs.getObject("D"));
573         check(ts2 != rs.getObject("TS"));
574         checkFalse(rs.next());
575         conn.close();
576     }
577     
578     private void testCreateDrop() throws Exception JavaDoc {
579         trace("testCreateDrop");
580         deleteDb("cases");
581         Connection JavaDoc conn=getConnection("cases");
582         Statement JavaDoc stat = conn.createStatement();
583         stat.execute(
584                 "create table employee(id int, "
585                 +"firstname VARCHAR(50), "
586                 +"salary decimal(10, 2), "
587                 +"superior_id int, "
588                 +"CONSTRAINT PK_employee PRIMARY KEY (id), "
589                 +"CONSTRAINT FK_superior FOREIGN KEY (superior_id) "
590                 +"REFERENCES employee(ID))");
591         stat.execute("DROP TABLE employee");
592         conn.close();
593         conn=getConnection("cases");
594         conn.close();
595     }
596     
597     private void testPolePos() throws Exception JavaDoc {
598         trace("testPolePos");
599         // poleposition-0.20
600

601         Connection JavaDoc c0=getConnection("cases");
602         c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
603         c0.createStatement().executeUpdate("create table australia (ID INTEGER NOT NULL, Name VARCHAR(100), FirstName VARCHAR(100), Points INTEGER, LicenseID INTEGER, PRIMARY KEY(ID))");
604         c0.createStatement().executeUpdate("COMMIT");
605         c0.close();
606         
607         c0=getConnection("cases");
608         c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
609         PreparedStatement JavaDoc p15=c0.prepareStatement("insert into australia (id,Name,FirstName,Points,LicenseID) values (?,?,?,?,?)");
610         int len = getSize(1, 1000);
611         for(int i=0; i<len; i++) {
612             p15.setInt(1, i); p15.setString(2, "Pilot_"+i); p15.setString(3, "Herkules"); p15.setInt(4, i); p15.setInt(5, i); p15.executeUpdate();
613         }
614         c0.createStatement().executeUpdate("COMMIT");
615         c0.close();
616         
617 // c0=getConnection("cases");
618
// c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
619
// c0.createStatement().executeQuery("select * from australia");
620
// c0.createStatement().executeQuery("select * from australia");
621
// c0.close();
622

623 // c0=getConnection("cases");
624
// c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
625
// c0.createStatement().executeUpdate("COMMIT");
626
// c0.createStatement().executeUpdate("delete from australia");
627
// c0.createStatement().executeUpdate("COMMIT");
628
// c0.close();
629

630         c0=getConnection("cases");
631         c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
632         c0.createStatement().executeUpdate("drop table australia");
633         c0.createStatement().executeUpdate("create table australia (ID INTEGER NOT NULL, Name VARCHAR(100), FirstName VARCHAR(100), Points INTEGER, LicenseID INTEGER, PRIMARY KEY(ID))");
634         c0.createStatement().executeUpdate("COMMIT");
635         c0.close();
636         
637         c0=getConnection("cases");
638         c0.createStatement().executeUpdate("SET AUTOCOMMIT FALSE");
639         PreparedStatement JavaDoc p65=c0.prepareStatement("insert into australia (id,Name,FirstName,Points,LicenseID) values (?,?,?,?,?)");
640         len = getSize(1, 1000);
641         for(int i=0; i<len; i++) {
642             p65.setInt(1, i); p65.setString(2, "Pilot_"+i); p65.setString(3, "Herkules"); p65.setInt(4, i); p65.setInt(5, i); p65.executeUpdate();
643         }
644         c0.createStatement().executeUpdate("COMMIT");
645         c0.createStatement().executeUpdate("COMMIT");
646         c0.createStatement().executeUpdate("COMMIT");
647         c0.close();
648         
649         c0=getConnection("cases");
650         c0.close();
651     }
652     
653     
654     private void testQuick() throws Exception JavaDoc {
655         trace("testQuick");
656         deleteDb("cases");
657
658         Connection JavaDoc c0=getConnection("cases");
659         c0.createStatement().executeUpdate("create table test (ID int PRIMARY KEY)");
660         c0.createStatement().executeUpdate("insert into test values(1)");
661         c0.createStatement().executeUpdate("drop table test");
662         c0.createStatement().executeUpdate("create table test (ID int PRIMARY KEY)");
663         c0.close();
664         
665         c0=getConnection("cases");
666         c0.createStatement().executeUpdate("insert into test values(1)");
667         c0.close();
668         
669         c0=getConnection("cases");
670         c0.close();
671     }
672     
673
674 }
675
Popular Tags