package com.orientechnologies.orient.jdbc;

import org.junit.Test;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;

public class OrientJdbcResultSetTest extends OrientJdbcBaseTest {

  @Test
  public void shouldMapReturnTypes() throws Exception {

    assertFalse(conn.isClosed());

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT stringKey, intKey, text, length, date FROM Item");

    ResultSetMetaData metaData = rs.getMetaData();

    assertNotNull(metaData);
  }

  @Test
  public void testDouble() throws Exception {
    assertFalse(conn.isClosed());

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM Author limit 10");
    int count = 0;
    while (rs.next()) {
      Double rating = rs.getDouble("rating");
      assertNotNull(rating);
      count++;
    }
    assertEquals(count, 10);
  }

  @Test
  public void testDoubleConversion() throws Exception {
    assertFalse(conn.isClosed());

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT * FROM Author limit 10");
    int count = 0;
    while (rs.next()) {
      Double rating = rs.getDouble("uuid");
      assertNotNull(rating);
      count++;
    }
    assertEquals(count, 10);
  }
}

@@ -35,24 +35,56 @@
 nt.jdbc;%0D%0A%0D%0A
+import junit.framework.Assert;%0D%0A
 import org.j
@@ -161,16 +161,47 @@
 aData;%0D%0A
+import java.sql.SQLException;%0D%0A
 import j
@@ -1563,12 +1563,399 @@
 );%0D%0A  %7D%0D
+%0A%0D%0A  @Test%0D%0A  public void testNoResult() throws Exception %7B%0D%0A    assertFalse(conn.isClosed());%0D%0A%0D%0A    Statement stmt = conn.createStatement();%0D%0A    ResultSet rs = stmt.executeQuery(%22SELECT * FROM Author where false = true%22);%0D%0A    try %7B%0D%0A      rs.getMetaData().getColumnType(1);%0D%0A      Assert.assertTrue(false);%0D%0A    %7D catch (SQLException e) %7B%0D%0A      Assert.assertTrue(true);%0D%0A    %7D%0D%0A  %7D%0D
 %0A%7D%0D%0A

Test case for issue #29