SqliteMailbox: index columns
[org.ibex.mail.git] / src / org / ibex / mail / SqliteMailbox.java
index c423fef..0d80532 100644 (file)
@@ -22,7 +22,18 @@ public class SqliteMailbox extends Mailbox.Default implements MailTree {
     private Connection conn;
     private static final String columns  =
         "                                        messageid_,       from_,to_,date_,subject_,headers_,body_,flags_";
-
+    private static final String[] indexedColumns = new String[] {
+        "uid_",
+        "messageid_",
+        "flags_",
+        /*
+        "from_",
+        "to_",
+        "subject_",
+        "date_"
+        */
+    };
+    
     /**
      *  from http://www.sqlite.org/autoinc.html
      *  "If a column has the type INTEGER PRIMARY KEY AUTOINCREMENT
@@ -35,6 +46,7 @@ public class SqliteMailbox extends Mailbox.Default implements MailTree {
      *   allowed and any attempt to insert a new row will fail with an
      *   SQLITE_FULL error.
      */
+    // FIXME: should messageid_ be decared unique?
     private static final String columns_ =
         "uid_ INTEGER PRIMARY KEY AUTOINCREMENT, messageid_ unique,from_,to_,date_,subject_,headers_,body_,flags_";
 
@@ -57,13 +69,9 @@ public class SqliteMailbox extends Mailbox.Default implements MailTree {
             } else {
                 this.uidValidity = rs.getInt(1);
             }
-            try {
-                //conn.prepareStatement("create virtual table 'mail' using FTS2("+columns_+")").executeUpdate();
-                conn.prepareStatement("create table 'mail' ("+columns_+")").executeUpdate();
-            } catch (SQLException e) {
-                /* FIXME */
-            }
-            conn.prepareStatement("create index if not exists uid_index on mail(uid_);").executeUpdate();
+            conn.prepareStatement("create table if not exists 'mail' ("+columns_+")").executeUpdate();
+            for(String name : indexedColumns)
+                conn.prepareStatement("create index if not exists "+name+"index on mail("+name+");").executeUpdate();
         }
         catch (SQLException e) { throw new RuntimeException(e); }
         catch (ClassNotFoundException e) { throw new RuntimeException(e); }