Grace Batumbya avatar Grace Batumbya committed 1d3d242

Fixes Issue #109 SQLiteConfig ignores calls to setDateStringFormat/setDateClass/setDatePrecision.

Comments (0)

Files changed (2)

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

 
     /* Date storage class*/
     public final static String DEFAULT_DATE_STRING_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";
-    protected final DateClass dateClass;
-    protected final DatePrecision datePrecision;
-    protected final long dateMultiplier;
-    protected final String dateStringFormat;
+    protected DateClass dateClass;
+    protected DatePrecision datePrecision;
+    protected long dateMultiplier;
+    protected String dateStringFormat;
 
     /**
      * Default constructor.
 
     private static final String[] OnOff = new String[] { "true", "false" };
 
-    private static enum Pragma {
+    public static enum Pragma {
 
         // Parameters requiring SQLite3 API invocation
         OPEN_MODE("open_mode", "Database open-mode flag", null),
             this.description = description;
             this.choices = choices;
         }
+
+        public final String getPragmaName()
+        {
+            return pragmaName;
+        }
     }
 
     /**
     }
 
     /**
+     * @deprecated
      * Enables or disables the count-changes flag. When enabled, INSERT, UPDATE
      * and DELETE statements return the number of rows they modified.
      * @param enable True to enable; false to disable.
     }
 
     /**
+     * @deprecated
      * Enables or disables the empty_result_callbacks flag.
      * @param enable True to enable; false to disable.
      * false.
     }
 
     /**
+     * @deprecated
      * Enables or disables the full_column_name flag. This flag together with
      * the short_column_names flag determine the way SQLite assigns names to
      * result columns of SELECT statements.
      * @throws SQLException 
      */
     public void setDatePrecision(String datePrecision) throws SQLException {
-        setPragma(Pragma.DATE_PRECISION, DatePrecision.getPrecision(datePrecision).getValue());
+        this.datePrecision = DatePrecision.getPrecision(datePrecision);
     }
 
     public static enum DateClass implements PragmaValue {
      * @param dateClass One of INTEGER, TEXT or REAL
      */
     public void setDateClass(String dateClass) {
-        setPragma(Pragma.DATE_CLASS, DateClass.getDateClass(dateClass).getValue());
+        this.dateClass = DateClass.getDateClass(dateClass);
     }
 
     /**
      * @param dateStringFormat Format of date string
      */
     public void setDateStringFormat(String dateStringFormat) {
-        setPragma(Pragma.DATE_STRING_FORMAT, dateStringFormat);
+        this.dateStringFormat = dateStringFormat;
     }
 
     /**

src/test/java/org/sqlite/SQLiteConfigTest.java

+package org.sqlite;
+
+import static org.junit.Assert.*;
+
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.junit.Test;
+
+public class SQLiteConfigTest {
+
+    @Test
+    public void toProperites() throws SQLException
+    {
+        SQLiteConfig config = new SQLiteConfig();
+
+        config.setReadOnly(true);
+        config.setDateStringFormat("yyyy/mm/dd");
+        config.setDatePrecision("seconds");
+        config.setDateClass("real");
+
+        Properties properties = config.toProperties();
+
+        assertEquals("yyyy/mm/dd",
+            properties.getProperty(SQLiteConfig.Pragma.DATE_STRING_FORMAT.getPragmaName()));
+        assertEquals(SQLiteConfig.DatePrecision.SECONDS.name(),
+            properties.getProperty(SQLiteConfig.Pragma.DATE_PRECISION.getPragmaName()));
+        assertEquals(SQLiteConfig.DateClass.REAL.name(),
+            properties.getProperty(SQLiteConfig.Pragma.DATE_CLASS.getPragmaName()));
+    }
+}
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.