add SqliteDB.close(ResultSet) and use it
[org.ibex.mail.git] / src / org / ibex / mail / SqliteDB.java
index 4b818ce..6167eec 100644 (file)
@@ -38,18 +38,29 @@ public class SqliteDB {
         conn.prepareStatement("PRAGMA cache_size="+Math.ceil(kilobytes/1.5)+";").executeUpdate();
     }
 
+
+    public void close(ResultSet rs) {
+        if (rs==null) return;
+        try {
+            rs.close();
+        } catch (SQLException s) {
+            Log.error(ResultSet.class, s);
+        }
+    }
+
     public SqliteDB(String filename) {
         this.filename = filename;
         try {
+            Log.error("start", "initializing " + filename);
             Class.forName("org.sqlite.JDBC");
             conn = DriverManager.getConnection("jdbc:sqlite:"+filename);
             conn.prepareStatement("PRAGMA auto_vacuum = 1").executeUpdate();
-            conn.prepareStatement("VACUUM").executeUpdate();
+            //conn.prepareStatement("VACUUM").executeUpdate();
 
             // until we have better assurances about locking on network filesystems...
             conn.prepareStatement("PRAGMA locking_mode = EXCLUSIVE").executeQuery();
 
-            conn.prepareStatement("PRAGMA temp_store = MEMORY").executeUpdate();
+            //conn.prepareStatement("PRAGMA temp_store = MEMORY").executeUpdate();
             conn.prepareStatement("PRAGMA page_size=4096").executeUpdate();
             conn.prepareStatement("PRAGMA cache_size=2000").executeUpdate();
             ResultSet rs = conn.prepareStatement("PRAGMA integrity_check").executeQuery();
@@ -57,6 +68,7 @@ public class SqliteDB {
             String result = rs.getString(1);
             if (!result.equals("ok"))
                 throw new RuntimeException("PRAGMA integrity_check returned \""+result+"\"");
+            Log.error(".", "done initializing " + filename);
         }
         catch (SQLException e) { throw new RuntimeException(e); }
         catch (ClassNotFoundException e) { throw new RuntimeException(e); }
@@ -124,7 +136,7 @@ public class SqliteDB {
     }
 
     static String streamToString(Stream stream) throws Exception {
-        // FIXME
+        // FIXME!!!! This is corrupting line endings!!!!
         StringBuffer b = new StringBuffer();
         for(String s = stream.readln(); s!=null; s=stream.readln())
             b.append(s+"\n");