System.Data.SQLite
Check-in [0b55ce3401]
Not logged in

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

Overview
Comment:UTF-16 bugfixes and performance enhancements
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sourceforge
Files: files | file ages | folders
SHA1: 0b55ce340148adab8121db35822f1286b9211ea5
User & Date: rmsimpson 2005-08-06 06:46:09
Context
2005-08-16
19:09
1.0.14 Designer support check-in: f31df8c30b user: rmsimpson tags: sourceforge
2005-08-06
06:46
UTF-16 bugfixes and performance enhancements check-in: 0b55ce3401 user: rmsimpson tags: sourceforge
01:47
1.0.12 repost check-in: 12b3901b7e user: rmsimpson tags: sourceforge
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to SQLite.Interop/interop.h.

   248    248   __declspec(dllexport) const char * __stdcall sqlite3_errmsg_interop(sqlite3 *db, int *plen)
   249    249   {
   250    250     const char *pval = sqlite3_errmsg(db);
   251    251     *plen = (pval != 0) ? strlen(pval) : 0;
   252    252     return pval;
   253    253   }
   254    254   
   255         -__declspec(dllexport) const void * __stdcall sqlite3_errmsg16_interop(sqlite3 *db)
          255  +__declspec(dllexport) const void * __stdcall sqlite3_errmsg16_interop(sqlite3 *db, int *plen)
   256    256   {
   257         -  return sqlite3_errmsg16(db);
          257  +  const void *pval = sqlite3_errmsg16(db);
          258  +  *plen = (pval != 0) ? wcslen((wchar_t *)pval) * sizeof(wchar_t): 0;
          259  +  return pval;
   258    260   }
   259    261   
   260    262   __declspec(dllexport) int __stdcall sqlite3_prepare_interop(sqlite3 *db, const char *sql, int nbytes, sqlite3_stmt **ppstmt, const char **pztail, int *plen)
   261    263   {
   262    264     int n = sqlite3_prepare(db, sql, nbytes, ppstmt, pztail);
   263    265     *plen = (*pztail != 0) ? strlen(*pztail) : 0;
   264    266     return n;
   265    267   }
   266    268   
   267         -__declspec(dllexport) int __stdcall sqlite3_prepare16_interop(sqlite3 *db, const void *sql, int nbytes, sqlite3_stmt **ppstmt, const void **pztail)
          269  +__declspec(dllexport) int __stdcall sqlite3_prepare16_interop(sqlite3 *db, const void *sql, int nbytes, sqlite3_stmt **ppstmt, const void **pztail, int *plen)
   268    270   {
   269         -  return sqlite3_prepare16(db, sql, nbytes, ppstmt, pztail);
          271  +  int n = sqlite3_prepare16(db, sql, nbytes, ppstmt, pztail);
          272  +  *plen = (*pztail != 0) ? wcslen((wchar_t *)*pztail) * sizeof(wchar_t) : 0;
          273  +  return n;
   270    274   }
   271    275   
   272    276   __declspec(dllexport) int __stdcall sqlite3_bind_blob_interop(sqlite3_stmt *stmt, int iCol, const void *pv, int n, void(*cb)(void*))
   273    277   {
   274    278     return sqlite3_bind_blob(stmt, iCol, pv, n, cb);
   275    279   }
   276    280   
