forked from tada/pljava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTester.java
More file actions
864 lines (785 loc) · 23.3 KB
/
Copy pathTester.java
File metadata and controls
864 lines (785 loc) · 23.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
/*
* Copyright (c) 2004, 2005 TADA AB - Taby Sweden
* Distributed under the terms shown in the file COPYRIGHT
* found in the root folder of this project or at
* http://eng.tada.se/osprojects/COPYRIGHT.html
*/
package org.postgresql.pljava.test;
import java.sql.Timestamp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
import java.io.PrintStream;
/**
* Some fairly crude tests. All tests are confided to the schema
* "javatest"
*
* @author Thomas Hallgren
*/
public class Tester
{
private static final int CMD_AMBIGUOUS = -2;
private static final int CMD_UNKNOWN = -1;
private static final int CMD_USER = 0;
private static final int CMD_PASSWORD = 1;
private static final int CMD_DATABASE = 2;
private static final int CMD_HOSTNAME = 3;
private static final int CMD_PORT = 4;
private static final int CMD_DEBUG = 5;
private static final int CMD_EXCLUDE = 6;
private final Connection m_connection;
private static final ArrayList s_commands = new ArrayList();
static
{
s_commands.add(CMD_USER, "user");
s_commands.add(CMD_PASSWORD, "password");
s_commands.add(CMD_DATABASE, "database");
s_commands.add(CMD_HOSTNAME, "host");
s_commands.add(CMD_PORT, "port");
s_commands.add(CMD_DEBUG, "debug");
s_commands.add(CMD_EXCLUDE, "exclude");
}
private static final int getCommand(String arg)
{
int top = s_commands.size();
int candidateCmd = CMD_UNKNOWN;
for(int idx = 0; idx < top; ++idx)
{
if(((String)s_commands.get(idx)).startsWith(arg))
{
if(candidateCmd != CMD_UNKNOWN)
return CMD_AMBIGUOUS;
candidateCmd = idx;
}
}
return candidateCmd;
}
public static void printUsage()
{
PrintStream out = System.err;
out.println("usage: java org.postgresql.pljava.test.Tester");
out.println(" [ -host <hostName> ] # default is localhost");
out.println(" [ -port <portNubmer> ] # default is blank");
out
.println(" [ -database <database> ] # default is name of current user");
out
.println(" [ -user <userName> ] # default is name of current user");
out.println(" [ -password <password> ] # default is no password");
out
.println(" [ -exclude excludePattern ] # exclude tests matching pattern");
out
.println(" [ -debug ] # wait for debugger to attach to backend");
}
public static void main(String[] argv)
{
String driverClass = "org.postgresql.Driver";
String hostName = "localhost";
String portNumber = null;
String userName = System.getProperty("user.name", "postgres");
String database = userName;
String subsystem = "postgresql";
String password = null;
String exclude = null;
boolean debug = false;
int top = argv.length;
for(int idx = 0; idx < top; ++idx)
{
String arg = argv[idx];
if(arg.length() < 2)
{
printUsage();
return;
}
if(arg.charAt(0) == '-')
{
int optCmd = getCommand(arg.substring(1));
switch(optCmd)
{
case CMD_DEBUG:
debug = true;
break;
case CMD_USER:
if(++idx < top)
{
userName = argv[idx];
if(userName.length() > 0
&& userName.charAt(0) != '-')
break;
}
printUsage();
return;
case CMD_PASSWORD:
if(++idx < top)
{
password = argv[idx];
if(password.length() > 0
&& password.charAt(0) != '-')
break;
}
printUsage();
return;
case CMD_DATABASE:
if(++idx < top)
{
database = argv[idx];
if(database.length() > 0
&& database.charAt(0) != '-')
break;
}
printUsage();
return;
case CMD_HOSTNAME:
if(++idx < top)
{
hostName = argv[idx];
if(hostName.length() > 0
&& hostName.charAt(0) != '-')
break;
}
printUsage();
return;
case CMD_EXCLUDE:
if(++idx < top)
{
exclude = argv[idx];
if(exclude.length() > 0 && exclude.charAt(0) != '-')
break;
}
printUsage();
return;
case CMD_PORT:
if(++idx < top)
{
portNumber = argv[idx];
if(portNumber.length() > 0
&& portNumber.charAt(0) != '-')
break;
}
printUsage();
return;
default:
printUsage();
return;
}
}
}
try
{
Class.forName(driverClass);
StringBuffer cc = new StringBuffer();
cc.append("jdbc:");
cc.append(subsystem);
cc.append("://");
cc.append(hostName);
if(portNumber != null)
{
cc.append(':');
cc.append(portNumber);
}
cc.append('/');
cc.append(database);
Connection c = DriverManager.getConnection(cc.toString(), userName,
password);
Tester t = new Tester(c);
if(debug)
{
System.out.println("Attach debugger to backend");
Thread.sleep(30000);
System.out.println("continuing");
}
for(int idx = 0; idx < 10; ++idx)
{
Pattern p = (exclude == null) ? null : Pattern.compile(exclude, Pattern.CASE_INSENSITIVE);
if(p == null || !p.matcher("parameters").matches())
t.testParameters();
if(p == null || !p.matcher("usernametrigger").matches())
t.testInsertUsernameTrigger();
if(p == null || !p.matcher("moddatetimetrigger").matches())
t.testModdatetimeTrigger();
if(p == null || !p.matcher("spiactions").matches())
t.testSPIActions();
if(p == null || !p.matcher("tuplereturn").matches())
t.testTupleReturn();
if(p == null || !p.matcher("setreturn").matches())
t.testSetReturn();
if(p == null || !p.matcher("callincall").matches())
t.testCallInCall();
if(p == null || !p.matcher("currentdir").matches())
t.testCurrentDir();
if(p == null || !p.matcher("usingproperties").matches())
t.testUsingProperties();
if(p == null || !p.matcher("usingscalarproperties").matches())
t.testUsingScalarProperties();
if(p == null || !p.matcher("usingresultsetproperties").matches())
t.testUsingResultSetProperties();
if(p == null || !p.matcher("savepointsanity").matches())
t.testSavepointSanity();
if(p == null || !p.matcher("transactionrecovery").matches())
t.testTransactionRecovery();
if(p == null || !p.matcher("trustedsecurity").matches())
t.testTrustedSecurity();
if(p == null || !p.matcher("binarycolumns").matches())
t.testBinaryColumns();
if(p == null || !p.matcher("databasemetadata").matches())
t.testDatabaseMetaData();
if(p == null || !p.matcher("resultset").matches())
t.testResultSet();
if(p == null || !p.matcher("complexscalar").matches())
t.testComplexScalar();
if(p == null || !p.matcher("complextuple").matches())
t.testComplexTuple();
}
t.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public Tester(Connection conn) throws SQLException
{
Statement stmt = conn.createStatement();
stmt.execute("SET search_path TO javatest,public");
stmt.close();
m_connection = conn;
}
public void close() throws SQLException
{
m_connection.close();
}
public void testParameters() throws SQLException
{
this.testTimestamp();
this.testInt();
}
public void testSPIActions() throws SQLException
{
System.out.println("*** testSPIActions()");
Statement stmt = m_connection.createStatement();
stmt.execute("DELETE FROM employees1");
stmt.execute("DELETE FROM employees2");
stmt.execute("INSERT INTO employees1 VALUES("
+ "1, 'Calvin Forrester', 10000)");
stmt.execute("INSERT INTO employees1 VALUES("
+ "2, 'Edwin Archer', 20000)");
stmt.execute("INSERT INTO employees1 VALUES("
+ "3, 'Rebecka Shawn', 30000)");
stmt.execute("INSERT INTO employees1 VALUES("
+ "4, 'Priscilla Johnson', 25000)");
stmt.execute("SELECT transferPeople(20000)");
ResultSet rs = stmt.executeQuery("SELECT * FROM employees2");
while(rs.next())
{
int id = rs.getInt(1);
String name = rs.getString(2);
int salary = rs.getInt(3);
System.out.println("Id = \"" + id + "\", name = \"" + name
+ "\", salary = \"" + salary + "\"");
}
rs.close();
}
public void testTupleReturn() throws SQLException
{
System.out.println("*** testTupleReturn()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT tupleReturnToString(tupleReturnExample(1, 5))");
while(rs.next())
{
String str = rs.getString(1);
System.out.println(str);
}
rs.close();
rs = stmt.executeQuery("SELECT tupleReturnToString(tupleReturnExample2(1, NULL))");
while(rs.next())
{
String str = rs.getString(1);
System.out.println(str);
}
rs.close();
}
public void testSetReturn() throws SQLException
{
System.out.println("*** testSetReturn()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT base, incbase, ctime FROM setReturnExample(1, 5)");
while(rs.next())
{
int base = rs.getInt(1);
int incbase = rs.getInt(2);
Timestamp ctime = rs.getTimestamp(3);
System.out.println("Base = \"" + base + "\", incbase = \""
+ incbase + "\", ctime = \"" + ctime + "\"");
}
rs.close();
}
public void testUsingProperties() throws SQLException
{
System.out.println("*** testUsingProperties()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT name, value FROM propertyExample()");
while(rs.next())
{
String name = rs.getString(1);
String value = rs.getString(2);
System.out.println("Name = \"" + name + "\", value = \"" + value
+ "\"");
}
rs.close();
}
public void testUsingResultSetProperties() throws SQLException
{
System.out.println("*** testUsingResultSetProperties()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT name, value FROM resultSetPropertyExample()");
while(rs.next())
{
String name = rs.getString(1);
String value = rs.getString(2);
System.out.println("Name = \"" + name + "\", value = \"" + value
+ "\"");
}
rs.close();
}
public void testUsingScalarProperties() throws SQLException
{
System.out.println("*** testUsingScalarProperties()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT scalarPropertyExample()");
while(rs.next())
System.out.println(rs.getString(1));
rs.close();
}
public void testBinaryColumns() throws SQLException
{
System.out.println("*** testBinaryColumns()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM binaryColumnTest()");
while(rs.next())
{
byte[] b1 = rs.getBytes(1);
byte[] b2 = rs.getBytes(2);
if(!Arrays.equals(b1, b2))
throw new SQLException("binary columns differ");
}
rs.close();
}
public void testCallInCall() throws SQLException
{
System.out.println("*** testCallInCall()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT maxFromSetReturnExample(10, 8)");
while(rs.next())
{
int max = rs.getInt(1);
System.out.println("Max = \"" + max + "\"");
}
}
public void testModdatetimeTrigger() throws SQLException
{
System.out.println("*** testModdatetimeTrigger()");
Statement stmt = m_connection.createStatement();
stmt.execute("DELETE FROM mdt");
stmt.execute("INSERT INTO mdt VALUES (1, 'first')");
stmt.execute("INSERT INTO mdt VALUES (2, 'second')");
stmt.execute("INSERT INTO mdt VALUES (3, 'third')");
ResultSet rs = stmt.executeQuery("SELECT * FROM mdt");
while(rs.next())
{
int id = rs.getInt(1);
String idesc = rs.getString(2);
Timestamp moddate = rs.getTimestamp(3);
System.out.println("Id = \"" + id + "\", idesc = \"" + idesc
+ "\", moddate = \"" + moddate + "\"");
}
rs.close();
stmt.execute("UPDATE mdt SET id = 4 WHERE id = 1");
stmt.execute("UPDATE mdt SET id = 5 WHERE id = 2");
stmt.execute("UPDATE mdt SET id = 6 WHERE id = 3");
rs = stmt.executeQuery("SELECT * FROM mdt");
while(rs.next())
{
int id = rs.getInt(1);
String idesc = rs.getString(2);
Timestamp moddate = rs.getTimestamp(3);
System.out.println("Id = \"" + id + "\", idesc = \"" + idesc
+ "\", moddate = \"" + moddate + "\"");
}
rs.close();
stmt.close();
}
public void testInsertUsernameTrigger() throws SQLException
{
System.out.println("*** testInsertUsernameTrigger()");
Statement stmt = m_connection.createStatement();
stmt.execute("DELETE FROM username_test");
stmt.execute("INSERT INTO username_test VALUES ('nothing', 'thomas')");
stmt.execute("INSERT INTO username_test VALUES ('null', null)");
stmt.execute("INSERT INTO username_test VALUES ('empty string', '')");
stmt.execute("INSERT INTO username_test VALUES ('space', ' ')");
stmt.execute("INSERT INTO username_test VALUES ('tab', ' ')");
stmt.execute("INSERT INTO username_test VALUES ('name', 'name')");
ResultSet rs = stmt.executeQuery("SELECT * FROM username_test");
while(rs.next())
{
String name = rs.getString(1);
String username = rs.getString(2);
System.out.println("Name = \"" + name + "\", username = \""
+ username + "\"");
}
rs.close();
// Test the update trigger as well as leaking statements
//
// System.out.println("Doing 800 updates with double triggers that leak
// statements");
// System.out.println("(but not leak memory). One trigger executes SQL
// that reenters PL/Java");
// for(int idx = 0; idx < 200; ++idx)
// {
// stmt.execute("UPDATE username_test SET username = 'Kalle Kula' WHERE
// username = 'name'");
// stmt.execute("UPDATE username_test SET username = 'Pelle Kanin' WHERE
// username = 'thomas'");
// stmt.execute("UPDATE username_test SET username = 'thomas' WHERE
// username = 'Kalle Kula'");
// stmt.execute("UPDATE username_test SET username = 'name' WHERE
// username = 'Pelle Kanin'");
// }
stmt.close();
}
public void testTimestamp() throws SQLException
{
System.out.println("*** testTimestamp()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT java_getTimestamp(), java_getTimestamptz()");
if(!rs.next())
System.out.println("Unable to position ResultSet");
else
System.out.println("Timestamp = " + rs.getTimestamp(1)
+ ", Timestamptz = " + rs.getTimestamp(2));
rs.close();
// Test parameter overloading. Set log_min_messages (in posgresql.conf)
// to INFO or higher and watch the result.
//
stmt.execute("SELECT print(current_date)");
stmt.execute("SELECT print(current_time)");
stmt.execute("SELECT print(current_timestamp)");
stmt.close();
}
public void testInt() throws SQLException
{
System.out.println("*** testInt()");
/*
* Test parameter override from int primitive to java.lang.Integer Test
* return value override (stipulated by the Java method rather than in
* the function declaration. Seems to be that way according to the
* SQL-2003 spec). Test function call within function call and function
* that returns an object rather than a primitive to reflect null
* values.
*/
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT java_addOne(java_addOne(54)), nullOnEven(1), nullOnEven(2)");
if(!rs.next())
System.out.println("Unable to position ResultSet");
else
{
System.out.println("54 + 2 = " + rs.getInt(1));
int n = rs.getInt(2);
System.out.println("nullOnEven(1) = "
+ (rs.wasNull() ? "null" : Integer.toString(n)));
n = rs.getInt(3);
System.out.println("nullOnEven(2) = "
+ (rs.wasNull() ? "null" : Integer.toString(n)));
}
rs.close();
stmt.close();
}
public void testComplexScalar() throws SQLException
{
System.out.println("*** testComplexScalar()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT logcomplex('(34.56,12.78)'::complex)");
if(!rs.next())
System.out.println("Unable to position ResultSet");
else
System.out.println(rs.getString(1));
rs.close();
stmt.close();
}
public void testComplexTuple() throws SQLException
{
System.out.println("*** testComplexTuple()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT logcomplex((34.56,12.78)::complextuple)");
if(!rs.next())
System.out.println("Unable to position ResultSet");
else
System.out.println(rs.getString(1));
rs.close();
stmt.close();
}
public void testCurrentDir() throws SQLException
{
System.out.println("*** testCurrentDir()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt
.executeQuery("SELECT java_getSystemProperty('user.dir')");
if(!rs.next())
System.out.println("Unable to position ResultSet");
else
System.out.println("Server directory = " + rs.getString(1));
rs.close();
stmt.close();
}
public void testSavepointSanity() throws SQLException
{
System.out.println("*** testSavepointSanity()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT testSavepointSanity()");
if(!rs.next())
System.out.println("Unable to position ResultSet");
else
System.out.println("Savepoint sanity = " + rs.getInt(1));
rs.close();
stmt.close();
}
public void testTransactionRecovery() throws SQLException
{
System.out.println("*** testTransactionRecovery()");
Statement stmt = m_connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT testTransactionRecovery()");
if(!rs.next())
System.out.println("Unable to position ResultSet");
else
System.out.println("Transaction recovery = " + rs.getInt(1));
rs.close();
stmt.close();
}
public void testTrustedSecurity() throws SQLException
{
System.out.println("*** testTrustedSecurity()");
Statement stmt = m_connection.createStatement();
ResultSet rs = null;
tryCreateTempFile(true);
boolean funcCreated = false;
try
{
rs = stmt.executeQuery("SHOW IS_SUPERUSER");
if(!(rs.next() && rs.getString(1).equals("on")))
{
System.out
.println("Tester is not superuser so tests on untrusted language cannot be performed");
return;
}
// Try the same java method again, this time using language javaU
//
System.out.println("*** testUntrustedSecurity()");
stmt
.execute("CREATE OR REPLACE FUNCTION javatest.create_temp_file_untrusted()"
+ " RETURNS varchar"
+ " AS 'org.postgresql.pljava.example.Security.createTempFile'"
+ " LANGUAGE javaU");
tryCreateTempFile(false);
}
finally
{
if(rs != null)
{
try
{
rs.close();
}
catch(SQLException e)
{
}
rs = null;
}
if(funcCreated)
stmt
.execute("DROP FUNCTION javatest.create_temp_file_untrusted()");
stmt.close();
}
}
private void tryCreateTempFile(boolean trusted) throws SQLException
{
Statement stmt = m_connection.createStatement();
ResultSet rs = null;
try
{
if(trusted)
rs = stmt.executeQuery("SELECT create_temp_file_trusted()");
else
rs = stmt.executeQuery("SELECT create_temp_file_untrusted()");
if(!rs.next())
System.out.println("Unable to position ResultSet");
else
System.out.println("Name of created temp file = "
+ rs.getString(1));
if(trusted)
throw new RuntimeException(
"ERROR: Tempfile creation succeded although language is trusted!");
}
catch(SQLException e)
{
if(!trusted)
throw e;
System.out
.println("OK, creation of temp file was *unsuccessful* as it should be");
}
finally
{
if(rs != null)
{
try
{
rs.close();
}
catch(SQLException e)
{
}
rs = null;
}
stmt.close();
}
}
public void testDatabaseMetaData() throws SQLException
{
Statement stmt = m_connection.createStatement();
ResultSet rs = null;
try
{
System.out.println("*** DatabaseMetaData 'String' functions:");
rs = stmt
.executeQuery("SELECT * FROM javatest.getMetaDataStrings()");
while(rs.next())
{
String methodName = rs.getString(1);
String methodResult = rs.getString(2);
System.out.println("Method = \"" + methodName
+ "\", result = \"" + methodResult + "\"");
}
rs.close();
System.out.println("*** DatabaseMetaData 'boolean' functions:");
rs = stmt
.executeQuery("SELECT * FROM javatest.getMetaDataBooleans()");
while(rs.next())
{
String methodName = rs.getString(1);
boolean methodResult = rs.getBoolean(2);
System.out.println("Method = \"" + methodName
+ "\", result = \"" + methodResult + "\"");
}
rs.close();
System.out.println("*** DatabaseMetaData 'int' functions:");
rs = stmt.executeQuery("SELECT * FROM javatest.getMetaDataInts()");
while(rs.next())
{
String methodName = rs.getString(1);
int methodResult = rs.getInt(2);
System.out.println("Method = \"" + methodName
+ "\", result = \"" + methodResult + "\"");
}
rs.close();
executeMetaDataFunction(stmt,
"getAttributes((String)null,\"javatest\",\"%\",\"%\")");
executeMetaDataFunction(stmt,
"getBestRowIdentifier((String)null,\"sqlj\",\"jar_repository\",0,FALSE)");
executeMetaDataFunction(stmt, "getCatalogs()");
executeMetaDataFunction(stmt,
"getColumnPrivileges((String)null,\"sqlj\",\"jar_repository\",\"jarid\")");
executeMetaDataFunction(stmt,
"getColumns((String)null,\"sqlj\",\"jar_repository\",\"%\")");
executeMetaDataFunction(
stmt,
"getCrossReference((String)null,\"sqlj\",\"jar_repository\",(String)null,\"sqlj\",\"jar_entry\")");
executeMetaDataFunction(stmt,
"getExportedKeys((String)null,\"sqlj\",\"jar_repository\")");
executeMetaDataFunction(stmt,
"getImportedKeys((String)null,\"sqlj\",\"jar_repository\")");
executeMetaDataFunction(stmt,
"getIndexInfo((String)null,\"sqlj\",\"jar_repository\",TRUE,FALSE)");
executeMetaDataFunction(stmt,
"getPrimaryKeys((String)null,\"sqlj\",\"jar_repository\")");
executeMetaDataFunction(stmt,
"getProcedureColumns((String)null,\"sqlj\",\"install_jar\",(String)null)");
executeMetaDataFunction(stmt,
"getProcedures((String)null,\"sqlj\",\"%\")");
executeMetaDataFunction(stmt, "getSchemas()");
executeMetaDataFunction(stmt,
"getSuperTables((String)null,\"sqlj\",\"jar_repository\")");
executeMetaDataFunction(stmt,
"getSuperTypes((String)null,\"sqlj\",\"%\")");
executeMetaDataFunction(stmt,
"getTablePrivileges((String)null,\"sqlj\",\"jar_repository\")");
executeMetaDataFunction(stmt,
"getTables((String)null,\"sqlj\",\"jar%\",{\"TABLE\"})");
executeMetaDataFunction(stmt, "getTableTypes()");
executeMetaDataFunction(stmt, "getTypeInfo()");
executeMetaDataFunction(stmt,
"getUDTs((String)null,\"sqlj\",\"%\",(int[])null)");
executeMetaDataFunction(stmt,
"getVersionColumns((String)null,\"sqlj\",\"jar_repository\")");
}
finally
{
if(rs != null)
{
try
{
rs.close();
}
catch(SQLException e)
{
}
rs = null;
}
}
}
private void executeMetaDataFunction(Statement stmt, String functionCall)
throws SQLException
{
ResultSet rs = null;
try
{
System.out.println("*** " + functionCall + ":");
rs = stmt
.executeQuery("SELECT * FROM javatest.callMetaDataMethod('"
+ functionCall + "')");
while(rs.next())
{
System.out.println(rs.getString(1));
}
rs.close();
}
catch(Exception e)
{
System.out.println(" Failed: " + e.getMessage());
}
finally
{
if(rs != null)
{
try
{
rs.close();
}
catch(SQLException e)
{
}
rs = null;
}
}
}
}