<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
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
(*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;
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;
}
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
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)
--- /dev/null
+/*--------------------------------------------------------------------------
+ * 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);
+ }
+}
-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
ResultSet rs = conn.createStatement().executeQuery("select * from sample");
assertTrue(rs.next());
-
assertEquals(now, rs.getDate(1));
}