System.Data.SQLite
Check-in [1f028b5b16]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improve the SQL type detection code in the ColumnType method.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 1f028b5b164aa60b1146d2f1003e5c4b02fda91b
User & Date: mistachkin 2016-03-22 20:20:14
Context
2016-03-22
20:20
Remove superfluous namespace qualifiers. check-in: 075e88e9e6 user: mistachkin tags: trunk
20:20
Improve the SQL type detection code in the ColumnType method. check-in: 1f028b5b16 user: mistachkin tags: trunk
18:00
Fix ColumnType method when not using the interop assembly. check-in: c5f0bf844f user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to System.Data.SQLite/SQLite3.cs.

  1898   1898       internal override TypeAffinity ColumnAffinity(SQLiteStatement stmt, int index)
  1899   1899       {
  1900   1900         return UnsafeNativeMethods.sqlite3_column_type(stmt._sqlite_stmt, index);
  1901   1901       }
  1902   1902   
  1903   1903       internal override string ColumnType(SQLiteStatement stmt, int index, ref TypeAffinity nAffinity)
  1904   1904       {
  1905         -      int len;
         1905  +        int len;
  1906   1906   #if !SQLITE_STANDARD
  1907         -      len = 0;
  1908         -      IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype_interop(stmt._sqlite_stmt, index, ref len);
         1907  +        len = 0;
         1908  +        IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype_interop(stmt._sqlite_stmt, index, ref len);
  1909   1909   #else
  1910         -      len = -1;
  1911         -      IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype(stmt._sqlite_stmt, index);
         1910  +        len = -1;
         1911  +        IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype(stmt._sqlite_stmt, index);
  1912   1912   #endif
  1913         -      nAffinity = ColumnAffinity(stmt, index);
         1913  +        nAffinity = ColumnAffinity(stmt, index);
  1914   1914   
  1915         -      if (p != IntPtr.Zero && ((len > 0) || (len == -1))) return UTF8ToString(p, len);
  1916         -      else
  1917         -      {
         1915  +        if ((p != IntPtr.Zero) && ((len > 0) || (len == -1)))
         1916  +        {
         1917  +            string declType = UTF8ToString(p, len);
         1918  +
         1919  +            if (!String.IsNullOrEmpty(declType))
         1920  +                return declType;
         1921  +        }
         1922  +
  1918   1923           string[] ar = stmt.TypeDefinitions;
         1924  +
  1919   1925           if (ar != null)
  1920   1926           {
  1921         -          if (index < ar.Length && ar[index] != null)
  1922         -            return ar[index];
         1927  +            if (index < ar.Length && ar[index] != null)
         1928  +                return ar[index];
  1923   1929           }
         1930  +
  1924   1931           return String.Empty;
  1925         -
  1926         -        //switch (nAffinity)
  1927         -        //{
  1928         -        //  case TypeAffinity.Int64:
  1929         -        //    return "BIGINT";
  1930         -        //  case TypeAffinity.Double:
  1931         -        //    return "DOUBLE";
  1932         -        //  case TypeAffinity.Blob:
  1933         -        //    return "BLOB";
  1934         -        //  default:
  1935         -        //    return "TEXT";
  1936         -        //}
  1937         -      }
  1938   1932       }
  1939   1933   
  1940   1934       internal override int ColumnIndex(SQLiteStatement stmt, string columnName)
  1941   1935       {
  1942   1936         int x = ColumnCount(stmt);
  1943   1937   
  1944   1938         for (int n = 0; n < x; n++)