................................................................................
   329    333   __declspec(dllexport) const char * __stdcall sqlite3_column_name_interop(sqlite3_stmt *stmt, int iCol, int *plen)
   330    334   {
   331    335     const char *pval = sqlite3_column_name(stmt, iCol);
   332    336     *plen = (pval != 0) ? strlen(pval) : 0;
   333    337     return pval;
   334    338   }
   335    339   
   336         -__declspec(dllexport) const void * __stdcall sqlite3_column_name16_interop(sqlite3_stmt *stmt, int iCol)
          340  +__declspec(dllexport) const void * __stdcall sqlite3_column_name16_interop(sqlite3_stmt *stmt, int iCol, int *plen)
   337    341   {
   338         -  return sqlite3_column_name16(stmt, iCol);
          342  +  const void *pval = sqlite3_column_name16(stmt, iCol);
          343  +  *plen = (pval != 0) ? wcslen((wchar_t *)pval) * sizeof(wchar_t) : 0;
          344  +  return pval;
   339    345   }
   340    346   
   341    347   __declspec(dllexport) const char * __stdcall sqlite3_column_decltype_interop(sqlite3_stmt *stmt, int iCol, int *plen)
   342    348   {
   343    349     const char *pval = sqlite3_column_decltype(stmt, iCol);
   344    350     *plen = (pval != 0) ? strlen(pval) : 0;
   345    351     return pval;
   346    352   }
   347    353   
   348         -__declspec(dllexport) const void * __stdcall sqlite3_column_decltype16_interop(sqlite3_stmt *stmt, int iCol)
          354  +__declspec(dllexport) const void * __stdcall sqlite3_column_decltype16_interop(sqlite3_stmt *stmt, int iCol, int *plen)
   349    355   {
   350         -  return sqlite3_column_decltype16(stmt, iCol);
          356  +  const void *pval = sqlite3_column_decltype16(stmt, iCol);
          357  +  *plen = (pval != 0) ? wcslen((wchar_t *)pval) * sizeof(wchar_t) : 0;
          358  +  return pval;
   351    359   }
   352    360   
   353    361   __declspec(dllexport) int __stdcall sqlite3_step_interop(sqlite3_stmt *stmt)
   354    362   {
   355    363     return sqlite3_step(stmt);
   356    364   }
   357    365   
................................................................................
   393    401   __declspec(dllexport) const unsigned char * __stdcall sqlite3_column_text_interop(sqlite3_stmt *stmt, int iCol, int *plen)
   394    402   {
   395    403     const unsigned char *pval = sqlite3_column_text(stmt, iCol);
   396    404     *plen = (pval != 0) ? strlen((char *)pval) : 0;
   397    405     return pval;
   398    406   }
   399    407   
   400         -__declspec(dllexport) const void * __stdcall sqlite3_column_text16_interop(sqlite3_stmt *stmt, int iCol)
          408  +__declspec(dllexport) const void * __stdcall sqlite3_column_text16_interop(sqlite3_stmt *stmt, int iCol, int *plen)
   401    409   {
   402         -  return sqlite3_column_text16(stmt, iCol);
          410  +  const void *pval = sqlite3_column_text16(stmt, iCol);
          411  +  *plen = (pval != 0) ? wcslen((wchar_t *)pval) * sizeof(wchar_t): 0;
          412  +  return pval;
   403    413   }
   404    414   
   405    415   __declspec(dllexport) int __stdcall sqlite3_column_type_interop(sqlite3_stmt *stmt, int iCol)
   406    416   {
   407    417     return sqlite3_column_type(stmt, iCol);
   408    418   }
   409    419   
