[CONJ-243] ResultSet.getString returns '1' on BOOLEAN-false values. Created: 2016-01-11  Updated: 2016-01-12  Resolved: 2016-01-12

Status: Closed
Project: MariaDB Connector/J
Component/s: Other
Affects Version/s: 1.3.3, 1.3.4
Fix Version/s: 1.3.5

Type: Bug Priority: Major
Reporter: Andreas Pillath Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None
Environment:

'org.mariadb.jdbc:mariadb-java-client:1.3.4'
MariaDB 10.0.22


Issue Links:
Problem/Incident
is caused by CONJ-225 limit cause `getString` from int colu... Closed

 Description   

ResultSet.getString() returns "1" for BOOLEAN/TINYINT fields with '0' value.

      Statement stmt = con.createStatement();
      stmt.executeUpdate("drop table if exists tt");
      stmt.executeUpdate("create table tt(t1 BOOLEAN)");
      stmt.executeUpdate("insert into tt(t1) values(FALSE)");      
      ResultSet q = stmt.executeQuery("select t1 from tt");
      while (q.next())
      {
         String res = q.getString(1);
         boolean b = q.getBoolean(1);
         System.out.println(res + "/" + b);
      }

This code prints

1/false

in version 1.3.4 and

0/false

in version 1.2.3

The problem seems to be in MariaDbValueObject, isBinaryEncoded=false, but the value 48='0' is evaluated as binary.

Code-Snippet:

 case TINYINT:
                if (options.tinyInt1isBit && columnInfo.getLength() == 1) {
                    return (rawBytes[0] == 0) ? "0" : "1";
                }
                if (this.isBinaryEncoded) {
                    return String.valueOf(getTinyInt());
                }
                break;

Values in debugger:

this	MariaDbValueObject  (id=21)	
	columnInfo	ColumnInformation  (id=23)	
		buffer	HeapByteBuffer  (id=34)	
		charsetNumber	63	
		decimals	0	
		flags	0	
		length	1	
		type	MariaDbType  (id=25)	
	dataType	MariaDbType  (id=25)	
	isBinaryEncoded	false	
	options	Options  (id=30)	
		allowLocalInfile	true	
		allowMultiQueries	false	
		alwaysAutoGeneratedKeys	false	
		assureReadOnly	false	
		autoReconnect	false	
		cachePrepStmts	true	
		clientCertificateKeyStorePassword	null	
		clientCertificateKeyStoreUrl	null	
		connectTimeout	null	
		createDatabaseIfNotExist	false	
		dumpQueriesOnException	false	
		failOnReadOnly	false	
		failoverLoopRetries	120	
		interactiveClient	false	
		loadBalanceBlacklistTimeout	50	
		localSocket	null	
		localSocketAddress	null	
		maximizeMysqlCompatibility	false	
		nullCatalogMeansCurrent	true	
		password	"" (id=40)	
		pinGlobalTxToPhysicalConnection	false	
		pipe	null	
		prepStmtCacheSize	Integer  (id=43)	
		prepStmtCacheSqlLimit	Integer  (id=46)	
		retriesAllDown	120	
		rewriteBatchedStatements	false	
		serverSslCert	null	
		serverTimezone	null	
		sessionVariables	null	
		sharedMemory	null	
		socketFactory	null	
		socketTimeout	null	
		tcpAbortiveClose	false	
		tcpKeepAlive	false	
		tcpNoDelay	false	
		tcpRcvBuf	null	
		tcpSndBuf	null	
		tinyInt1isBit	true	
		trustCertificateKeyStorePassword	null	
		trustCertificateKeyStoreUrl	null	
		trustServerCertificate	false	
		useCompression	false	
		useFractionalSeconds	true	
		useLegacyDatetimeCode	true	
		useOldAliasMetadataBehavior	false	
		user	"root" (id=107)	
		useServerPrepStmts	true	
		useSsl	false	
		validConnectionTimeout	120	
		yearIsDateType	true	
	rawBytes	(id=32)	
		[0]	48	
cal	null	



 Comments   
Comment by Diego Dupin [ 2016-01-12 ]

Thanks for reporting this.
Corrected for next correction version 1.3.5

Generated at Thu Feb 08 03:14:14 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.