~maria-captains/mariadb-java-client/trunk

« back to all changes in this revision

Viewing changes to src/main/java/org/mariadb/jdbc/MySQLDatabaseMetaData.java

  • Committer: Vladislav Vaintroub
  • Date: 2013-01-07 00:36:34 UTC
  • Revision ID: wlad@montyprogram.com-20130107003634-pk4rbdc4evgdlwd8
remove common database metadata. move methods to MySQLDatabaseMetaData. This abstraction was only useful to support drizzle server, and now got obsolete

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
import java.sql.*;
53
53
 
54
 
public final class MySQLDatabaseMetaData extends CommonDatabaseMetaData {
55
 
    public MySQLDatabaseMetaData(CommonDatabaseMetaData.Builder builder) {
56
 
        super(builder);
 
54
 
 
55
public class MySQLDatabaseMetaData implements DatabaseMetaData {
 
56
    private String version;
 
57
    private String url;
 
58
    private String username;
 
59
    private Connection connection;
 
60
    private String databaseProductName = "MySQL";
 
61
 
 
62
    protected final String dataTypeClause = " CASE data_type" +
 
63
                        " when 'bit' then "         + Types.BIT +
 
64
                        " when 'tinyblob' then "    + Types.LONGVARBINARY +
 
65
                        " when 'mediumblob' then "  + Types.LONGVARBINARY +
 
66
                        " when 'longblob' then "    + Types.LONGVARBINARY +
 
67
                        " when 'blob' then "        + Types.LONGVARBINARY +
 
68
                        " when 'tinytext' then "    + Types.LONGVARCHAR +
 
69
                        " when 'mediumtext' then "  + Types.LONGVARCHAR +
 
70
                        " when 'longtext' then "    + Types.LONGVARCHAR +
 
71
                        " when 'text' then "        + Types.LONGVARCHAR +
 
72
                        " when 'date' then "        + Types.DATE +
 
73
                        " when 'datetime' then "    + Types.TIMESTAMP +
 
74
                        " when 'decimal' then "     + Types.DECIMAL +
 
75
                        " when 'double' then "      + Types.DOUBLE +
 
76
                        " when 'enum' then "        + Types.VARCHAR +
 
77
                        " when 'float' then "       + Types.FLOAT +
 
78
                        " when 'int' then "         + Types.INTEGER +
 
79
                        " when 'bigint' then "      + Types.BIGINT +
 
80
                        " when 'mediumint' then "   + Types.INTEGER +
 
81
                        " when 'null' then "        + Types.NULL +
 
82
                        " when 'set' then "         + Types.VARCHAR +
 
83
                        " when 'smallint' then "    + Types.SMALLINT +
 
84
                        " when 'varchar' then "     + Types.VARCHAR +
 
85
                        " when 'varbinary' then "   + Types.VARBINARY +
 
86
                        " when 'char' then "        + Types.CHAR +
 
87
                        " when 'binary' then "      + Types.BINARY +
 
88
                        " when 'time' then "        + Types.TIME +
 
89
                        " when 'timestamp' then "   + Types.TIMESTAMP +
 
90
                        " when 'tinyint' then "     + Types.TINYINT +
 
91
                        " when 'year' then "        + Types.SMALLINT +
 
92
                        " END ";
 
93
 
 
94
    public MySQLDatabaseMetaData(Connection connection, String user, String url) {
 
95
        this.connection = connection;
 
96
        this.username = user;
 
97
        this.url = url;
57
98
    }
58
99
 
59
 
    @Override
 
100
 
60
101
    public ResultSet getPrimaryKeys(final String catalog, final String schema, final String table) throws SQLException {
61
102
        final Connection conn = getConnection();
62
 
        String query = "SELECT NULL TABLE_CAT, " +
 
103
        String query = "SELECT NULL TABLE_CAT, " +
63
104
                "table_schema TABLE_SCHEM, " +
64
105
                "table_name, " +
65
106
                "column_name, " +
86
127
        }
87
128
        return tableType;
88
129
    }
89
 
    @Override
 
130
 
 
131
 
90
132
    public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, final String[] types) throws SQLException {
91
133
 
92
134
        if (tableNamePattern == null || tableNamePattern.equals(""))
162
204
                "WHERE ";
163
205
        if (((MySQLConnection)getConnection()).noSchemaPattern == false)
164
206
        {
165
 
                query = query + "table_schema LIKE '" + schemaPattern + "' AND ";
 
207
            query = query + "table_schema LIKE '" + schemaPattern + "' AND ";
166
208
        }
167
209
        query = query + "table_name LIKE '" + tableNamePattern  + "'" +
168
210
                " AND column_name LIKE '" +  columnNamePattern + "'" +
170
212
        final Statement stmt = getConnection().createStatement();
171
213
        return stmt.executeQuery(query);
172
214
    }
173
 
        
 
215
 
174
216
    public ResultSet getExportedKeys(final String catalog, final String schema, final String table) throws SQLException {
175
 
        final Connection conn = getConnection();
176
 
        final String query = "SELECT null PKTABLE_CAT, \n" +
 
217
        final Connection conn = getConnection();
 
218
        final String query = "SELECT null PKTABLE_CAT, \n" +
177
219
                "kcu.referenced_table_schema PKTABLE_SCHEM, \n" +
178
220
                "kcu.referenced_table_name PKTABLE_NAME, \n" +
179
221
                "kcu.referenced_column_name PKCOLUMN_NAME, \n" +
213
255
        return stmt.executeQuery(query);
214
256
    }
215
257
    public ResultSet getImportedKeys(final String catalog, final String schema, final String table) throws SQLException {
216
 
        Connection conn = getConnection();
217
 
        String query = "SELECT null PKTABLE_CAT, \n" +
 
258
        Connection conn = getConnection();
 
259
        String query = "SELECT null PKTABLE_CAT, \n" +
218
260
                "kcu.referenced_table_schema PKTABLE_SCHEM, \n" +
219
261
                "kcu.referenced_table_name PKTABLE_NAME, \n" +
220
262
                "kcu.referenced_column_name PKCOLUMN_NAME, \n" +
250
292
                table +
251
293
                "'" +
252
294
                " ORDER BY FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, KEY_SEQ";
253
 
        
 
295
 
254
296
        Statement stmt = conn.createStatement();
255
297
        return stmt.executeQuery(query);
256
298
    }
277
319
        return stmt.executeQuery(query);
278
320
    }
