OSDN Git Service

Fixed the problem
authorleo <leo@ae02f08e-27ec-0310-ae8c-8ba02fe2eafd>
Tue, 21 Apr 2009 03:57:13 +0000 (03:57 +0000)
committerleo <leo@ae02f08e-27ec-0310-ae8c-8ba02fe2eafd>
Tue, 21 Apr 2009 03:57:13 +0000 (03:57 +0000)
http://code.google.com/p/xerial/issues/detail?id=6

git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/sqlite-jdbc@3229 ae02f08e-27ec-0310-ae8c-8ba02fe2eafd

pom.xml
src/main/java/org/sqlite/DB.java
src/main/java/org/sqlite/NativeDB.c
src/main/java/org/sqlite/PrepStmt.java
src/main/java/org/sqlite/SQLiteErrorCode.java [new file with mode: 0644]
src/main/resources/native/Windows/x86/sqlitejdbc.dll
src/test/java/org/sqlite/ConnectionTest.java
src/test/java/org/sqlite/QueryTest.java

diff --git a/pom.xml b/pom.xml
index c62ccd8..88e9458 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
   <modelVersion>4.0.0</modelVersion>\r
   <groupId>org.xerial</groupId>\r
   <artifactId>sqlite-jdbc</artifactId>\r
-  <version>3.6.11.2</version>\r
+  <version>3.6.11.3-SNAPSHOT</version>\r
   <name>SQLite JDBC</name>\r
   <description>SQLite JDBC library</description>\r
 \r
index f7d0f64..6cae9e6 100644 (file)
@@ -380,6 +380,12 @@ abstract class DB implements Codes
         throw new SQLException(errmsg());
     }
 
