[
https://issues.apache.org/jira/browse/SIS-180?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14166398#comment-14166398
]
M. Le Bihan commented on SIS-180:
---------------------------------
I have done the first implementation of the Connection / Statement / ResultSet
that succeed in reading the DBF content.
But I need to commit all the changes I've done on a remote branch, because they
are many.
Else, maybe this week-end I will upload the files on this JIRA, but it will be
less easy.
{code}package org.apache.sis.storage.database.jdbc;
import static org.junit.Assert.*;
import java.io.*;
import java.sql.*;
import java.text.*;
import org.junit.*;
import org.opengis.test.*;
/**
* ResultSet test.
* @author Marc LE BIHAN
*/
public class ResultSetTest extends TestCase {
/** Database file. */
private File dbfFile;
/**
* Read the first record.
* @throws SQLException if an SQL error occurs.
*/
@Test public void readFirstRecord() throws SQLException {
Driver driver = new DBFDriver();
Connection connection =
driver.connect(dbfFile.getAbsolutePath(), null);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("Dummy"); // We don't care
currently of the request : we are returning everything each time.
rs.next();
assertEquals("The record has not the expected field value.",
"336TH ST", rs.getString("ST_NAME"));
rs.close();
stmt.close();
connection.close();
}
/**
* Read all the DBF records.
* @throws SQLException if an SQL error occurs.
*/
@Test public void readAllRecords() throws SQLException {
Driver driver = new DBFDriver();
Connection connection =
driver.connect(dbfFile.getAbsolutePath(), null);
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("Dummy"); // We don't care
currently of the request : we are returning everything each time.
int count = 0;
while(rs.next())
count ++;
assertTrue("Less than one record was readed.", count > 1);
rs.close();
stmt.close();
connection.close();
}
/**
* Test setup.
*/
@Before public void setup() {
dbfFile = new
File("src/test/resources/org/apache/sis/storage/shapefile/SignedBikeRoute_4326_clipped.dbf");
assertTrue(MessageFormat.format("The database file ''{0}'' used
for testing doesn''t exist." , dbfFile.getAbsolutePath()), dbfFile.exists());
}
}
{code}
> Place a crude JDBC driver over Dbase files
> ------------------------------------------
>
> Key: SIS-180
> URL: https://issues.apache.org/jira/browse/SIS-180
> Project: Spatial Information Systems
> Issue Type: Improvement
> Components: Storage
> Affects Versions: 0.5
> Reporter: M. Le Bihan
> Priority: Minor
>
> It would be useful to be able to query DBF content through SQL.
> But there are no free drivers available for the old _Dbase 3_ format.
> The first step is to create short implementations of _Connection_,
> _Statement_, _ResultSet_, _ResultSetMetadata_ interfaces for a JDBC using our
> _Database_ class as core binary loader at the begining.
> The main difficulty is to respond to a SQL request, and first : being able to
> analyze it to understand what is expected.
> The SQL request analysis is a very strong job, but I suggest to ease it a lot
> by relying on _AntLR_ API for grammar analysis, associated with a BNF grammar
> file, maybe taken from ^1^ or from elsewhere (grammars are of public domain).
> The goal of this current JIRA is only to be able to perform a
> _SELECT * FROM <shapefile layer name>_
> The WHERE clause or the selection of fields, will come later in other JIRA.
> No transactions, classic _Statement_ only.
> _PreparedStatement_ would be also implemented later (another JIRA).
> Of course, this improvment can be discarded if an open source or free driver
> is discovered, that would allow us to execute SQL requests on DBase 3 easily.
> ^1^ For example, [http://www.savage.net.au/SQL/] has some BNF, but maybe
> elsewhere they will more compliant with AntLR.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)