davidjanmercado / sqlite-jdbc

Automatically exported from code.google.com/p/sqlite-jdbc
Apache License 2.0
0 stars 0 forks source link

SQLiteConfig.setEncoding does not work #26

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Class.forName(org.sqlite.JDBC.class.getCanonicalName());
String url = "jdbc:sqlite:";
SQLiteConfig config = new SQLiteConfig();
config.setEncoding(SQLiteConfig.Encoding.UTF8);
Connection conn = DriverManager.getConnection(url, config.toProperties());

What is the expected output?

- a new Connection object instance

What do you see instead?

- an SQLException (see below)

java.sql.BatchUpdateException: batch entry 1: [SQLITE_ERROR] SQL error or 
missing database (near "-": syntax error)

What version of the product are you using?

- sqlite-jdbc-3.7.2.jar
- compiled from source (branch: default, commit: f6429dadc828)

On what operating system?

Debian GNU/Linux "wheezy" (testing)

Please provide any additional information below.

The cause of the problem is to be found in SQLiteConfig.apply(Connection):

String sql = String.format("pragma %s=%s", key, value);

In the above example (which results in an SQLException) the parameters have the 
following values:

String key = "encoding";
String value = "UTF-8";

So the String sql becomes:

String sql = "pragma encoding=UTF-8";

But trying to execute this is futile as UTF-8 has to be enclosed in quotation 
marks for the sql-parser:

String sql = "pragma encoding=\"UTF-8\"";

Original issue reported on code.google.com by matthias...@gmx.de on 5 May 2012 at 4:51

GoogleCodeExporter commented 8 years ago
See attached patch file for a simple fix.

Original comment by matthias...@gmx.de on 6 May 2012 at 4:59

Attachments:

GoogleCodeExporter commented 8 years ago
Fixed on bitbucket: https://bitbucket.org/xerial/sqlite-jdbc/issue/2

Original comment by Grace.Ba...@gmail.com on 8 Sep 2012 at 2:24