Export to GitHub

sqlite-jdbc - issue #26

SQLiteConfig.setEncoding does not work


Posted on May 5, 2012 by Happy Rabbit

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\"";

Comment #1

Posted on May 6, 2012 by Happy Rabbit

See attached patch file for a simple fix.

Attachments

Comment #2

Posted on Sep 8, 2012 by Quick Panda

Fixed on bitbucket: https://bitbucket.org/xerial/sqlite-jdbc/issue/2

Status: New

Labels:
Type-Defect Priority-Medium AffectedVersion-3.7.x FixedVersion-NA