+    final void throwex(int errorCode) throws SQLException
+    {
+        SQLiteErrorCode code = SQLiteErrorCode.getErrorCode(errorCode);
+        throw new SQLException(String.format("%s (%s)", code, errmsg()));
+    }
+
     /*
      * SQLite and the JDBC API have very different ideas about the meaning
      * of auto-commit. Under JDBC, when executeUpdate() returns in
index fd16081..fa8af0e 100644 (file)
@@ -48,6 +48,16 @@ static void throwex(JNIEnv *env, jobject this)
     (*env)->CallVoidMethod(env, this, mth_throwex);
 }
 
+static void throw_errorcode(JNIEnv *env, jobject this, int errorCode)
+{
+    static jmethodID mth_throwex = 0;
+
+    if (!mth_throwex)
+        mth_throwex = (*env)->GetMethodID(env, dbclass, "throwex", "(I)V");
+
+    (*env)->CallVoidMethod(env, this, mth_throwex, (jint) errorCode);
+}
+
 static void throwexmsg(JNIEnv *env, const char *str)
 {
     static jmethodID mth_throwexmsg = 0;
@@ -309,9 +319,10 @@ JNIEXPORT void JNICALL Java_org_sqlite_NativeDB__1open(
         return;
     }
 
-    str = (*env)->GetStringUTFChars(env, file, 0); 
-    if (sqlite3_open(str, &db)) {
-        throwex(env, this);
+    str = (*env)->GetStringUTFChars(env, file, 0);
+    ret = sqlite3_open(str, &db); 
+    if (ret) {
+        throw_errorcode(env, this, ret);
         sqlite3_close(db);
         return;
     }
index 7aa3f22..ac6ad38 100644 (file)
@@ -214,7 +214,7 @@ final class PrepStmt extends Stmt implements PreparedStatement, ParameterMetaDat
 
     public void setFloat(int pos, float value) throws SQLException
     {
-        setDouble(pos, value);
+        batch(pos, new Float(value));
     }
 
     public void setInt(int pos, int value) throws SQLException
@@ -254,7 +254,7 @@ final class PrepStmt extends Stmt implements PreparedStatement, ParameterMetaDat
         else if (value instanceof Integer)
             batch(pos, value);
         else if (value instanceof Short)
-            batch(pos, ((Short) value).intValue());
+            batch(pos, new Integer(((Short) value).intValue()));
         else if (value instanceof Float)
             batch(pos, value);
         else if (value instanceof Double)
diff --git a/src/main/java/org/sqlite/SQLiteErrorCode.java b/src/main/java/org/sqlite/SQLiteErrorCode.java
new file mode 100644 (file)
index 0000000..2028bbe
--- /dev/null
@@ -0,0 +1,92 @@
+/*--------------------------------------------------------------------------
+ *  Copyright 2009 Taro L. Saito
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *--------------------------------------------------------------------------*/
+//--------------------------------------
+// sqlite-jdbc Project
+//
+// SQLiteErrorCode.java
+// Since: Apr 21, 2009
+//
+// $URL$ 
+// $Author$
+//--------------------------------------
+package org.sqlite;
+
+/**
+ * SQLite3 error code
+ * 
+ * @author leo
+ * @see http://www.sqlite.org/c3ref/c_abort.html
+ * 
+ */
+public enum SQLiteErrorCode {
+
+    UNKNOWN_ERROR(-1, "unknown error"),
+    SQLITE_OK(0, "Successful result"),
+    /* beginning-of-error-codes */
+    SQLITE_ERROR(1, "SQL error or missing database"),
+    SQLITE_INTERNAL(2, "Internal logic error in SQLite"),
+    SQLITE_PERM(3, " Access permission denied"),
+    SQLITE_ABORT(4, " Callback routine requested an abort"),
+    SQLITE_BUSY(5, " The database file is locked"),
+    SQLITE_LOCKED(6, " A table in the database is locked"),
+    SQLITE_NOMEM(7, " A malloc() failed"),
+    SQLITE_READONLY(8, " Attempt to write a readonly database"),
+    SQLITE_INTERRUPT(9, " Operation terminated by sqlite3_interrupt()"),
+    SQLITE_IOERR(10, " Some kind of disk I/O error occurred"),
+    SQLITE_CORRUPT(11, " The database disk image is malformed"),
+    SQLITE_NOTFOUND(12, " NOT USED. Table or record not found"),
+    SQLITE_FULL(13, " Insertion failed because database is full"),
+    SQLITE_CANTOPEN(14, " Unable to open the database file"),
+    SQLITE_PROTOCOL(15, " NOT USED. Database lock protocol error"),
+    SQLITE_EMPTY(16, " Database is empty"),
+    SQLITE_SCHEMA(17, " The database schema changed"),
+    SQLITE_TOOBIG(18, " String or BLOB exceeds size limit"),
+    SQLITE_CONSTRAINT(19, " Abort due to constraint violation"),
+    SQLITE_MISMATCH(20, " Data type mismatch"),
+    SQLITE_MISUSE(21, " Library used incorrectly"),
+    SQLITE_NOLFS(22, " Uses OS features not supported on host"),
+    SQLITE_AUTH(23, " Authorization denied"),
+    SQLITE_FORMAT(24, " Auxiliary database format error"),
+    SQLITE_RANGE(25, " 2nd parameter to sqlite3_bind out of range"),
+    SQLITE_NOTADB(26, " File opened that is not a database file"),
+    SQLITE_ROW(100, " sqlite3_step() has another row ready"),
+    SQLITE_DONE(101, " sqlite3_step() has finished executing");
+
+    public final int code;
+    public final String message;
+
+    private SQLiteErrorCode(int code, String message)
+    {
+        this.code = code;
+        this.message = message;
+    }
+
+    public static SQLiteErrorCode getErrorCode(int errorCode)
+    {
+        for (SQLiteErrorCode each : SQLiteErrorCode.values())
+        {
+            if (errorCode == each.code)
+                return each;
+        }
+        return UNKNOWN_ERROR;
+    }
+
+    @Override
+    public String toString()
+    {
+        return String.format("[%s] %s", this.name(), message);
+    }
+}
index 0bf0364..4de2894 100644 (file)
Binary files a/src/main/resources/native/Windows/x86/sqlitejdbc.dll and b/src/main/resources/native/Windows/x86/sqlitejdbc.dll differ
index b5b2d3f..04c4de9 100644 (file)
@@ -1,45 +1,71 @@
-package org.sqlite;
-
-import java.io.File;
-import java.sql.*;
-import org.junit.*;
-import static org.junit.Assert.*;
-
-/** These tests check whether access to files is woring correctly and
- *  some Connection.close() cases. */
-public class ConnectionTest
-{
-    @BeforeClass public static void forName() throws Exception {
-        Class.forName("org.sqlite.JDBC");
-    }
-
-    @Test public void openMemory() throws SQLException {
-        Connection conn = DriverManager.getConnection("jdbc:sqlite:");
-        conn.close();
-    }
-
-    @Test public void isClosed() throws SQLException {
-        Connection conn = DriverManager.getConnection("jdbc:sqlite:");
-        conn.close();
-        assertTrue(conn.isClosed());
-    }
-
-    @Test public void openFile() throws SQLException {
-        File testdb = new File("test.db");
-        if (testdb.exists()) testdb.delete();
-        assertFalse(testdb.exists());
-        Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");
-        conn.close();
-        assertTrue(testdb.exists());
-        testdb.delete();
-    }
-
-    @Test(expected= SQLException.class)
-    public void closeTest() throws SQLException {
-        Connection conn = DriverManager.getConnection("jdbc:sqlite:");
-        PreparedStatement prep = conn.prepareStatement("select null;");
-        ResultSet rs = prep.executeQuery();
-        conn.close();
-        prep.clearParameters();
-    }
-}
+package org.sqlite;\r
+\r
+import static org.junit.Assert.*;\r
+\r
+import java.io.File;\r
+import java.sql.Connection;\r
+import java.sql.DriverManager;\r
+import java.sql.PreparedStatement;\r
+import java.sql.ResultSet;\r
+import java.sql.SQLException;\r
+\r
+import org.junit.BeforeClass;\r
+import org.junit.Test;\r
+\r
+/**\r
+ * These tests check whether access to files is woring correctly and some\r
+ * Connection.close() cases.\r
+ */\r
+public class ConnectionTest\r
+{\r
+    @BeforeClass\r
+    public static void forName() throws Exception\r
+    {\r
+        Class.forName("org.sqlite.JDBC");\r
+    }\r
+\r
+    @Test\r
+    public void openMemory() throws SQLException\r
+    {\r
+        Connection conn = DriverManager.getConnection("jdbc:sqlite:");\r
+        conn.close();\r
+    }\r
+\r
+    @Test\r
+    public void isClosed() throws SQLException\r
+    {\r
+        Connection conn = DriverManager.getConnection("jdbc:sqlite:");\r
+        conn.close();\r
+        assertTrue(conn.isClosed());\r
+    }\r
+\r
+    @Test\r
+    public void openFile() throws SQLException\r
+    {\r
+        File testdb = new File("test.db");\r
+        if (testdb.exists())\r
+            testdb.delete();\r
+        assertFalse(testdb.exists());\r
+        Connection conn = DriverManager.getConnection("jdbc:sqlite:test.db");\r
+        conn.close();\r
+        assertTrue(testdb.exists());\r
+        testdb.delete();\r
+    }\r
+\r
+    @Test(expected = SQLException.class)\r
+    public void closeTest() throws SQLException\r
+    {\r
+        Connection conn = DriverManager.getConnection("jdbc:sqlite:");\r
+        PreparedStatement prep = conn.prepareStatement("select null;");\r
+        ResultSet rs = prep.executeQuery();\r
+        conn.close();\r
+        prep.clearParameters();\r
+    }\r
+\r
+    @Test\r
+    public void openInvalidLocation() throws SQLException\r
+    {\r
+        Connection conn = DriverManager.getConnection("jdbc:sqlite:/");\r
+        conn.close();\r
+    }\r
+}\r
index 940bb1a..d0c5dbe 100644 (file)
@@ -92,7 +92,6 @@ public class QueryTest
 
         ResultSet rs = conn.createStatement().executeQuery("select * from sample");
         assertTrue(rs.next());
-
         assertEquals(now, rs.getDate(1));
 
     }