279
321
 
280
 
        public boolean generatedKeyAlwaysReturned() throws SQLException {
281
 
                return true;
282
 
        }
283
 
 
284
 
        public ResultSet getPseudoColumns(String arg0, String arg1, String arg2,
285
 
                        String arg3) throws SQLException {
286
 
                return MySQLResultSet.EMPTY;
287
 
        }
 
322
    public boolean generatedKeyAlwaysReturned() throws SQLException {
 
323
        return true;
 
324
    }
 
325
 
 
326
    public ResultSet getPseudoColumns(String arg0, String arg1, String arg2,
 
327
            String arg3) throws SQLException {
 
328
        return MySQLResultSet.EMPTY;
 
329
    }
 
330
 
 
331
    public boolean allProceduresAreCallable() throws SQLException {
 
332
        return false;
 
333
    }
 
334
 
 
335
    public boolean allTablesAreSelectable() throws SQLException {
 
336
        return true;
 
337
    }
 
338
 
 
339
    public String getURL() throws SQLException {
 
340
        return url;
 
341
    }
 
342
 
 
343
    public String getUserName() throws SQLException {
 
344
        return username;
 
345
    }
 
346
 
 
347
 
 
348
    public boolean isReadOnly() throws SQLException {
 
349
        return false;
 
350
    }
 
351
 
 
352
 
 
353
    public boolean nullsAreSortedHigh() throws SQLException {
 
354
        return false;
 
355
    }
 
356
 
 
357
 
 
358
    public boolean nullsAreSortedLow() throws SQLException {
 
359
        return !nullsAreSortedHigh();
 
360
    }
 
361
 
 
362
 
 
363
    public boolean nullsAreSortedAtStart() throws SQLException {
 
364
        return false;
 
365
    }
 
366
 
 
367
    public boolean nullsAreSortedAtEnd() throws SQLException {
 
368
        return !nullsAreSortedAtStart();
 
369
    }
 
370
 
 
371
 
 
372
    public String getDatabaseProductName() throws SQLException {
 
373
        return databaseProductName;
 
374
    }
 
375
 
 
376
 
 
377
    public String getDatabaseProductVersion() throws SQLException {
 
378
        if (version == null) {
 
379
            ResultSet rs = connection.createStatement().executeQuery("select version()");
 
380
            rs.next();
 
381
            version = rs.getString(1);
 
382
        }
 
383
        return version;
 
384
    }
 
385
 
 
386
 
 
387
    public String getDriverName() throws SQLException {
 
388
        return "mariadb-jdbc"; // TODO: get from constants file
 
389
    }
 
390
 
 
391
    public String getDriverVersion() throws SQLException {
 
392
        return String.format("%d.%d",getDriverMajorVersion(),getDriverMinorVersion());
 
393
    }
 
394
 
 
395
 
 
396
    public int getDriverMajorVersion() {
 
397
        return 1;
 
398
    }
 
399
 
 
400
    public int getDriverMinorVersion() {
 
401
        return 2;
 
402
    }
 
403
 
 
404
 
 
405
    public boolean usesLocalFiles() throws SQLException {
 
406
        return false;
 
407
    }
 
408
 
 
409
    public boolean usesLocalFilePerTable() throws SQLException {
 
410
        return false;
 
411
    }
 
412
 
 
413
    public boolean supportsMixedCaseIdentifiers() throws SQLException {
 
414
        return true;
 
415
    }
 
416
 
 
417
    public boolean storesUpperCaseIdentifiers() throws SQLException {
 
418
        return false;
 
419
    }
 
420
 
 
421
    public boolean storesLowerCaseIdentifiers() throws SQLException {
 
422
        return !storesUpperCaseIdentifiers();
 
423
    }
 
424
 
 
425
    public boolean storesMixedCaseIdentifiers() throws SQLException {
 
426
        return false;
 
427
    }
 
428
 
 
429
    public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException {
 
430
        return false;
 
431
    }
 
432
 
 
433
    public boolean storesUpperCaseQuotedIdentifiers() throws SQLException {
 
434
        return !storesMixedCaseQuotedIdentifiers();
 
435
    }
 
