Commits

Taro L. Saito committed 714f2f5

Avoid to set unknown pragma.

Fixes issue 54

Comments (0)

Files changed (1)

src/main/java/org/sqlite/SQLiteConfig.java

      */
     public void apply(Connection conn) throws SQLException {
 
-        HashSet<String> nonPragmaParams = new HashSet<String>();
-        nonPragmaParams.add(Pragma.OPEN_MODE.pragmaName);
-        nonPragmaParams.add(Pragma.SHARED_CACHE.pragmaName);
-        nonPragmaParams.add(Pragma.LOAD_EXTENSION.pragmaName);
+        HashSet<String> pragmaParams = new HashSet<String>();
+        for (Pragma each : Pragma.values()) {
+            pragmaParams.add(each.pragmaName);
+        }
+
+        pragmaParams.remove(Pragma.OPEN_MODE.pragmaName);
+        pragmaParams.remove(Pragma.SHARED_CACHE.pragmaName);
+        pragmaParams.remove(Pragma.LOAD_EXTENSION.pragmaName);
 
         Statement stat = conn.createStatement();
         try {
             int count = 0;
             for (Object each : pragmaTable.keySet()) {
                 String key = each.toString();
-                if (nonPragmaParams.contains(key))
+                if (!pragmaParams.contains(key))
                     continue;
 
                 String value = pragmaTable.getProperty(key);
-                stat.addBatch(String.format("pragma %s=%s", key, value));
+                String sql = String.format("pragma %s=%s", key, value);
+                stat.addBatch(sql);
                 count++;
             }
-            stat.executeBatch();
+            if (count > 0)
+                stat.executeBatch();
         }
         finally {
             if (stat != null)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.