Skip to content

Commit 9e0b9a4

Browse files
committed
Fix: compilation under jdk 1.7
Fix: TestCsvDriver test for column name proper case
1 parent 953c35d commit 9e0b9a4

3 files changed

Lines changed: 55 additions & 12 deletions

File tree

src/main/java/Test.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
8+
import java.sql.*;
9+
import org.relique.jdbc.csv.CsvDriver;
10+
11+
public class Test
12+
{
13+
public static void main(String[] args) throws Exception
14+
{
15+
// Load the driver.
16+
Class.forName("org.relique.jdbc.csv.CsvDriver");
17+
18+
// Create a connection. The first command line parameter is
19+
// the directory containing the .csv files.
20+
// A single connection is thread-safe for use by several threads.
21+
//Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + args[0]);
22+
Connection conn = DriverManager.getConnection("jdbc:relique:csv:c:\\tmpbox\\CSV_relique2\\data\\");
23+
24+
// Create a Statement object to execute the query with.
25+
// A Statement is not thread-safe.
26+
Statement stmt = conn.createStatement();
27+
28+
// Select the ID and NAME columns from sample.csv
29+
//ResultSet results = stmt.executeQuery("SELECT nAme as NaMe FROM csv2000 group by nAme order by namE desc");// group by Name");
30+
ResultSet results = stmt.executeQuery("SELECT NAME FROM csv2000 group by nAme order by namE desc");// group by Name");
31+
// Dump out the results to a CSV file with the same format
32+
// using CsvJdbc helper function
33+
boolean append = true;
34+
CsvDriver.writeToCsv(results, System.out, append);
35+
36+
// Clean up
37+
conn.close();
38+
}
39+
}

src/main/java/org/relique/jdbc/csv/CsvResultSet.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,11 @@ public ResultSetMetaData getMetaData() throws SQLException
14431443
for(int i=0; i<columnCount; i++)
14441444
{
14451445
Object[] o = queryEnvironment.get(i);
1446-
columnNames[i] = originalColumnNames.getOrDefault(((String)o[0]).toUpperCase(), (String)o[0]);
1446+
String originalName = originalColumnNames.get(((String)o[0]).toUpperCase());
1447+
columnNames[i] = originalName != null
1448+
? originalName
1449+
: (String)o[0];
1450+
14471451
//TODO: The suggested title is usually specified by the SQL AS clause.
14481452
columnLabels[i] = columnNames[i];
14491453

src/test/java/org/relique/jdbc/csv/TestCsvDriver.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -529,8 +529,8 @@ public void testMetadataColumnLabels() throws SQLException
529529

530530
assertEquals("name of column 1 is incorrect", "XID", metadata.getColumnName(1));
531531
assertEquals("label of column 1 is incorrect", "XID", metadata.getColumnLabel(1));
532-
assertEquals("name of column 2 is incorrect", "NAME", metadata.getColumnName(2));
533-
assertEquals("label of column 2 is incorrect", "NAME", metadata.getColumnLabel(2));
532+
assertEquals("name of column 2 is incorrect", "Name", metadata.getColumnName(2));
533+
assertEquals("label of column 2 is incorrect", "Name", metadata.getColumnLabel(2));
534534
assertEquals("name of column 3 is incorrect", "DEPT", metadata.getColumnName(3));
535535
assertEquals("label of column 3 is incorrect", "DEPT", metadata.getColumnLabel(3));
536536

@@ -1880,13 +1880,13 @@ public void testFromIndexedTable() throws SQLException
18801880
"test"));
18811881

18821882
assertEquals("Incorrect Column Name 1", metadata.getColumnName(1),
1883-
"LOCATION");
1883+
"location");
18841884
assertEquals("Incorrect Column Name 2", metadata.getColumnName(2),
1885-
"STATION");
1885+
"Station");
18861886
assertEquals("Incorrect Column Name 3", metadata.getColumnName(3),
1887-
"DATUM");
1887+
"Datum");
18881888
assertEquals("Incorrect Column Name 4", metadata.getColumnName(4),
1889-
"TIJD");
1889+
"Tijd");
18901890

18911891
assertTrue(results.next());
18921892
for (int i = 1; i < 12; i++)
@@ -1939,15 +1939,15 @@ public void testFromIndexedTablePrepend() throws SQLException
19391939
"test"));
19401940

19411941
assertEquals("Incorrect Column Name 1", metadata.getColumnName(1),
1942-
"LOCATION");
1942+
"location");
19431943
assertEquals("Incorrect Column Name 1", metadata.getColumnName(2),
1944-
"FILE_DATE");
1944+
"file_date");
19451945
assertEquals("Incorrect Column Name 1", metadata.getColumnName(3),
1946-
"DATUM");
1946+
"Datum");
19471947
assertEquals("Incorrect Column Name 2", metadata.getColumnName(4),
1948-
"TIJD");
1948+
"Tijd");
19491949
assertEquals("Incorrect Column Name 3", metadata.getColumnName(5),
1950-
"STATION");
1950+
"Station");
19511951

19521952
assertTrue(results.next());
19531953
for (int i = 1; i < 12; i++)

0 commit comments

Comments
 (0)