436
 
 
437
    public boolean storesLowerCaseQuotedIdentifiers() throws SQLException {
 
438
        return false;
 
439
    }
 
440
 
 
441
    public boolean storesMixedCaseQuotedIdentifiers() throws SQLException {
 
442
        return false;
 
443
    }
 
444
 
 
445
    public String getIdentifierQuoteString() throws SQLException {
 
446
        return "`";
 
447
    }
 
448
 
 
449
    public String getSQLKeywords() throws SQLException {
 
450
        return
 
451
        "ACCESSIBLE,"+
 
452
        "ANALYZE,"+
 
453
        "ASENSITIVE,"+
 
454
        "BEFORE,"+
 
455
        "BIGINT,"+
 
456
        "BINARY,"+
 
457
        "BLOB,"+
 
458
        "CALL,"+
 
459
        "CHANGE,"+
 
460
        "CONDITION,"+
 
461
        "DATABASE,"+
 
462
        "DATABASES,"+
 
463
        "DAY_HOUR,"+
 
464
        "DAY_MICROSECOND,"+
 
465
        "DAY_MINUTE,"+
 
466
        "DAY_SECOND,"+
 
467
        "DELAYED,"+
 
468
        "DETERMINISTIC,"+
 
469
        "DISTINCTROW,"+
 
470
        "DIV,"+
 
471
        "DUAL,"+
 
472
        "EACH,"+
 
473
        "ELSEIF,"+
 
474
        "ENCLOSED,"+
 
475
        "ESCAPED,"+
 
476
        "EXIT,"+
 
477
        "EXPLAIN,"+
 
478
        "FLOAT4,"+
 
479
        "FLOAT8,"+
 
480
        "FORCE,"+
 
481
        "FULLTEXT,"+
 
482
        "HIGH_PRIORITY,"+
 
483
        "HOUR_MICROSECOND,"+
 
484
        "HOUR_MINUTE,"+
 
485
        "HOUR_SECOND,"+
 
486
        "IF,"+
 
487
        "IGNORE,"+
 
488
        "INFILE,"+
 
489
        "INOUT,"+
 
490
        "INT1,"+
 
491
        "INT2,"+
 
492
        "INT3,"+
 
493
        "INT4,"+
 
494
        "INT8,"+
 
495
        "ITERATE,"+
 
496
        "KEY," +
 
497
        "KEYS,"+
 
498
        "KILL,"+
 
499
        "LEAVE,"+
 
500
        "LIMIT,"+
 
501
        "LINEAR,"+
 
502
        "LINES,"+
 
503
        "LOAD,"+
 
504
        "LOCALTIME,"+
 
505
        "LOCALTIMESTAMP,"+
 
506
        "LOCK,"+
 
507
        "LONG,"+
 
508
        "LONGBLOB,"+
 
509
        "LONGTEXT,"+
 
510
        "LOOP,"+
 
511
        "LOW_PRIORITY,"+
 
512
        "MEDIUMBLOB,"+
 
513
        "MEDIUMINT,"+
 
514
        "MEDIUMTEXT,"+
 
515
        "MIDDLEINT,"+
 
516
        "MINUTE_MICROSECOND,"+
 
517
        "MINUTE_SECOND,"+
 
518
        "MOD,"+
 
519
        "MODIFIES,"+
 
520
        "NO_WRITE_TO_BINLOG,"+
 
521
        "OPTIMIZE,"+
 
522
        "OPTIONALLY,"+
 
523
        "OUT,"+
 
524
        "OUTFILE,"+
 
525
        "PURGE,"+
 
526
        "RANGE,"+
 
527
        "READS,"+
 
528
        "READ_ONLY,"+
 
529
        "READ_WRITE,"+
 
530
        "REGEXP,"+
 
531
        "RELEASE,"+
 
532
        "RENAME,"+
 
533
        "REPEAT,"+
 
534
        "REPLACE,"+
 
535
        "REQUIRE,"+
 
536
        "RETURN,"+
 
537
        "RLIKE,"+
 
538
        "SCHEMAS,"+
 
539
        "SECOND_MICROSECOND,"+
 
540
        "SENSITIVE,"+
 
541
        "SEPARATOR,"+
 
542
        "SHOW,"+
 
543
        "SPATIAL,"+
 
544
        "SPECIFIC,"+
 
545
        "SQLEXCEPTION,"+
 
546
        "SQL_BIG_RESULT,"+
 
547
        "SQL_CALC_FOUND_ROWS,"+
 
548
        "SQL_SMALL_RESULT,"+
 
549
        "SSL,"+
 
550
        "STARTING,"+
 
551
        "STRAIGHT_JOIN,"+
 
552
        "TERMINATED,"+
 
553
        "TINYBLOB,"+
 
554
        "TINYINT,"+
 
555
        "TINYTEXT,"+
 
556
        "TRIGGER,"+
 
557
        "UNDO,"+
 
558
        "UNLOCK,"+
 
559
        "UNSIGNED,"+
 
560
        "USE,"+
 
561
        "UTC_DATE,"+
 
562
        "UTC_TIME,"+
 
563
        "UTC_TIMESTAMP,"+
 
564
        "VARBINARY,"+
 
565
        "VARCHARACTER,"+
 
566
        "WHILE,"+
 
567
        "X509,"+
 
568
        "XOR,"+
 
569
        "YEAR_MONTH,"+
 
570
        "ZEROFILL,"+
 
571
        "GENERAL,"+
 
572
        "IGNORE_SERVER_IDS,"+
 
573
        "MASTER_HEARTBEAT_PERIOD,"+
 
574
        "MAXVALUE,"+
 
575
        "RESIGNAL,"+
 
576
        "SIGNAL,"+
 
577
        "SLOW";
 
578
    }
 
