From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id C52E12C133 for ; Wed, 26 Sep 2018 05:33:36 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FAvl8RiRr1Qs for ; Wed, 26 Sep 2018 05:33:36 -0400 (EDT) Received: from mail-lf1-f65.google.com (mail-lf1-f65.google.com [209.85.167.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 6E82A2C122 for ; Wed, 26 Sep 2018 05:33:36 -0400 (EDT) Received: by mail-lf1-f65.google.com with SMTP id l26-v6so22622807lfc.8 for ; Wed, 26 Sep 2018 02:33:36 -0700 (PDT) From: Sergei Kalashnikov Subject: [tarantool-patches] [PATCH] jdbc: fix primary keys meta retrieval Date: Wed, 26 Sep 2018 12:33:28 +0300 Message-Id: <1537954408-3275-1-git-send-email-ztarvos@gmail.com> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Sergei Kalashnikov Fixed parsing primary keys metadata response. Updated integration tests. Closes #41 --- https://github.com/tarantool/tarantool-java/issues/41 https://github.com/ztarvos/tarantool-java/commits/gh-41-fix-jdbc-pk-meta .../org/tarantool/jdbc/SQLDatabaseMetadata.java | 8 +++--- .../java/org/tarantool/jdbc/AbstractJdbcIT.java | 11 ++++---- .../org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java | 32 ++++++++++++++++++++-- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java b/src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java index e43bcdc..790bbe7 100644 --- a/src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java +++ b/src/main/java/org/tarantool/jdbc/SQLDatabaseMetadata.java @@ -774,12 +774,12 @@ public class SQLDatabaseMetadata implements DatabaseMetaData { List> fields = (List>) space.get(FORMAT_IDX); List> indexes = (List>) connection.connection.select(_VINDEX, 0, Arrays.asList(space.get(SPACE_ID_IDX), 0), 0, 1, 0); List primaryKey = indexes.get(0); - List> parts = (List>) primaryKey.get(INDEX_FORMAT_IDX); + List> parts = (List>) primaryKey.get(INDEX_FORMAT_IDX); for (int i = 0; i < parts.size(); i++) { - List part = parts.get(i); - int ordinal = ((Number) part.get(0)).intValue(); + Map part = parts.get(i); + int ordinal = ((Number) part.get("field")).intValue(); String column = (String) fields.get(ordinal).get("name"); - rows.add(Arrays.asList(table, column, i + 1, "primary", primaryKey.get(NAME_IDX))); + rows.add(Arrays.asList(table, column, i + 1, primaryKey.get(NAME_IDX))); } } return new SQLNullResultSet((JDBCBridge.mock( diff --git a/src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java b/src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java index 21e3f53..abed9b6 100644 --- a/src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java +++ b/src/test/java/org/tarantool/jdbc/AbstractJdbcIT.java @@ -32,9 +32,6 @@ public abstract class AbstractJdbcIT { private static String URL = String.format("tarantool://%s:%d?user=%s&password=%s", host, port, user, pass); private static String[] initSql = new String[] { - "DROP TABLE IF EXISTS test", - "DROP TABLE IF EXISTS test_types", - "CREATE TABLE test(id INT PRIMARY KEY, val VARCHAR(100))", "INSERT INTO test VALUES (1, 'one'), (2, 'two'), (3, 'three')", @@ -78,12 +75,15 @@ public abstract class AbstractJdbcIT { "X'010203040506'," + //LONGVARBINARY "'1983-03-14'," + //DATE "'12:01:06'," + //TIME - "129479994)" //TIMESTAMP + "129479994)", //TIMESTAMP + + "CREATE TABLE test_compound(id1 INT, id2 INT, val VARCHAR(100), PRIMARY KEY (id1, id2))" }; private static String[] cleanSql = new String[] { "DROP TABLE IF EXISTS test", - "DROP TABLE IF EXISTS test_types" + "DROP TABLE IF EXISTS test_types", + "DROP TABLE IF EXISTS test_compound" }; static Object[] testRow = new Object[] { @@ -112,6 +112,7 @@ public abstract class AbstractJdbcIT { @BeforeAll public static void setupEnv() throws Exception { + sqlExec(cleanSql); sqlExec(initSql); } diff --git a/src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java b/src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java index b934bbe..984a60b 100644 --- a/src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java +++ b/src/test/java/org/tarantool/jdbc/JdbcDatabaseMetaDataIT.java @@ -1,6 +1,5 @@ package org.tarantool.jdbc; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; @@ -45,6 +44,9 @@ public class JdbcDatabaseMetaDataIT extends AbstractJdbcIT { assertTrue(rs.next()); assertEquals("TEST_TYPES", rs.getString("TABLE_NAME")); + assertTrue(rs.next()); + assertEquals("TEST_COMPOUND", rs.getString("TABLE_NAME")); + assertFalse(rs.next()); rs.close(); @@ -84,7 +86,6 @@ public class JdbcDatabaseMetaDataIT extends AbstractJdbcIT { rs.close(); } - @Disabled(value="Test ignored, issue#41") @Test public void testGetPrimaryKeys() throws SQLException { ResultSet rs = meta.getPrimaryKeys(null, null, "TEST"); @@ -103,4 +104,31 @@ public class JdbcDatabaseMetaDataIT extends AbstractJdbcIT { rs.close(); } + + @Test + public void testGetPrimaryKeysCompound() throws SQLException { + ResultSet rs = meta.getPrimaryKeys(null, null, "TEST_COMPOUND"); + + assertNotNull(rs); + assertTrue(rs.next()); + + assertNull(rs.getString("TABLE_CAT")); + assertNull(rs.getString("TABLE_SCHEM")); + assertEquals("TEST_COMPOUND", rs.getString("TABLE_NAME")); + assertEquals("ID1", rs.getString("COLUMN_NAME")); + assertEquals(1, rs.getInt("KEY_SEQ")); + assertEquals("pk_unnamed_TEST_COMPOUND_1", rs.getString("PK_NAME")); + + assertTrue(rs.next()); + assertNull(rs.getString("TABLE_CAT")); + assertNull(rs.getString("TABLE_SCHEM")); + assertEquals("TEST_COMPOUND", rs.getString("TABLE_NAME")); + assertEquals("ID2", rs.getString("COLUMN_NAME")); + assertEquals(2, rs.getInt("KEY_SEQ")); + assertEquals("pk_unnamed_TEST_COMPOUND_1", rs.getString("PK_NAME")); + + assertFalse(rs.next()); + + rs.close(); + } } -- 1.8.3.1