Skip to content

Commit

Permalink
[CONJ-243] correction getString on tinyInt false value
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jan 12, 2016
1 parent b4262bd commit 01ff2ef
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 8 deletions.
19 changes: 19 additions & 0 deletions README.md
Expand Up @@ -25,6 +25,25 @@ or maven :
</dependency>
```

Development snapshot are available on sonatype nexus repository
```script
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>1.3.5-SNAPSHOT</version>
</dependency>
</dependencies>
```

## Documentation

For a Getting started guide, API docs, recipes, etc. see the
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@
<artifactId>mariadb-java-client</artifactId>
<packaging>jar</packaging>
<name>mariadb-java-client</name>
<version>1.3.4</version>
<version>1.3.5-SNAPSHOT</version>
<description>JDBC driver for MariaDB and MySQL</description>
<url>https://mariadb.com/kb/en/mariadb/about-mariadb-connector-j/</url>

Expand Down
Expand Up @@ -131,9 +131,6 @@ public String getString(Calendar cal) throws SQLException {
}
break;
case TINYINT:
if (options.tinyInt1isBit && columnInfo.getLength() == 1) {
return (rawBytes[0] == 0) ? "0" : "1";
}
if (this.isBinaryEncoded) {
return String.valueOf(getTinyInt());
}
Expand Down
46 changes: 42 additions & 4 deletions src/test/java/org/mariadb/jdbc/BooleanTest.java
Expand Up @@ -10,6 +10,8 @@

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertEquals;


public class BooleanTest extends BaseTest {
Expand All @@ -20,6 +22,8 @@ public class BooleanTest extends BaseTest {
@BeforeClass()
public static void initClass() throws SQLException {
createTable("booleantest", "id int not null primary key auto_increment, test boolean");
createTable("booleanvalue", "test boolean");

}

@Test
Expand All @@ -28,10 +32,44 @@ public void testBoolean() throws SQLException {
stmt.execute("insert into booleantest values(null, true)");
stmt.execute("insert into booleantest values(null, false)");
ResultSet rs = stmt.executeQuery("select * from booleantest");
assertTrue(rs.next());
assertTrue(rs.getBoolean(2));
assertTrue(rs.next());
assertFalse(rs.getBoolean(2));
if (rs.next()) {
assertTrue(rs.getBoolean(2));
if (rs.next()) {
assertFalse(rs.getBoolean(2));
} else {
fail("must have a result !");
}
} else {
fail("must have a result !");
}

}

@Test
public void testBooleanString() throws SQLException {
Statement stmt = sharedConnection.createStatement();
stmt.execute("insert into booleanvalue values(true)");
stmt.execute("insert into booleanvalue values(false)");
stmt.execute("insert into booleanvalue values(4)");
ResultSet rs = stmt.executeQuery("select * from booleanvalue");

if (rs.next()) {
assertTrue(rs.getBoolean(1));
assertEquals("1", rs.getString(1));
if (rs.next()) {
assertFalse(rs.getBoolean(1));
assertEquals("0", rs.getString(1));
if (rs.next()) {
assertFalse(rs.getBoolean(1));
assertEquals("4", rs.getString(1));
} else {
fail("must have a result !");
}
} else {
fail("must have a result !");
}
} else {
fail("must have a result !");
}
}
}

0 comments on commit 01ff2ef

Please sign in to comment.