579
 
 
580
    public String getNumericFunctions() throws SQLException {
 
581
        return ""; //TODO : fix
 
582
    }
 
583
 
 
584
 
 
585
    public String getStringFunctions() throws SQLException {
 
586
        return ""; //TODO: fix
 
587
    }
 
588
 
 
589
    public String getSystemFunctions() throws SQLException {
 
590
        return "DATABASE,USER,SYSTEM_USER,SESSION_USER,LAST_INSERT_ID,VERSION";
 
591
    }
 
592
 
 
593
 
 
594
    public String getTimeDateFunctions() throws SQLException {
 
595
        return ""; //TODO : fix
 
596
    }
 
597
 
 
598
    public String getSearchStringEscape() throws SQLException {
 
599
        return "\\";
 
600
    }
 
601
 
 
602
    public String getExtraNameCharacters() throws SQLException {
 
603
        return "#@";
 
604
    }
 
605
 
 
606
    public boolean supportsAlterTableWithAddColumn() throws SQLException {
 
607
        return true;
 
608
    }
 
609
 
 
610
    public boolean supportsAlterTableWithDropColumn() throws SQLException {
 
611
        return true;
 
612
    }
 
613
 
 
614
    public boolean supportsColumnAliasing() throws SQLException {
 
615
        return true;
 
616
    }
 
617
 
 
618
    public boolean nullPlusNonNullIsNull() throws SQLException {
 
619
        return true;
 
620
    }
 
621
 
 
622
    public boolean supportsConvert() throws SQLException {
 
623
        return false; //TODO: fix
 
624
    }
 
625
 
 
626
    public boolean supportsConvert(final int fromType, final int toType)
 
627
            throws SQLException {
 
628
                return false; // TODO: fix
 
629
            }
 
630
 
 
631
    public boolean supportsTableCorrelationNames() throws SQLException {
 
632
        return true;
 
633
    }
 
634
 
 
635
    public boolean supportsDifferentTableCorrelationNames() throws SQLException {
 
636
        return true;
 
637
    }
 
638
 
 
639
    public boolean supportsExpressionsInOrderBy() throws SQLException {
 
640
        return true;
 
641
    }
 
642
 
 
643
    public boolean supportsOrderByUnrelated() throws SQLException {
 
644
        return false;
 
645
    }
 
646
 
 
647
    public boolean supportsGroupBy() throws SQLException {
 
648
        return true;
 
649
    }
 
650
 
 
651
    public boolean supportsGroupByUnrelated() throws SQLException {
 
652
        return true;
 
653
    }
 
654
 
 
655
    public boolean supportsGroupByBeyondSelect() throws SQLException {
 
656
        return true;
 
657
    }
 
658
 
 
659
    public boolean supportsLikeEscapeClause() throws SQLException {
 
660
        return true;
 
661
    }
 
662
 
 
663
    public boolean supportsMultipleResultSets() throws SQLException {
 
664
        return false;
 
665
    }
 
666
 
 
667
    public boolean supportsMultipleTransactions() throws SQLException {
 
668
        return true;
 
669
    }
 
670
 
 
671
    public boolean supportsNonNullableColumns() throws SQLException {
 
672
        return true;
 
673
    }
 
674
 
 
675
    public boolean supportsMinimumSQLGrammar() throws SQLException {
 
676
        return true;
 
677
    }
 
678
 
 
679
    public boolean supportsCoreSQLGrammar() throws SQLException {
 
680
        return true;
 
681
    }
 
682
 
 
683
    public boolean supportsExtendedSQLGrammar() throws SQLException {
 
684
        return false;
 
685
    }
 
686
 
 
687
    public boolean supportsANSI92EntryLevelSQL() throws SQLException {
 
688
        return true;
 
689
    }
 
690
 
 
691
    public boolean supportsANSI92IntermediateSQL() throws SQLException {
 
692
        return false;
 
693
    }
 
694
 
 
695
    public boolean supportsANSI92FullSQL() throws SQLException {
 
696
        return false;
 
697
    }
 
698
 
 
699
    public boolean supportsIntegrityEnhancementFacility() throws SQLException {
 
700
        return false; //TODO: verify
 
701
    }
 
702
 
 
703
    public boolean supportsOuterJoins() throws SQLException {
 
704
        return true;
 
705
    }
 
706
    public boolean supportsFullOuterJoins() throws SQLException {
 
707
        return false;
 
708
    }
 
709
 
 
710
    public boolean supportsLimitedOuterJoins() throws SQLException {
 
711
        return true;
 
712
    }
 
713
 
 
714
    public String getSchemaTerm() throws SQLException {
 
715
        return "schema";
 
716
    }
 
