Commits

Grace Batumbya  committed 175e34e

Fixes Issue #109 SQLiteConfig ignores calls to setDateStringFormat/setDateClass/setDatePrecision.
(grafted from 1d3d2425cb7e3a9536539f963fde4c5f07e5dd2e)

  • Participants
  • Parent commits ce49c53
  • Branches feature/jdbc4

Comments (0)

Files changed (2)

File 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";
-    public final DateClass dateClass;
-    public final DatePrecision datePrecision;
-    public final long dateMultiplier;
-    public final String dateStringFormat;
+    public DateClass dateClass;
+    public DatePrecision datePrecision;
+    public long dateMultiplier;
+    public 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;
     }
 
     /**

File 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()));
+    }
+}