~ubuntu-branches/ubuntu/oneiric/mysql-connector-java/oneiric

« back to all changes in this revision

Viewing changes to src/com/mysql/jdbc/Field.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2007-11-30 10:34:13 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20071130103413-mxm4lpfrr4fnjbuj
Tags: 5.1.5+dfsg-1
* New upstream release. Closes: #450718.
* Add Homepage field to debian/control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 Copyright (C) 2002-2004 MySQL AB
3
3
 
4
4
 This program is free software; you can redistribute it and/or modify
5
 
 it under the terms of version 2 of the GNU General Public License as 
 
5
 it under the terms of version 2 of the GNU General Public License as
6
6
 published by the Free Software Foundation.
7
7
 
8
 
 There are special exceptions to the terms and conditions of the GPL 
9
 
 as it is applied to this software. View the full text of the 
10
 
 exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
 
8
 There are special exceptions to the terms and conditions of the GPL
 
9
 as it is applied to this software. View the full text of the
 
10
 exception in file EXCEPTIONS-CONNECTOR-J in the directory of this
11
11
 software distribution.
12
12
 
13
13
 This program is distributed in the hope that it will be useful,
27
27
import java.io.UnsupportedEncodingException;
28
28
import java.sql.SQLException;
29
29
import java.sql.Types;
 
30
import java.util.regex.PatternSyntaxException;
30
31
 
31
32
/**
32
33
 * Field is a class used to describe fields in a ResultSet
33
 
 * 
 
34
 *
34
35
 * @author Mark Matthews
35
 
 * @version $Id: Field.java 5639 2006-08-16 14:18:23Z mmatthews $
 
36
 * @version $Id: Field.java 6577 2007-09-07 16:12:04Z mmatthews $
36
37
 */
37
38
public class Field {
38
 
        // ~ Static fields/initializers
39
 
        // ---------------------------------------------
40
39
 
41
40
        private static final int AUTO_INCREMENT_FLAG = 512;
42
41
 
43
42
        private static final int NO_CHARSET_INFO = -1;
44
43
 
45
 
        // ~ Instance fields
46
 
        // --------------------------------------------------------
47
 
 
48
44
        private byte[] buffer;
49
45
 
50
46
        private int charsetIndex = 0;
57
53
 
58
54
        private String collationName = null;
59
55
 
60
 
        private Connection connection = null;
 
56
        private ConnectionImpl connection = null;
61
57
 
62
58
        private String databaseName = null;
63
59
 
110
106
        private int tableNameLength;
111
107
 
112
108
        private int tableNameStart;
113
 
        
 
109
 
114
110
        private boolean useOldNameMetadata = false;
115
111
 
116
112
        private boolean isSingleBit;
117
113
 
118
 
        // ~ Constructors
119
 
        // -----------------------------------------------------------
 
114
        private int maxBytesPerChar;
120
115
 
121
116
        /**
122
117
         * Constructor used when communicating with 4.1 and newer servers
123
118
         */
124
 