717
 
 
718
 
 
719
    public String getProcedureTerm() throws SQLException {
 
720
        return "procedure";
 
721
    }
 
722
 
 
723
    public String getCatalogTerm() throws SQLException {
 
724
        return "database";
 
725
    }
 
726
 
 
727
 
 
728
    public boolean isCatalogAtStart() throws SQLException {
 
729
        return true;
 
730
    }
 
731
 
 
732
 
 
733
    public String getCatalogSeparator() throws SQLException {
 
734
        return ".";
 
735
    }
 
736
 
 
737
 
 
738
    public boolean supportsSchemasInDataManipulation() throws SQLException {
 
739
        return true;
 
740
    }
 
741
 
 
742
 
 
743
    public boolean supportsSchemasInProcedureCalls() throws SQLException {
 
744
        return false;
 
745
    }
 
746
 
 
747
    public boolean supportsSchemasInTableDefinitions() throws SQLException {
 
748
        return true;
 
749
    }
 
750
 
 
751
    public boolean supportsSchemasInIndexDefinitions() throws SQLException {
 
752
        return true;
 
753
    }
 
754
 
 
755
    public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException {
 
756
        return true;
 
757
    }
 
758
 
 
759
    public boolean supportsCatalogsInDataManipulation() throws SQLException {
 
760
        return false;
 
761
    }
 
762
 
 
763
    public boolean supportsCatalogsInProcedureCalls() throws SQLException {
 
764
        return false;
 
765
    }
 
766
 
 
767
    public boolean supportsCatalogsInTableDefinitions() throws SQLException {
 
768
        return false;
 
769
    }
 
770
 
 
771
    public boolean supportsCatalogsInIndexDefinitions() throws SQLException {
 
772
        return false;
 
773
    }
 
774
 
 
775
    public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException {
 
776
        return false;
 
777
    }
 
778
 
 
779
    public boolean supportsPositionedDelete() throws SQLException {
 
780
        return false;
 
781
    }
 
782
 
 
783
    public boolean supportsPositionedUpdate() throws SQLException {
 
784
        return false;
 
785
    }
 
786
 
 
787
    public boolean supportsSelectForUpdate() throws SQLException {
 
788
        return true;
 
789
    }
 
790
 
 
791
    public boolean supportsStoredProcedures() throws SQLException {
 
792
        return true;
 
793
    }
 
794
 
 
795
 
 
796
    public boolean supportsSubqueriesInComparisons() throws SQLException {
 
797
        return true;
 
798
    }
 
799
 
 
800
    public boolean supportsSubqueriesInExists() throws SQLException {
 
801
        return true;
 
802
    }
 
803
 
 
804
 
 
805
    public boolean supportsSubqueriesInIns() throws SQLException {
 
806
        return true;
 
807
    }
 
808
 
 
809
    public boolean supportsSubqueriesInQuantifieds() throws SQLException {
 
810
        return true;
 
811
    }
 
812
 
 
813
 
 
814
    public boolean supportsCorrelatedSubqueries() throws SQLException {
 
815
        return true;
 
816
    }
 
817
 
 
818
 
 
819
    public boolean supportsUnion() throws SQLException {
 
820
        return true;
 
821
    }
 
822
 
 
823
 
 
824
    public boolean supportsUnionAll() throws SQLException {
 
825
        return true;
 
826
    }
 
827
 
 
828
 
 
829
    public boolean supportsOpenCursorsAcrossCommit() throws SQLException {
 
830
        return true;
 
831
    }
 
832
 
 
833
    public boolean supportsOpenCursorsAcrossRollback() throws SQLException {
 
834
        return true;
 
835
    }
 
836
 
 
837
    public boolean supportsOpenStatementsAcrossCommit() throws SQLException {
 
838
        return true;
 
839
    }
 
840
 
 
841
    public boolean supportsOpenStatementsAcrossRollback() throws SQLException {
 
842
        return true;
 
843
    }
 
844
 
 
845
    public int getMaxBinaryLiteralLength() throws SQLException {
 
846
        return 16777208;
 
847
    }
 
848
 
 
849
    public int getMaxCharLiteralLength() throws SQLException {
 
850
        return 16777208;
 
851
    }
 
852
 
 
853
    public int getMaxColumnNameLength() throws SQLException {
 
854
        return 64;
 
855
    }
 
856
 
 
857
    public int getMaxColumnsInGroupBy() throws SQLException {
 
858
        return 64;
 
859
    }
 
860
 
 
861
 
 
862
    public int getMaxColumnsInIndex() throws SQLException {
 
863
        return 16;
 
864
    }
 
865
 
 
866
 
 
867
    public int getMaxColumnsInOrderBy() throws SQLException {
 
868
        return 64;
 
869
    }
 
870
 
 
871
    public int getMaxColumnsInSelect() throws SQLException {
 
872
        return 256;
 
873
    }
 
874
 
 
875
 
 
876
    public int getMaxColumnsInTable() throws SQLException {
 
877
        return 0;
 
878
    }
 
879
 
 
880
    public int getMaxConnections() throws SQLException {
 
881
        return 0;
 
882
    }
 
883
 
 
884
 
 
885
    public int getMaxCursorNameLength() throws SQLException {
 
886
        return 0;
 
887
    }
 