................................................................................
   531    541   __declspec(dllexport) const unsigned char * __stdcall sqlite3_value_text_interop(sqlite3_value *val, int *plen)
   532    542   {
   533    543     const unsigned char *pval = sqlite3_value_text(val);
   534    544     *plen = (pval != 0) ? strlen((char *)pval) : 0;
   535    545     return pval;
   536    546   }
   537    547   
   538         -__declspec(dllexport) const void * __stdcall sqlite3_value_text16_interop(sqlite3_value *val)
          548  +__declspec(dllexport) const void * __stdcall sqlite3_value_text16_interop(sqlite3_value *val, int *plen)
   539    549   {
   540         -  return sqlite3_value_text16(val);
          550  +  const void *pval = sqlite3_value_text16(val);
          551  +  *plen = (pval != 0) ? wcslen((wchar_t *)pval) * sizeof(wchar_t) : 0;
          552  +  return pval;
   541    553   }
   542    554   
   543    555   __declspec(dllexport) int __stdcall sqlite3_value_type_interop(sqlite3_value *val)
   544    556   {
   545    557     return sqlite3_value_type(val);
   546    558   }
   547    559   

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

    28     28       /// <returns>A .NET string</returns>
    29     29       public override string ToString(IntPtr b, int nbytelen)
    30     30       {
    31     31         if (nbytelen == 0) return "";
    32     32         return Marshal.PtrToStringUni(b, nbytelen / 2);
    33     33       }
    34     34   
    35         -    /// <summary>
    36         -    /// Another custom string marshaling function
    37         -    /// </summary>
    38         -    /// <param name="b">A pointer to a zero-terminated UTF-16 string</param>
    39         -    /// <returns>A .NET string</returns>
    40         -    internal static string ToString(IntPtr b)
           35  +    internal override string Version
    41     36       {
    42         -      if (b == IntPtr.Zero) return "";
    43         -      return Marshal.PtrToStringUni(b);
           37  +      get
           38  +      {
           39  +        int len;
           40  +        return base.ToString(UnsafeNativeMethods.sqlite3_libversion_interop(out len), len);
           41  +      }
    44     42       }
    45     43   
    46     44       internal override void Open(string strFilename)
    47     45       {
    48     46         if (_sql != 0) return;
    49     47         int n = UnsafeNativeMethods.sqlite3_open16_interop(strFilename, out _sql);
    50     48         if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    51     49   
    52     50         _functionsArray = SQLiteFunction.BindFunctions(this);
    53     51       }
    54     52   
    55     53       internal override string SQLiteLastError()
    56     54       {
    57         -      return ToString(UnsafeNativeMethods.sqlite3_errmsg16_interop(_sql));
           55  +      int len;
           56  +      return ToString(UnsafeNativeMethods.sqlite3_errmsg16_interop(_sql, out len), len);
    58     57       }
    59     58   
    60     59       internal override SQLiteStatement Prepare(string strSql, ref int nParamStart, out string strRemain)
    61     60       {
    62     61         int stmt;
    63     62         IntPtr ptr;
           63  +      int len;
    64     64   
    65         -      int n = UnsafeNativeMethods.sqlite3_prepare16_interop(_sql, strSql, strSql.Length, out stmt, out ptr);
           65  +      int n = UnsafeNativeMethods.sqlite3_prepare16_interop(_sql, strSql, strSql.Length, out stmt, out ptr, out len);
    66     66         if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    67     67   
    68         -      strRemain = ToString(ptr);
           68  +      strRemain = ToString(ptr, len);
    69     69   
    70     70         SQLiteStatement cmd = new SQLiteStatement(this, stmt, strSql.Substring(0, strSql.Length - strRemain.Length), ref nParamStart);
    71     71   
    72     72         return cmd;
    73     73       }
    74     74   
    75     75       internal override void Bind_DateTime(SQLiteStatement stmt, int index, DateTime dt)
    76     76       {
    77     77         Bind_Text(stmt, index, ToString(dt));
    78     78       }
           79  +
           80  +    internal override string Bind_ParamName(SQLiteStatement stmt, int index)
           81  +    {
           82  +      int len;
           83  +      return base.ToString(UnsafeNativeMethods.sqlite3_bind_parameter_name_interop(stmt._sqlite_stmt, index, out len), len);
           84  +    }
    79     85   
    80     86       internal override void Bind_Text(SQLiteStatement stmt, int index, string value)
    81     87       {
    82     88         int n = UnsafeNativeMethods.sqlite3_bind_text16_interop(stmt._sqlite_stmt, index, value, value.Length * 2, -1);
    83     89         if (n > 0) throw new SQLiteException(n, SQLiteLastError());
    84     90       }
    85     91   
    86     92       internal override string ColumnName(SQLiteStatement stmt, int index)
    87     93       {
    88         -      return ToString(UnsafeNativeMethods.sqlite3_column_name16_interop(stmt._sqlite_stmt, index));
           94  +      int len;
           95  +      return ToString(UnsafeNativeMethods.sqlite3_column_name16_interop(stmt._sqlite_stmt, index, out len), len);
    89     96       }
    90     97   
    91     98       internal override DateTime GetDateTime(SQLiteStatement stmt, int index)
    92     99       {
    93    100         return ToDateTime(GetText(stmt, index));
    94    101       }
    95    102       internal override string GetText(SQLiteStatement stmt, int index)
    96    103       {
    97         -      return ToString(UnsafeNativeMethods.sqlite3_column_text16_interop(stmt._sqlite_stmt, index));
          104  +      int len;
          105  +      return ToString(UnsafeNativeMethods.sqlite3_column_text16_interop(stmt._sqlite_stmt, index, out len), len);
    98    106       }
    99    107   
   100    108       internal override string ColumnType(SQLiteStatement stmt, int index, out TypeAffinity nAffinity)
   101    109       {
   102    110         nAffinity = TypeAffinity.None;
          111  +      
          112  +      int len;
          113  +      IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype16_interop(stmt._sqlite_stmt, index, out len);
   103    114   
   104         -      IntPtr p = UnsafeNativeMethods.sqlite3_column_decltype16_interop(stmt._sqlite_stmt, index);
   105         -      if (p != IntPtr.Zero) return ToString(p);
          115  +      if (p != IntPtr.Zero) return ToString(p, len);
   106    116         else
   107    117         {
   108    118           nAffinity = UnsafeNativeMethods.sqlite3_column_type_interop(stmt._sqlite_stmt, index);
   109    119           switch (nAffinity)
   110    120           {
   111    121             case TypeAffinity.Int64:
   112    122               return "BIGINT";
................................................................................
   138    148         if (n > 0) throw new SQLiteException(n, SQLiteLastError());
   139    149   
   140    150         return nCookie;
   141    151       }
   142    152   
   143    153       internal override string GetParamValueText(int ptr)
   144    154       {
   145         -      return ToString(UnsafeNativeMethods.sqlite3_value_text16_interop(ptr));
          155  +      int len;
          156  +      return ToString(UnsafeNativeMethods.sqlite3_value_text16_interop(ptr, out len), len);
   146    157       }
   147    158   
   148    159       internal override void ReturnError(int context, string value)
   149    160       {
   150    161         UnsafeNativeMethods.sqlite3_result_error16_interop(context, value, value.Length);
   151    162       }
   152    163   
   153    164       internal override void ReturnText(int context, string value)
   154    165       {
   155    166         UnsafeNativeMethods.sqlite3_result_text16_interop(context, value, value.Length, -1);
   156    167       }
   157    168     }
   158    169   }

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

   208    208           case DateTimeFormat.Ticks:
   209    209             return new DateTime(Convert.ToInt64(dateText, System.Globalization.CultureInfo.InvariantCulture));
   210    210           default:
   211    211             return DateTime.ParseExact(dateText, _datetimeFormats, System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.None);
   212    212         }
   213    213       }
   214    214   
   215         -    ///// <summary>
   216         -    ///// Attempt to convert the specified string to a datetime value.
   217         -    ///// </summary>
   218         -    ///// <param name="strSrc">The string to parse into a datetime</param>
   219         -    ///// <param name="result">If successful, a valid datetime structure</param>
   220         -    ///// <returns>Returns true if the string was a valid ISO8601 datetime, false otherwise.</returns>
   221         -    //public bool TryToDateTime(string strSrc, out DateTime result)
   222         -    //{
   223         -    //  switch (_datetimeFormat)
   224         -    //  {
   225         -    //    case DateTimeFormat.ISO8601:
   226         -    //      return DateTime.TryParseExact(strSrc, _datetimeFormats, System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.None, out result);
   227         -    //    case DateTimeFormat.Ticks:
   228         -    //      {
   229         -    //        long n;
   230         -    //        if (long.TryParse(strSrc, out n) == true)
   231         -    //        {
   232         -    //          result = new DateTime(n);
   233         -    //          return true;
   234         -    //        }
   235         -    //      }
   236         -    //      break;
   237         -    //  }
   238         -
   239         -    //  result = DateTime.Now;
   240         -    //  return false;
   241         -    //}
   242         -
   243    215       /// <summary>
   244    216       /// Converts a DateTime to a string value, using the current DateTimeFormat specified for the connection when it was opened.
   245    217       /// </summary>
   246    218       /// <param name="dateValue">The DateTime value to convert</param>
   247    219       /// <returns>Either a string consisting of the tick count for DateTimeFormat.Ticks, or a date/time in ISO8601 format.</returns>
   248    220       public string ToString(DateTime dateValue)
   249    221       {
................................................................................
   357    329       /// <param name="t">The SQLiteType to convert</param>
   358    330       /// <returns>Returns a .NET Type object</returns>
   359    331       internal static Type SQLiteTypeToType(SQLiteType t)
   360    332       {
   361    333         if (t.Type != DbType.Object)
   362    334           return SQLiteConvert.DbTypeToType(t.Type);
   363    335   
   364         -      switch (t.Affinity)
   365         -      {
   366         -        case TypeAffinity.Null:
   367         -          return typeof(DBNull);
   368         -        case TypeAffinity.Int64:
   369         -          return typeof(Int64);
   370         -        case TypeAffinity.Double:
   371         -          return typeof(Double);
   372         -        case TypeAffinity.Blob:
   373         -          return typeof(byte[]);
   374         -        default:
   375         -          return typeof(string);
   376         -      }
          336  +      return _typeaffinities[(int)t.Affinity];
   377    337       }
          338  +
          339  +    static Type[] _typeaffinities = {
          340  +      null,
          341  +      typeof(Int64),
          342  +      typeof(Double),
          343  +      typeof(string),
          344  +      typeof(byte[]),
          345  +      typeof(DBNull),
          346  +      null,
          347  +      null,
          348  +      null,
          349  +      null,
          350  +      typeof(DateTime),
          351  +    };
   378    352   
   379    353       /// <summary>
   380    354       /// For a given intrinsic type, return a DbType
   381    355       /// </summary>
   382    356       /// <param name="typ">The native type to convert</param>
   383    357       /// <returns>The corresponding (closest match) DbType</returns>
   384    358       internal static DbType TypeToDbType(Type typ)
   385    359       {
   386         -      switch (Type.GetTypeCode(typ))
          360  +      TypeCode tc = Type.GetTypeCode(typ);
          361  +      if (tc == TypeCode.Object)
   387    362         {
   388         -        case TypeCode.Int16:
   389         -          return DbType.Int16;
   390         -        case TypeCode.Int32:
   391         -          return DbType.Int32;
   392         -        case TypeCode.Int64:
   393         -          return DbType.Int64;
   394         -        case TypeCode.UInt16:
   395         -          return DbType.UInt16;
   396         -        case TypeCode.UInt32:
   397         -          return DbType.UInt32;
   398         -        case TypeCode.UInt64:
   399         -          return DbType.UInt64;
   400         -        case TypeCode.Double:
   401         -          return DbType.Double;
   402         -        case TypeCode.Single:
   403         -          return DbType.Single;
   404         -        case TypeCode.Decimal:
   405         -          return DbType.Decimal;
   406         -        case TypeCode.Boolean:
   407         -          return DbType.Boolean;
   408         -        case TypeCode.SByte:
   409         -        case TypeCode.Char:
   410         -          return DbType.SByte;
   411         -        case TypeCode.DateTime:
   412         -          return DbType.DateTime;
   413         -        case TypeCode.String:
   414         -          return DbType.String;
   415         -        case TypeCode.Object:
   416         -          if (typ == typeof(byte[])) return DbType.Binary;
   417         -          if (typ == typeof(Guid)) return DbType.Guid;
   418         -          return DbType.String;
          363  +        if (typ == typeof(byte[])) return DbType.Binary;
          364  +        if (typ == typeof(Guid)) return DbType.Guid;
          365  +        return DbType.String;
   419    366         }
          367  +      return _typetodbtype[(int)tc];
          368  +    }
   420    369   
   421         -      return DbType.String;
   422         -    }
          370  +    private static DbType[] _typetodbtype = {
          371  +      DbType.Object,
          372  +      DbType.Binary,
          373  +      DbType.Object,
          374  +      DbType.Boolean,
          375  +      DbType.SByte,
          376  +      DbType.SByte,
          377  +      DbType.Byte,
          378  +      DbType.Int16, // 7
          379  +      DbType.UInt16,
          380  +      DbType.Int32,
          381  +      DbType.UInt32,
          382  +      DbType.Int64, // 11
          383  +      DbType.UInt64,
          384  +      DbType.Single,
          385  +      DbType.Double,
          386  +      DbType.Decimal,
          387  +      DbType.DateTime,
          388  +      DbType.Object,
          389  +      DbType.String,
          390  +    };
   423    391   
   424    392       /// <summary>
   425    393       /// Convert a DbType to a Type
   426    394       /// </summary>
   427    395       /// <param name="typ">The DbType to convert from</param>
   428    396       /// <returns>The closest-match .NET type</returns>
   429    397       internal static Type DbTypeToType(DbType typ)
   430    398       {
   431         -      switch (typ)
   432         -      {
   433         -        case DbType.Binary:
   434         -          return typeof(byte[]);
   435         -        case DbType.Boolean:
   436         -          return typeof(bool);
   437         -        case DbType.Byte:
   438         -          return typeof(byte);
   439         -        case DbType.Currency:
   440         -        case DbType.Decimal:
   441         -          return typeof(decimal);
   442         -        case DbType.DateTime:
   443         -          return typeof(DateTime);
   444         -        case DbType.Double:
   445         -          return typeof(double);
   446         -        case DbType.Guid:
   447         -          return typeof(Guid);
   448         -        case DbType.Int16:
   449         -        case DbType.UInt16:
   450         -          return typeof(Int16);
   451         -        case DbType.Int32:
   452         -        case DbType.UInt32:
   453         -          return typeof(Int32);
   454         -        case DbType.Int64:
   455         -        case DbType.UInt64:
   456         -          return typeof(Int64);
   457         -        case DbType.String:
   458         -          return typeof(string);
   459         -        case DbType.SByte:
   460         -          return typeof(char);
   461         -        case DbType.Single:
   462         -          return typeof(float);
   463         -      }
   464         -      return typeof(string);
          399  +      return _dbtypeToType[(int)typ];
   465    400       }
          401  +
          402  +    private static Type[] _dbtypeToType = {
          403  +      typeof(string),   // 0
          404  +      typeof(byte[]),   // 1
          405  +      typeof(byte),     // 2
          406  +      typeof(bool),     // 3
          407  +      typeof(decimal),  // 4
          408  +      typeof(DateTime), // 5
          409  +      typeof(DateTime), // 6
          410  +      typeof(decimal),  // 7
          411  +      typeof(double),   // 8
          412  +      typeof(Guid),     // 9
          413  +      typeof(Int16),
          414  +      typeof(Int32),
          415  +      typeof(Int64),
          416  +      typeof(object),
          417  +      typeof(sbyte),
          418  +      typeof(float),
          419  +      typeof(string),
          420  +      typeof(DateTime),
          421  +      typeof(UInt16),
          422  +      typeof(UInt32),
          423  +      typeof(UInt64),
          424  +      typeof(double),
          425  +      typeof(string),
          426  +      typeof(string),
          427  +      typeof(string),
          428  +      typeof(string),   // 25 (Xml)
          429  +    };
   466    430   
   467    431       /// <summary>
   468    432       /// For a given type, return the closest-match SQLite TypeAffinity, which only understands a very limited subset of types.
   469    433       /// </summary>
   470    434       /// <param name="typ">The type to evaluate</param>
   471    435       /// <returns>The SQLite type affinity for that type.</returns>
   472    436       internal static TypeAffinity TypeToAffinity(Type typ)
   473    437       {
   474         -      switch (Type.GetTypeCode(typ))
          438  +      TypeCode tc = Type.GetTypeCode(typ);
          439  +      if (tc == TypeCode.Object)
   475    440         {
   476         -        case TypeCode.DBNull:
   477         -          return TypeAffinity.Null;
   478         -        case TypeCode.String:
          441  +        if (typ == typeof(byte[]))
          442  +          return TypeAffinity.Blob;
          443  +        else
   479    444             return TypeAffinity.Text;
   480         -        case TypeCode.DateTime:
   481         -          return TypeAffinity.DateTime;
   482         -        case TypeCode.Int16:
   483         -        case TypeCode.Int32:
   484         -        case TypeCode.Int64:
   485         -        case TypeCode.UInt16:
   486         -        case TypeCode.UInt32:
   487         -        case TypeCode.UInt64:
   488         -        case TypeCode.Char:
   489         -        case TypeCode.SByte:
   490         -        case TypeCode.Byte:
   491         -        case TypeCode.Boolean:
   492         -          return TypeAffinity.Int64;
   493         -        case TypeCode.Double:
   494         -        case TypeCode.Single:
   495         -        case TypeCode.Decimal:
   496         -          return TypeAffinity.Double;
   497         -        case TypeCode.Object:
   498         -          if (typ == typeof(byte[])) return TypeAffinity.Blob;
   499         -          else return TypeAffinity.Text;
   500    445         }
   501         -      return TypeAffinity.Text;
          446  +      return _typecodeAffinities[(int)tc];
   502    447       }
          448  +
          449  +    private static TypeAffinity[] _typecodeAffinities = {
          450  +      TypeAffinity.Null,
          451  +      TypeAffinity.Blob,
          452  +      TypeAffinity.Null,
          453  +      TypeAffinity.Int64,
          454  +      TypeAffinity.Int64,
          455  +      TypeAffinity.Int64,
          456  +      TypeAffinity.Int64,
          457  +      TypeAffinity.Int64, // 7
          458  +      TypeAffinity.Int64,
          459  +      TypeAffinity.Int64,
          460  +      TypeAffinity.Int64,
          461  +      TypeAffinity.Int64, // 11
          462  +      TypeAffinity.Int64,
          463  +      TypeAffinity.Double,
          464  +      TypeAffinity.Double,
          465  +      TypeAffinity.Double,
          466  +      TypeAffinity.DateTime,
          467  +      TypeAffinity.Null,
          468  +      TypeAffinity.Text,
          469  +    };
   503    470   
   504    471       /// <summary>
   505    472       /// For a given type name, return a closest-match .NET type
   506    473       /// </summary>
   507    474       /// <param name="Name">The name of the type to match</param>
   508    475       /// <returns>The .NET DBType the text evaluates to.</returns>
   509    476       internal static DbType TypeNameToDbType(string Name)

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

   182    182       [DllImport(SQLITE_DLL)]
   183    183       internal static extern int sqlite3_aggregate_context_interop(int context, int nBytes);
   184    184   
   185    185       [DllImport(SQLITE_DLL)]
   186    186       internal static extern void sqlite3_realcolnames(int db, int bset);
   187    187   
   188    188       [DllImport(SQLITE_DLL)]
   189         -    internal static extern IntPtr sqlite3_column_text16_interop(int stmt, int index);
          189  +    internal static extern IntPtr sqlite3_column_text16_interop(int stmt, int index, out int len);
   190    190   
   191    191       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   192    192       internal static extern int sqlite3_open16_interop(string utf16Filename, out int db);
   193    193   
   194    194       [DllImport(SQLITE_DLL)]
   195         -    internal static extern IntPtr sqlite3_errmsg16_interop(int db);
          195  +    internal static extern IntPtr sqlite3_errmsg16_interop(int db, out int len);
   196    196   
   197    197       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   198         -    internal static extern int sqlite3_prepare16_interop(int db, string strSql, int sqlLen, out int stmt, out IntPtr ptrRemain);
          198  +    internal static extern int sqlite3_prepare16_interop(int db, string strSql, int sqlLen, out int stmt, out IntPtr ptrRemain, out int len);
   199    199   
   200    200       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   201    201       internal static extern int sqlite3_bind_text16_interop(int stmt, int index, string value, int nlen, int nTransient);
   202    202   
   203    203       [DllImport(SQLITE_DLL)]
   204         -    internal static extern IntPtr sqlite3_column_name16_interop(int stmt, int index);
          204  +    internal static extern IntPtr sqlite3_column_name16_interop(int stmt, int index, out int len);
   205    205   
   206    206       [DllImport(SQLITE_DLL)]
   207         -    internal static extern IntPtr sqlite3_column_decltype16_interop(int stmt, int index);
          207  +    internal static extern IntPtr sqlite3_column_decltype16_interop(int stmt, int index, out int len);
   208    208   
   209    209       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   210    210       internal static extern int sqlite3_create_collation16_interop(int db, string strName, int nType, int nArgs, SQLiteCollation func, out int nCookie);
   211    211   
   212    212       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   213    213       internal static extern int sqlite3_create_function16_interop(int db, string strName, int nArgs, int nType, SQLiteCallback func, SQLiteCallback funcstep, SQLiteCallback funcfinal, out int nCookie);
   214    214   
   215    215       [DllImport(SQLITE_DLL)]
   216         -    internal static extern IntPtr sqlite3_value_text16_interop(int p);
          216  +    internal static extern IntPtr sqlite3_value_text16_interop(int p, out int len);
   217    217   
   218    218       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   219    219       internal static extern void sqlite3_result_error16_interop(int context, string strName, int nLen);
   220    220   
   221    221       [DllImport(SQLITE_DLL, CharSet = CharSet.Unicode)]
   222    222       internal static extern void sqlite3_result_text16_interop(int context, string strName, int nLen, int pvReserved);
   223    223     }
   224    224   }