        Field(Connection conn, byte[] buffer, int databaseNameStart,
 
119
        Field(ConnectionImpl conn, byte[] buffer, int databaseNameStart,
125
120
                        int databaseNameLength, int tableNameStart, int tableNameLength,
126
121
                        int originalTableNameStart, int originalTableNameLength,
127
122
                        int nameStart, int nameLength, int originalColumnNameStart,
156
151
                // charset
157
152
                this.charsetIndex = charsetIndex;
158
153
 
159
 
                
 
154
 
160
155
                // Map MySqlTypes to java.sql Types
161
156
                this.sqlType = MysqlDefs.mysqlToJavaType(this.mysqlType);
162
 
                
 
157
 
 
158
        checkForImplicitTemporaryTable();
163
159
                // Re-map to 'real' blob type, if we're a BLOB
164
160
 
165
161
                if (this.mysqlType == MysqlDefs.FIELD_TYPE_BLOB) {
166
 
                        if (this.charsetIndex == 63 || 
 
162
                    boolean isFromFunction = this.originalTableNameLength == 0;
 
163
 
 
164
                    if (this.connection != null && this.connection.getBlobsAreStrings() ||
 
165
                            (this.connection.getFunctionsNeverReturnBlobs() && isFromFunction)) {
 
166
                        this.sqlType = Types.VARCHAR;
 
167
                        this.mysqlType = MysqlDefs.FIELD_TYPE_VARCHAR;
 
168
                    } else if (this.charsetIndex == 63 ||
167
169
                                        !this.connection.versionMeetsMinimum(4, 1, 0)) {
168
 
                                setBlobTypeBasedOnLength();
169
 
                                this.sqlType = MysqlDefs.mysqlToJavaType(this.mysqlType);
 
170
                                if (this.connection.getUseBlobToStoreUTF8OutsideBMP() 
 
171
                                                && shouldSetupForUtf8StringInBlob()) {
 
172
                                        setupForUtf8StringInBlob();
 
173
                                } else {
 
174
                                        setBlobTypeBasedOnLength();
 
175
                                        this.sqlType = MysqlDefs.mysqlToJavaType(this.mysqlType);
 
176
                                }
170
177
                        } else {
171
178
                                // *TEXT masquerading as blob
172
179
                                this.mysqlType = MysqlDefs.FIELD_TYPE_VAR_STRING;
186
193
                        }
187
194
 
188
195
                }
189
 
                
 
196
 
190
197
                if (!isNativeNumericType() && !isNativeDateTimeType()) {
191
198
                        this.charsetName = this.connection
192
199
                                .getCharsetNameForIndex(this.charsetIndex);
193
200
 
194
 
                        
 
201
 
195
202
                        // Handle VARBINARY/BINARY (server doesn't have a different type
196
203
                        // for this
197
 
        
 
204
 
198
205
                        boolean isBinary = isBinary();
199
 
        
 
206
 
200
207
                        if (this.connection.versionMeetsMinimum(4, 1, 0) &&
201
 
                                        this.mysqlType == MysqlDefs.FIELD_TYPE_VAR_STRING && 
 
208
                                        this.mysqlType == MysqlDefs.FIELD_TYPE_VAR_STRING &&
202
209
                                        isBinary &&
203
210
                                        this.charsetIndex == 63) {
204
211
                                if (this.isOpaqueBinary()) {
205
212
                                        this.sqlType = Types.VARBINARY;
206
213
                                }
207
 
                        } 
208
 
                        
 
214
                        }
 
215
 
209
216
                        if (this.connection.versionMeetsMinimum(4, 1, 0) &&
210
 
                                        this.mysqlType == MysqlDefs.FIELD_TYPE_STRING && 
 
217
                                        this.mysqlType == MysqlDefs.FIELD_TYPE_STRING &&
211
218
                                        isBinary && this.charsetIndex == 63) {
212
219
                                //
213
220
                                // Okay, this is a hack, but there's currently no way
215
222
                                // from the "BINARY" column type, other than looking
216
223
                                // at the original column name.
217
224
                                //
218
 
                                
219
 
                                if (isOpaqueBinary()) {
 
225
 
 
226
                                if (isOpaqueBinary() && !this.connection.getBlobsAreStrings()) {
220
227
                                        this.sqlType = Types.BINARY;
221
228
                                }
222
229
                        }
223
 
        
224
 
                        
225
 
        
 
230
 
 
231
 
 
232
 
226
233
                        if (this.mysqlType == MysqlDefs.FIELD_TYPE_BIT) {
227
234
                                this.isSingleBit = (this.length == 0);
228
 
                                
 
235
 
229
236
                                if (this.connection != null && (this.connection.versionMeetsMinimum(5, 0, 21) ||
230
237
                                                this.connection.versionMeetsMinimum(5, 1, 10)) && this.length == 1) {
231
238
                                        this.isSingleBit = true;
232
239
                                }
233
 
                                
 
240
 
234
241
                                if (this.isSingleBit) {
235
242
                                        this.sqlType = Types.BIT;
236
243
                                } else {
237
244
                                        this.sqlType = Types.VARBINARY;
238
245
                                        this.colFlag |= 128; // we need to pretend this is a full
239
246
                                        this.colFlag |= 16; // binary blob
 
247
                                        isBinary = true;
240
248
                                }
241
249
                        }
242
 
        
 
250
 
243
251
                        //
244
252
                        // Handle TEXT type (special case), Fix proposed by Peter McKeown
245
253
                        //
248
256
                        } else if ((this.sqlType == java.sql.Types.VARBINARY) && !isBinary) {
249
257
                                this.sqlType = java.sql.Types.VARCHAR;
250
258
                        }
251
 
                        
252
 
                        checkForImplicitTemporaryTable();
253
259
                } else {
254
260
                        this.charsetName = "US-ASCII";
255
261
                }
281
287
                }
282
288
        }
283
289
 
 
290
        private boolean shouldSetupForUtf8StringInBlob() throws SQLException {
 
291
                String includePattern = this.connection
 
292
                                .getUtf8OutsideBmpIncludedColumnNamePattern();
 
293
                String excludePattern = this.connection
 
294
                                .getUtf8OutsideBmpExcludedColumnNamePattern();
 
295
 
 
296
                if (excludePattern != null
 
297
                                && !StringUtils.isEmptyOrWhitespaceOnly(excludePattern)) {
 
298
                        try {
 
299
                                if (getOriginalName().matches(excludePattern)) {
 
300
                                        if (includePattern != null
 
301
                                                        && !StringUtils.isEmptyOrWhitespaceOnly(includePattern)) {
 
302
                                                try {
 
303
                                                        if (getOriginalName().matches(includePattern)) {
 
304
                                                                return true;
 
305
                                                        }
 
306
                                                } catch (PatternSyntaxException pse) {
 
307
                                                        SQLException sqlEx = SQLError
 
308
                                                                        .createSQLException(
 
309
                                                                                        "Illegal regex specified for \"utf8OutsideBmpIncludedColumnNamePattern\"",
 
310
                                                                                        SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
 
311
 
 
312
                                                        if (!this.connection.getParanoid()) {
 
313
                                                                sqlEx.initCause(pse);
 
314
                                                        }
 
315
 
 
316
                                                        throw sqlEx;
 
317
                                                }
 
318
                                        }
 
319
                                        
 
320
                                        return false;
 
321
                                }
 
322
                        } catch (PatternSyntaxException pse) {
 
323
                                SQLException sqlEx = SQLError
 
324
                                                .createSQLException(
 
325
                                                                "Illegal regex specified for \"utf8OutsideBmpExcludedColumnNamePattern\"",
 
326
                                                                SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
 
327
 
 
328
                                if (!this.connection.getParanoid()) {
 
329
                                        sqlEx.initCause(pse);
 
330
                                }
 
331
 
 
332
                                throw sqlEx;
 
333
                        }
 
334
                }
 
335
 
 
336
                return true;
 
337
        }
 
338
 
 
339
        private void setupForUtf8StringInBlob() {
 
340
                if (this.length == MysqlDefs.LENGTH_TINYBLOB || this.length == MysqlDefs.LENGTH_BLOB) {
 
341
                        this.mysqlType = MysqlDefs.FIELD_TYPE_VARCHAR;
 
342
                        this.sqlType = Types.VARCHAR;
 
343
                }  else {
 
344
                        this.mysqlType = MysqlDefs.FIELD_TYPE_VAR_STRING;
 
345
                        this.sqlType = Types.LONGVARCHAR;
 
346
                }
 
347
                
 
348
                this.charsetIndex = 33; 
 
349
        }
 
350
 
284
351
        /**
285
352
         * Constructor used when communicating with pre 4.1 servers
286
353
         */
287
 
        Field(Connection conn, byte[] buffer, int nameStart, int nameLength,
 
354
        Field(ConnectionImpl conn, byte[] buffer, int nameStart, int nameLength,
288
355
                        int tableNameStart, int tableNameLength, int length, int mysqlType,
289
356
                        short colFlag, int colDecimals) throws SQLException {
290
357
                this(conn, buffer, -1, -1, tableNameStart, tableNameLength, -1, -1,
303
370
                this.colFlag = 0;
304
371
                this.colDecimals = 0;
305
372
        }
306
 
 
307
 
        // ~ Methods
308
 
        // ----------------------------------------------------------------
309
 
 
 
373
        
 
374
        /**
 
375
         * Used by prepared statements to re-use result set data conversion methods
 
376
         * when generating bound parmeter retrieval instance for statement
 
377
         * interceptors.
 
378
         * 
 
379
         * @param tableName
 
380
         *            not used
 
381
         * @param columnName
 
382
         *            not used
 
383
         * @param charsetIndex
 
384
         *            the MySQL collation/character set index
 
385
         * @param jdbcType
 
386
         *            from java.sql.Types
 
387
         * @param length
 
388
         *            length in characters or bytes (for BINARY data).
 
389
         */
 
390
        Field(String tableName, String columnName, int charsetIndex, int jdbcType,
 
391
                        int length) {
 
392
                this.tableName = tableName;
 
393
                this.name = columnName;
 
394
                this.length = length;
 
395
                this.sqlType = jdbcType;
 
396
                this.colFlag = 0;
 
397
                this.colDecimals = 0;
 
398
                this.charsetIndex = charsetIndex;
 
399
        }
 
400
        
310
401
        private void checkForImplicitTemporaryTable() {
311
402
                this.isImplicitTempTable = this.tableNameLength > 5
312
403
                                && this.buffer[tableNameStart] == (byte) '#'
318
409
 
319
410
        /**
320
411
         * Returns the character set (if known) for this field.
321
 
         * 
 
412
         *
322
413
         * @return the character set
323
414
         */
324
415
        public String getCharacterSet() throws SQLException {
329
420
                if (this.collationName == null) {
330
421
                        if (this.connection != null) {
331
422
                                if (this.connection.versionMeetsMinimum(4, 1, 0)) {
332
 
                                        java.sql.DatabaseMetaData dbmd = this.connection
333
 
                                                        .getMetaData();
334
 
 
335
 
                                        String quotedIdStr = dbmd.getIdentifierQuoteString();
336
 
 
337
 
                                        if (" ".equals(quotedIdStr)) { //$NON-NLS-1$
338
 
                                                quotedIdStr = ""; //$NON-NLS-1$
339
 
                                        }
340
 
 
341
 
                                        String csCatalogName = getDatabaseName();
342
 
                                        String csTableName = getOriginalTableName();
343
 
                                        String csColumnName = getOriginalName();
344
 
 
345
 
                                        if (csCatalogName != null && csCatalogName.length() != 0
346
 
                                                        && csTableName != null && csTableName.length() != 0
347
 
                                                        && csColumnName != null
348
 
                                                        && csColumnName.length() != 0) {
349
 
                                                StringBuffer queryBuf = new StringBuffer(csCatalogName
350
 
                                                                .length()
351
 
                                                                + csTableName.length() + 28);
352
 
                                                queryBuf.append("SHOW FULL COLUMNS FROM "); //$NON-NLS-1$
353
 
                                                queryBuf.append(quotedIdStr);
354
 
                                                queryBuf.append(csCatalogName);
355
 
                                                queryBuf.append(quotedIdStr);
356
 
                                                queryBuf.append("."); //$NON-NLS-1$
357
 
                                                queryBuf.append(quotedIdStr);
358
 
                                                queryBuf.append(csTableName);
359
 
                                                queryBuf.append(quotedIdStr);
360
 
 
361
 
                                                java.sql.Statement collationStmt = null;
362
 
                                                java.sql.ResultSet collationRs = null;
363
 
 
364
 
                                                try {
365
 
                                                        collationStmt = this.connection.createStatement();
366
 
 
367
 
                                                        collationRs = collationStmt.executeQuery(queryBuf
368
 
                                                                        .toString());
369
 
 
370
 
                                                        while (collationRs.next()) {
371
 
                                                                if (csColumnName.equals(collationRs
372
 
                                                                                .getString("Field"))) { //$NON-NLS-1$
373
 
                                                                        this.collationName = collationRs
374
 
                                                                                        .getString("Collation"); //$NON-NLS-1$
375
 
 
376
 
                                                                        break;
377
 
                                                                }
378
 
                                                        }
379
 
                                                } finally {
380
 
                                                        if (collationRs != null) {
381
 
                                                                collationRs.close();
382
 
                                                                collationRs = null;
383
 
                                                        }
384
 
 
385
 
                                                        if (collationStmt != null) {
386
 
                                                                collationStmt.close();
387
 
                                                                collationStmt = null;
388
 
                                                        }
389
 
                                                }
390
 
 
 
423
                                        if (this.connection.getUseDynamicCharsetInfo()) {
 
424
                                                java.sql.DatabaseMetaData dbmd = this.connection
 
425
                                                                .getMetaData();
 
426
 
 
427
                                                String quotedIdStr = dbmd.getIdentifierQuoteString();
 
428
 
 
429
                                                if (" ".equals(quotedIdStr)) { //$NON-NLS-1$
 
430
                                                        quotedIdStr = ""; //$NON-NLS-1$
 
431
                                                }
 
432
 
 
433
                                                String csCatalogName = getDatabaseName();
 
434
                                                String csTableName = getOriginalTableName();
 
435
                                                String csColumnName = getOriginalName();
 
436
 
 
437
                                                if (csCatalogName != null && csCatalogName.length() != 0
 
438
                                                                && csTableName != null && csTableName.length() != 0
 
439
                                                                && csColumnName != null
 
440
                                                                && csColumnName.length() != 0) {
 
441
                                                        StringBuffer queryBuf = new StringBuffer(csCatalogName
 
442
                                                                        .length()
 
443
                                                                        + csTableName.length() + 28);
 
444
                                                        queryBuf.append("SHOW FULL COLUMNS FROM "); //$NON-NLS-1$
 
445
                                                        queryBuf.append(quotedIdStr);
 
446
                                                        queryBuf.append(csCatalogName);
 
447
                                                        queryBuf.append(quotedIdStr);
 
448
                                                        queryBuf.append("."); //$NON-NLS-1$
 
449
                                                        queryBuf.append(quotedIdStr);
 
450
                                                        queryBuf.append(csTableName);
 
451
                                                        queryBuf.append(quotedIdStr);
 
452
 
 
453
                                                        java.sql.Statement collationStmt = null;
 
454
                                                        java.sql.ResultSet collationRs = null;
 
455
 
 
456
                                                        try {
 
457
                                                                collationStmt = this.connection.createStatement();
 
458
 
 
459
                                                                collationRs = collationStmt.executeQuery(queryBuf
 
460
                                                                                .toString());
 
461
 
 
462
                                                                while (collationRs.next()) {
 
463
                                                                        if (csColumnName.equals(collationRs
 
464
                                                                                        .getString("Field"))) { //$NON-NLS-1$
 
465
                                                                                this.collationName = collationRs
 
466
                                                                                                .getString("Collation"); //$NON-NLS-1$
 
467
 
 
468
                                                                                break;
 
469
                                                                        }
 
470
                                                                }
 
471
                                                        } finally {
 
472
                                                                if (collationRs != null) {
 
473
                                                                        collationRs.close();
 
474
                                                                        collationRs = null;
 
475
                                                                }
 
476
 
 
477
                                                                if (collationStmt != null) {
 
478
                                                                        collationStmt.close();
 
479
                                                                        collationStmt = null;
 
480
                                                                }
 
481
                                                        }
 
482
                                                }
 
483
                                        } else {
 
484
                                                this.collationName = CharsetMapping.INDEX_TO_COLLATION[charsetIndex];
391
485
                                        }
392
486
                                }
393
 
 
394
487
                        }
395
 
 
396
488
                }
397
489
 
398
490
                return this.collationName;
399
491
        }
400
 
 
 
492
        
401
493
        public String getColumnLabel() throws SQLException {
402
494
                return getName(); // column name if not aliased, alias if used
403
495
        }
404
496
 
405
497
        /**
406
498
         * DOCUMENT ME!
407
 
         * 
 
499
         *
408
500
         * @return DOCUMENT ME!
409
501
         */
410
502
        public String getDatabaseName() throws SQLException {
423
515
 
424
516
        /**
425
517
         * DOCUMENT ME!
426
 
         * 
 
518
         *
427
519
         * @return DOCUMENT ME!
428
520
         */
429
521
        public String getFullName() throws SQLException {
444
536
 
445
537
        /**
446
538
         * DOCUMENT ME!
447
 
         * 
 
539
         *
448
540
         * @return DOCUMENT ME!
449
541
         */
450
542
        public String getFullOriginalName() throws SQLException {
472
564
 
473
565
        /**
474
566
         * DOCUMENT ME!
475
 
         * 
 
567
         *
476
568
         * @return DOCUMENT ME!
477
569
         */
478
570
        public long getLength() {
479
571
                return this.length;
480
572
        }
481
573
 
482
 
        public int getMaxBytesPerCharacter() throws SQLException {
483
 
                return this.connection.getMaxBytesPerChar(getCharacterSet());
 
574
        public synchronized int getMaxBytesPerCharacter() throws SQLException {
 
575
                if (this.maxBytesPerChar == 0) {
 
576
                        this.maxBytesPerChar = this.connection.getMaxBytesPerChar(getCharacterSet());
 
577
                }
 
578
 
 
579
                return this.maxBytesPerChar;
484
580
        }
485
581
 
486
582
        /**
487
583
         * DOCUMENT ME!
488
 
         * 
 
584
         *
489
585
         * @return DOCUMENT ME!
490
586
         */
491
587
        public int getMysqlType() {
494
590
 
495
591
        /**
496
592
         * DOCUMENT ME!
497
 
         * 
 
593
         *
498
594
         * @return DOCUMENT ME!
499
595
         */
500
596
        public String getName() throws SQLException {
509
605
                if (this.useOldNameMetadata) {
510
606
                        return getName();
511
607
                }
512
 
                
513
 
                if (this.connection != null && 
 
608
 
 
609
                if (this.connection != null &&
514
610
                                this.connection.versionMeetsMinimum(4, 1, 0)) {
515
611
                        return getOriginalName();
516
612
                }
517
 
                
 
613
 
518
614
                return getName();
519
615
        }
520
616
 
521
617
        /**
522
618
         * DOCUMENT ME!
523
 
         * 
 
619
         *
524
620
         * @return DOCUMENT ME!
525
621
         */
526
622
        public String getOriginalName() throws SQLException {
536
632
 
537
633
        /**
538
634
         * DOCUMENT ME!
539
 
         * 
 
635
         *
540
636
         * @return DOCUMENT ME!
541
637
         */
542
638
        public String getOriginalTableName() throws SQLException {
553
649
        /**
554
650
         * Returns amount of correction that should be applied to the precision
555
651
         * value.
556
 
         * 
 
652
         *
557
653
         * Different versions of MySQL report different precision values.
558
 
         * 
 
654
         *
559
655
         * @return the amount to adjust precision value by.
560
656
         */
561
657
        public int getPrecisionAdjustFactor() {
564
660
 
565
661
        /**
566
662
         * DOCUMENT ME!
567
 
         * 
 
663
         *
568
664
         * @return DOCUMENT ME!
569
665
         */
570
666
        public int getSQLType() {
642
738
 
643
739
        /**
644
740
         * DOCUMENT ME!
645
 
         * 
 
741
         *
646
742
         * @return DOCUMENT ME!
647
743
         */
648
744
        public String getTable() throws SQLException {
651
747
 
652
748
        /**
653
749
         * DOCUMENT ME!
654
 
         * 
 
750
         *
655
751
         * @return DOCUMENT ME!
656
752
         */
657
753
        public String getTableName() throws SQLException {
667
763
                if (this.connection.versionMeetsMinimum(4, 1, 0)) {
668
764
                        return getOriginalTableName();
669
765
                }
670
 
                        
 
766
 
671
767
                return getTableName(); // pre-4.1, no aliases returned
672
768
        }
673
769
 
674
770
        /**
675
771
         * DOCUMENT ME!
676
 
         * 
 
772
         *
677
773
         * @return DOCUMENT ME!
678
774
         */
679
775
        public boolean isAutoIncrement() {
682
778
 
683
779
        /**
684
780
         * DOCUMENT ME!
685
 
         * 
 
781
         *
686
782
         * @return DOCUMENT ME!
687
783
         */
688
784
        public boolean isBinary() {
691
787
 
692
788
        /**
693
789
         * DOCUMENT ME!
694
 
         * 
 
790
         *
695
791
         * @return DOCUMENT ME!
696
792
         */
697
793
        public boolean isBlob() {
700
796
 
701
797
        /**
702
798
         * Is this field owned by a server-created temporary table?
703
 
         * 
 
799
         *
704
800
         * @return
705
801
         */
706
802
        private boolean isImplicitTemporaryTable() {
709
805
 
710
806
        /**
711
807
         * DOCUMENT ME!
712
 
         * 
 
808
         *
713
809
         * @return DOCUMENT ME!
714
810
         */
715
811
        public boolean isMultipleKey() {
731
827
                                && (this.getMysqlType() == MysqlDefs.FIELD_TYPE_STRING ||
732
828
                                this.getMysqlType() == MysqlDefs.FIELD_TYPE_VAR_STRING)) {
733
829
 
734
 
                        if (this.originalTableNameLength == 0) {
 
830
                        if (this.originalTableNameLength == 0 && (
 
831
                                        this.connection != null && !this.connection.versionMeetsMinimum(5, 0, 25))) {
735
832
                                return false; // Probably from function
736
833
                        }
737
834
 
748
845
 
749
846
        /**
750
847
         * DOCUMENT ME!
751
 
         * 
 
848
         *
752
849
         * @return DOCUMENT ME!
753
850
         */
754
851
        public boolean isPrimaryKey() {
757
854
 
758
855
        /**
759
856
         * Is this field _definitely_ not writable?
760
 
         * 
 
857
         *
761
858
         * @return true if this field can not be written to in an INSERT/UPDATE
762
859
         *         statement.
763
860
         */
775
872
 
776
873
        /**
777
874
         * DOCUMENT ME!
778
 
         * 
 
875
         *
779
876
         * @return DOCUMENT ME!
780
877
         */
781
878
        public boolean isUniqueKey() {
784
881
 
785
882
        /**
786
883
         * DOCUMENT ME!
787
 
         * 
 
884
         *
788
885
         * @return DOCUMENT ME!
789
886
         */
790
887
        public boolean isUnsigned() {
793
890
 
794
891
        /**
795
892
         * DOCUMENT ME!
796
 
         * 
 
893
         *
797
894
         * @return DOCUMENT ME!
798
895
         */
799
896
        public boolean isZeroFill() {
816
913
                        this.mysqlType = MysqlDefs.FIELD_TYPE_LONG_BLOB;
817
914
                }
818
915
        }
819
 
        
 
916
 
820
917
        private boolean isNativeNumericType() {
821
 
                return ((this.mysqlType >= MysqlDefs.FIELD_TYPE_TINY && 
 
918
                return ((this.mysqlType >= MysqlDefs.FIELD_TYPE_TINY &&
822
919
                                        this.mysqlType <= MysqlDefs.FIELD_TYPE_DOUBLE) ||
823
920
                                        this.mysqlType == MysqlDefs.FIELD_TYPE_LONGLONG ||
824
921
                                        this.mysqlType == MysqlDefs.FIELD_TYPE_YEAR);
825
922
        }
826
 
        
 
923
 
827
924
        private boolean isNativeDateTimeType() {
828
925
                return (this.mysqlType == MysqlDefs.FIELD_TYPE_DATE ||
829
926
                                this.mysqlType == MysqlDefs.FIELD_TYPE_NEWDATE ||
834
931
 
835
932
        /**
836
933
         * DOCUMENT ME!
837
 
         * 
 
934
         *
838
935
         * @param conn
839
936
         *            DOCUMENT ME!
840
937
         */
841
 
        public void setConnection(Connection conn) {
 
938
        public void setConnection(ConnectionImpl conn) {
842
939
                this.connection = conn;
843
940
 
844
941
                this.charsetName = this.connection.getEncoding();
857
954
                try {
858
955
                        StringBuffer asString = new StringBuffer();
859
956
                        asString.append(super.toString());
860
 
 
861
 
                        asString.append("\n  catalog: ");
 
957
                        asString.append("[");
 
958
                        asString.append("catalog=");
862
959
                        asString.append(this.getDatabaseName());
863
 
                        asString.append("\n  table name: ");
 
960
                        asString.append(",tableName=");
864
961
                        asString.append(this.getTableName());
865
 
                        asString.append("\n  original table name: ");
 
962
                        asString.append(",originalTableName=");
866
963
                        asString.append(this.getOriginalTableName());
867
 
                        asString.append("\n  column name: ");
 
964
                        asString.append(",columnName=");
868
965
                        asString.append(this.getName());
869
 
                        asString.append("\n  original column name: ");
 
966
                        asString.append(",originalColumnName=");
870
967
                        asString.append(this.getOriginalName());
871
 
                        asString.append("\n  MySQL data type: ");
 
968
                        asString.append(",mysqlType=");
872
969
                        asString.append(getMysqlType());
873
 
 
874
 
                        if (this.buffer != null) {
875
 
                                asString.append("\n\nData as received from server:\n\n");
876
 
                                asString.append(StringUtils.dumpAsHex(this.buffer,
877
 
                                                this.buffer.length));
878
 
                        }
879
 
 
 
970
                        asString.append("(");
 
971
                        asString.append(MysqlDefs.typeToName(getMysqlType()));
 
972
                        asString.append(")");
 
973
                        asString.append(",flags=");
 
974
                        
 
975
                        if (isAutoIncrement()) {
 
976
                                asString.append(" AUTO_INCREMENT");
 
977
                        }
 
978
                        
 
979
                        if (isPrimaryKey()) {
 
980
                                asString.append(" PRIMARY_KEY");
 
981
                        }
 
982
                        
 
983
                        if (isUniqueKey()) {
 
984
                                asString.append(" UNIQUE_KEY");
 
985
                        }
 
986
                        
 
987
                        if (isBinary()) {
 
988
                                asString.append(" BINARY");
 
989
                        }
 
990
                        
 
991
                        if (isBlob()) {
 
992
                                asString.append(" BLOB");
 
993
                        }
 
994
                        
 
995
                        if (isMultipleKey()) {
 
996
                                asString.append(" MULTI_KEY");
 
997
                        }
 
998
                        
 
999
                        if (isUnsigned()) {
 
1000
                                asString.append(" UNSIGNED");
 
1001
                        }
 
1002
                        
 
1003
                        if (isZeroFill()) {
 
1004
                                asString.append(" ZEROFILL");
 
1005
                        }
 
1006
 
 
1007
                        asString.append(", charsetIndex=");
 
1008
                        asString.append(this.charsetIndex);
 
1009
                        asString.append(", charsetName=");
 
1010
                        asString.append(this.charsetName);
 
1011
                        
 
1012
                        
 
1013
                        //if (this.buffer != null) {
 
1014
                        //      asString.append("\n\nData as received from server:\n\n");
 
1015
                        //      asString.append(StringUtils.dumpAsHex(this.buffer,
 
1016
                        //                      this.buffer.length));
 
1017
                        //}
 
1018
 
 
1019
                        asString.append("]");
 
1020
                        
880
1021
                        return asString.toString();
881
1022
                } catch (Throwable t) {
882
1023
                        return super.toString();