888
 
 
889
 
 
890
    public int getMaxIndexLength() throws SQLException {
 
891
        return 256;
 
892
    }
 
893
    public int getMaxSchemaNameLength() throws SQLException {
 
894
        return 32;
 
895
    }
 
896
 
 
897
    public int getMaxProcedureNameLength() throws SQLException {
 
898
        return 256;
 
899
    }
 
900
 
 
901
    public int getMaxCatalogNameLength() throws SQLException {
 
902
        return 0;
 
903
    }
 
904
 
 
905
    public int getMaxRowSize() throws SQLException {
 
906
        return 0;
 
907
    }
 
908
 
 
909
    public boolean doesMaxRowSizeIncludeBlobs() throws SQLException {
 
910
        return false;
 
911
    }
 
912
 
 
913
    public int getMaxStatementLength() throws SQLException {
 
914
        return 0;
 
915
    }
 
916
 
 
917
    public int getMaxStatements() throws SQLException {
 
918
        return 0;
 
919
    }
 
920
 
 
921
    public int getMaxTableNameLength() throws SQLException {
 
922
        return 64;
 
923
    }
 
924
 
 
925
    public int getMaxTablesInSelect() throws SQLException {
 
926
        return 256;
 
927
    }
 
928
 
 
929
    public int getMaxUserNameLength() throws SQLException {
 
930
        return 16;
 
931
    }
 
932
 
 
933
    public int getDefaultTransactionIsolation() throws SQLException {
 
934
        return Connection.TRANSACTION_REPEATABLE_READ;
 
935
    }
 
936
 
 
937
    public boolean supportsTransactions() throws SQLException {
 
938
        return true;
 
939
    }
 
940
 
 
941
 
 
942
    public boolean supportsTransactionIsolationLevel(final int level)
 
943
            throws SQLException {
 
944
                switch (level) {
 
945
                    case Connection.TRANSACTION_READ_UNCOMMITTED:
 
946
                    case Connection.TRANSACTION_READ_COMMITTED:
 
947
                    case Connection.TRANSACTION_REPEATABLE_READ:
 
948
                    case Connection.TRANSACTION_SERIALIZABLE:
 
949
                        return true;
 
950
                    default:
 
951
                        return false;
 
952
                }
 
953
            }
 
954
 
 
955
 
 
956
    public boolean supportsDataDefinitionAndDataManipulationTransactions()
 
957
            throws SQLException {
 
958
                return true;
 
959
            }
 
960
 
 
961
    public boolean supportsDataManipulationTransactionsOnly()
 
962
            throws SQLException {
 
963
                return false;
 
964
            }
 
965
 
 
966
    public boolean dataDefinitionCausesTransactionCommit() throws SQLException {
 
967
        return true;
 
968
    }
 
969
 
 
970
 
 
971
    public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
 
972
        return false;
 
973
    }
 
974
 
 
975
 
 
976
    public ResultSet getProcedures(final String catalog, final String schemaPattern, final String procedureNamePattern)
 
977
            throws SQLException {
 
978
 
 
979
                return MySQLResultSet.EMPTY; /*TODO: return real ones */
 
980
            }
 
981
 
 
982
    public ResultSet getProcedureColumns(final String catalog, final String schemaPattern, final String procedureNamePattern,
 
983
            String columnNamePattern) throws SQLException {
 
984
                return MySQLResultSet.EMPTY; /*TODO: return real ones */
 
985
            }
 
986
 
 
987
    protected String getSchemaPattern(String schemaPattern) {
 
988
        if(schemaPattern != null && ((MySQLConnection)connection).noSchemaPattern == false) {
 
989
            return " AND table_schema LIKE '" + schemaPattern + "'";
 
990
        } else {
 
991
            return " AND table_schema LIKE IFNULL(database(), '%')";
 
992
        }
 
993
    }
 
994
 
 
995
    public ResultSet getSchemas() throws SQLException {
 
996
        final Statement stmt = connection.createStatement();
 
997
        return stmt.executeQuery("SELECT schema_name table_schem, catalog_name table_catalog " +
 
998
                "FROM information_schema.schemata");
 
999
    }
 
1000
 
 
1001
 
 
1002
    public ResultSet getCatalogs() throws SQLException {
 
1003
        final Statement stmt = connection.createStatement();
 
1004
        return stmt.executeQuery("SELECT null as table_cat");
 
1005
    }
 
1006
 
 
1007
    public ResultSet getTableTypes() throws SQLException {
 
1008
        final Statement stmt = connection.createStatement();
 
1009
        return stmt.executeQuery("SELECT DISTINCT(table_type) FROM information_schema.tables");
 
1010
    }
 
1011
 
 
1012
    public ResultSet getColumnPrivileges(final String catalog, final String schema, final String table,
 
1013
            final String columnNamePattern) throws SQLException {
 
1014
      return MySQLResultSet.EMPTY;
 
1015
            }
 
1016
 
 
1017
 
 
1018
    public ResultSet getTablePrivileges(final String catalog, final String schemaPattern, final String tableNamePattern)
 
1019
            throws SQLException {
 
1020
                final Statement stmt = connection.createStatement();
 
1021
                final String query = "SELECT null table_cat, " +
 
1022
                        "table_schema table_schem, " +
 
1023
                        "table_name, " +
 
1024
                        "null grantor, " +
 
1025
                        "user() grantee, " +
 
1026
                        "'update' privilege, " +
 
1027
                        "'yes' is_grantable " +
 
1028
                        "FROM information_schema.columns " +
 
1029
                        "WHERE table_schema LIKE '" + ((schemaPattern == null) ? "%" : schemaPattern) + "'" +
 
1030
                        " AND table_name LIKE '" + ((tableNamePattern == null) ? "%" : tableNamePattern) + "'";
 
1031
 
 
1032
                return stmt.executeQuery(query);
 
1033
            }
 
1034
 
 
1035
    public ResultSet getVersionColumns(final String catalog, final String schema, final String table)
 
1036
            throws SQLException {
 
1037
        return MySQLResultSet.EMPTY;
 
1038
    }
 
1039
 
 
1040
    public ResultSet getCrossReference(final String parentCatalog, final String parentSchema, final String parentTable,
 
1041
            final String foreignCatalog, final String foreignSchema, final String foreignTable) throws SQLException {
 
1042
               return MySQLResultSet.EMPTY;
 
1043
            }
 
1044
 
 
1045
    public ResultSet getTypeInfo() throws SQLException {
 
1046
        return MySQLResultSet.EMPTY;
 
1047
    }
 
1048
 
 
1049
    public ResultSet getIndexInfo(final String catalog, final String schema, final String table,
 
1050
            final boolean unique, final boolean approximate) throws SQLException {
 
1051
                final String query = "SELECT null table_cat," +
 
1052
                        "       table_schema table_schem," +
 
1053
                        "       table_name," +
 
1054
                        "       non_unique," +
 
1055
                        "       table_schema index_qualifier," +
 
1056
                        "       index_name," +
 
1057
                        "       " + tableIndexOther + " type," +
 
1058
                        "       seq_in_index ordinal_position," +
 
1059
                        "       column_name," +
 
1060
                        "       collation asc_or_desc," +
 
1061
                        "       cardinality," +
 
1062
                        "       null as pages," +
 
1063
                        "       null as filter_condition" +
 
1064
                        " FROM information_schema.statistics" +
 
1065
                        " WHERE table_name='" + table + "' " +
 
1066
                        ((schema != null) ? (" AND table_schema like '" + schema + "' ") : "") +
 
1067
                        (unique ? " AND NON_UNIQUE = 0" : "") +
 
1068
                        " ORDER BY NON_UNIQUE, TYPE, INDEX_NAME, ORDINAL_POSITION";
 
1069
                final Statement stmt = connection.createStatement();
 
1070
                return stmt.executeQuery(query);
 
1071
            }
 
1072
    public boolean supportsResultSetType(final int type) throws SQLException {
 
1073
        return true;
 
1074
    }
 
1075
 
 
1076
 
 
1077
    public boolean supportsResultSetConcurrency(final int type, final int concurrency)
 
1078
            throws SQLException {
 
1079
                return concurrency == ResultSet.CONCUR_READ_ONLY;
 
1080
            }
 
1081
 
 
1082
    public boolean ownUpdatesAreVisible(final int type) throws SQLException {
 
1083
        return false;
 
1084
    }
 
1085
 
 
1086
 
 
1087
    public boolean ownDeletesAreVisible(final int type) throws SQLException {
 
1088
        return false;
 
1089
    }
 
1090
 
 
1091
 
 
1092
    public boolean ownInsertsAreVisible(final int type) throws SQLException {
 
1093
        return false;
 
1094
    }
 
1095
 
 
1096
 
 
1097
    public boolean othersUpdatesAreVisible(final int type) throws SQLException {
 
1098
        return false;
 
1099
    }
 
1100
 
 
1101
 
 
1102
    public boolean othersDeletesAreVisible(final int type) throws SQLException {
 
1103
        return false;
 
1104
    }
 
1105
 
 
1106
    public boolean othersInsertsAreVisible(final int type) throws SQLException {
 
1107
        return false;
 
1108
    }
 
1109
 
 
1110
    public boolean updatesAreDetected(final int type) throws SQLException {
 
1111
        return false;
 
1112
    }
 
1113
 
 
1114
 
 
1115
    public boolean deletesAreDetected(final int type) throws SQLException {
 
1116
        return false;
 
1117
    }
 
1118
 
 
1119
 
 
1120
    public boolean insertsAreDetected(final int type) throws SQLException {
 
1121
        return false;
 
1122
    }
 
1123
 
 
1124
 
 
1125
    public boolean supportsBatchUpdates() throws SQLException {
 
1126
        return true;
 
1127
    }
 
1128
 
 
1129
 
 
1130
    public ResultSet getUDTs(final String catalog, final String schemaPattern, final String typeNamePattern, final int[] types)
 
1131
            throws SQLException {
 
1132
                return MySQLResultSet.EMPTY;
 
1133
            }
 
1134
 
 
1135
 
 
1136
 
 
1137
    public Connection getConnection() throws SQLException {
 
1138
        return connection;
 
1139
    }
 
1140
 
 
1141
 
 
1142
    public boolean supportsSavepoints() throws SQLException {
 
1143
        return true;
 
1144
    }
 
1145
 
 
1146
 
 
1147
    public boolean supportsNamedParameters() throws SQLException {
 
1148
        return false;
 
1149
    }
 
1150
 
 
1151
 
 
1152
    public boolean supportsMultipleOpenResults() throws SQLException {
 
1153
        return false;
 
1154
    }
 
1155
 
 
1156
 
 
1157
    public boolean supportsGetGeneratedKeys() throws SQLException {
 
1158
        return true;
 
1159
    }
 
1160
 
 
1161
 
 
1162
    public ResultSet getSuperTypes(final String catalog, final String schemaPattern, final String typeNamePattern)
 
1163
            throws SQLException {
 
1164
 
 
1165
        return MySQLResultSet.EMPTY;
 
1166
            }
 
1167
 
 
1168
 
 
1169
    public ResultSet getSuperTables(final String catalog, final String schemaPattern, final String tableNamePattern)
 
1170
            throws SQLException {
 
1171
return MySQLResultSet.EMPTY;
 
1172
            }
 
1173
 
 
1174
 
 
1175
    public ResultSet getAttributes(final String catalog, final String schemaPattern, final String typeNamePattern,
 
1176
            final String attributeNamePattern) throws SQLException {
 
1177
return MySQLResultSet.EMPTY;
 
1178
            }
 
1179
 
 
1180
    public boolean supportsResultSetHoldability(final int holdability)
 
1181
            throws SQLException {
 
1182
                return holdability == ResultSet.HOLD_CURSORS_OVER_COMMIT;
 
1183
            }
 
1184
 
 
1185
 
 
1186
    public int getResultSetHoldability() throws SQLException {
 
1187
        return ResultSet.HOLD_CURSORS_OVER_COMMIT;
 
1188
    }
 
1189
 
 
1190
 
 
1191
    public int getDatabaseMajorVersion() throws SQLException {
 
1192
        String components[] = version.split("\\.");
 
1193
        return Integer.parseInt(components[0]);
 
1194
    }
 
1195
 
 
1196
 
 
1197
    public int getDatabaseMinorVersion() throws SQLException {
 
1198
        String components[] = version.split("\\.");
 
1199
        return Integer.parseInt(components[1]);
 
1200
    }
 
1201
 
 
1202
 
 
1203
    public int getJDBCMajorVersion() throws SQLException {
 
1204
        return 4;
 
1205
    }
 
1206
 
 
1207
    public int getJDBCMinorVersion() throws SQLException {
 
1208
        return 0;
 
1209
    }
 
1210
 
 
1211
 
 
1212
    public int getSQLStateType() throws SQLException {
 
1213
         return sqlStateSQL;
 
1214
    }
 
1215
 
 
1216
 
 
1217
    public boolean locatorsUpdateCopy() throws SQLException {
 
1218
        return false;
 
1219
    }
 
1220
 
 
1221
 
 
1222
    public boolean supportsStatementPooling() throws SQLException {
 
1223
        return false;
 
1224
    }
 
1225
 
 
1226
 
 
1227
    public java.sql.RowIdLifetime getRowIdLifetime() throws SQLException {
 
1228
        return java.sql.RowIdLifetime.ROWID_UNSUPPORTED;
 
1229
    }
 
1230
 
 
1231
 
 
1232
    public ResultSet getSchemas(final String catalog, final String schemaPattern) throws SQLException {
 
1233
        final String query = "SELECT schema_name table_schem, " +
 
1234
                "null table_catalog " +
 
1235
                "FROM information_schema.schemata " +
 
1236
                (schemaPattern != null ? "WHERE schema_name like '" + schemaPattern + "'" : "") +
 
1237
                " ORDER BY table_schem";
 
1238
        final Statement stmt = connection.createStatement();
 
1239
        return stmt.executeQuery(query);
 
1240
    }
 
1241
 
 
1242
    public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException {
 
1243
        return true;
 
1244
    }
 
1245
 
 
1246
    public boolean autoCommitFailureClosesAllResultSets() throws SQLException {
 
1247
        return false; //TODO: look into this
 
1248
    }
 
1249
 
 
1250
 
 
1251
    public ResultSet getClientInfoProperties() throws SQLException {
 
1252
        return MySQLResultSet.EMPTY; //TODO: look into this
 
1253
    }
 
1254
 
 
1255
 
 
1256
    public ResultSet getFunctions(final String catalog, final String schemaPattern, final String functionNamePattern)
 
1257
            throws SQLException {
 
1258
return MySQLResultSet.EMPTY; //TODO: fix
 
1259
 
 
1260
            }
 
1261
 
 
1262
    public ResultSet getFunctionColumns(final String catalog, final String schemaPattern, final String functionNamePattern,
 
1263
            final String columnNamePattern) throws SQLException {
 
1264
        return MySQLResultSet.EMPTY; //TODO: fix
 
1265
            }
 
1266
 
 
1267
 
 
1268
    public <T> T unwrap(final Class<T> iface) throws SQLException {
 
1269
        return null;
 
1270
    }
 
1271
 
 
1272
    public boolean isWrapperFor(final Class<?> iface) throws SQLException {
 
1273
        return false;
 
1274
    }
288
1275
 
289
1276
 
290
1277
}