System.Data.SQLite
Check-in [d8ed5e99ae]
Not logged in

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

Overview
Comment:More work on testability.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | tkt-8d928c3e88
Files: files | file ages | folders
SHA1: d8ed5e99aea5faee6231fe352710dd401a59c20c
User & Date: mistachkin 2015-01-08 17:42:25
Context
2015-01-08
18:57
Add 'AppendManifestToken_SQLiteProviderManifest' environment variable to enable better testing and tighter integration. Complete initial tests. check-in: c42db158c3 user: mistachkin tags: tkt-8d928c3e88
17:42
More work on testability. check-in: d8ed5e99ae user: mistachkin tags: tkt-8d928c3e88
04:55
Work in progress for ticket [8d928c3e88]. These changes are not yet fully tested. check-in: 0b6d0e63ca user: mistachkin tags: tkt-8d928c3e88
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to System.Data.SQLite.Linq/SQL Generation/SqlBuilder.cs.

    97     97             else
    98     98             {
    99     99               ISqlFragment sqlFragment = (o as ISqlFragment);
   100    100               if (null != sqlFragment)
   101    101               {
   102    102                 sqlFragment.WriteSql(writer, sqlGenerator);
   103    103               }
          104  +            else if (o is char)
          105  +            {
          106  +              writer.Write((char)o);
          107  +            }
   104    108               else
   105    109               {
   106    110                 throw new InvalidOperationException();
   107    111               }
   108    112             }
   109    113           }
   110    114         }
   111    115       }
   112    116   
   113    117       #endregion
   114    118     }
   115    119   }

Changes to System.Data.SQLite.Linq/SQL Generation/SqlGenerator.cs.

  3967   3967           //result.Append(".");
  3968   3968           result.Append(QuoteIdentifier(storeFunctionName));
  3969   3969         }
  3970   3970       }
  3971   3971   
  3972   3972       /// <summary>
  3973   3973       /// Appends the literal BLOB string representation of the specified
  3974         -    /// byte array to the <see cref="StringBuilder" />, creating it if
  3975         -    /// necessary.
         3974  +    /// byte array to the <see cref="SqlBuilder" />.
  3976   3975       /// </summary>
  3977   3976       /// <param name="bytes">
  3978   3977       /// The byte array to be formatted as a literal BLOB string.
  3979   3978       /// </param>
  3980   3979       /// <param name="builder">
  3981         -    /// The <see cref="StringBuilder" /> object to use.  If null, a new
  3982         -    /// instance will be created.
         3980  +    /// The <see cref="SqlBuilder" /> object to use.  If null, an exception
         3981  +    /// will be thrown.
  3983   3982       /// </param>
  3984   3983       private static void ToBlobLiteral(
  3985   3984           byte[] bytes,
  3986   3985           SqlBuilder builder
  3987   3986           )
  3988   3987       {
  3989         -        int capacity = (bytes != null) ? (bytes.Length * 2) + 3 : 4;
         3988  +        if (builder == null)
         3989  +            throw new ArgumentNullException("builder");
  3990   3990   
  3991   3991           if (bytes == null)
  3992   3992           {
  3993   3993               builder.Append("NULL"); /* TODO: Reasonable? */
  3994   3994               return;
  3995   3995           }
  3996   3996   

Changes to testlinq/Program.cs.

     2      2    * ADO.NET 2.0 Data Provider for SQLite Version 3.X
     3      3    * Written by Robert Simpson (robert@blackcastlesoft.com)
     4      4    *
     5      5    * Released to the public domain, use at your own risk!
     6      6    ********************************************************/
     7      7   
     8      8   using System;
            9  +using System.Data.Common;
     9     10   using System.Diagnostics;
    10     11   using System.Linq;
           12  +using System.Reflection;
    11     13   using System.Text;
    12     14   using System.Transactions;
    13     15   
    14     16   #if USE_ENTITY_FRAMEWORK_6
           17  +using System.Data.Entity.Core.EntityClient;
    15     18   using System.Data.Entity.Core.Objects;
    16     19   #else
           20  +using System.Data.EntityClient;
    17     21   using System.Data.Objects;
    18     22   #endif
    19     23   
    20     24   namespace testlinq
    21     25   {
    22     26     class Program
    23     27     {
................................................................................
   137    141                 default:
   138    142                     {
   139    143                         Console.WriteLine("unknown test \"{0}\"", arg);
   140    144                         return 1;
   141    145                     }
   142    146             }
   143    147         }
          148  +
          149  +      /// <summary>
          150  +      /// Attempts to obtain the underlying store connection
          151  +      /// (a <see cref="DbConnection" />) from the specified
          152  +      /// <see cref="EntityConnection" />.
          153  +      /// </summary>
          154  +      /// <param name="entityConnection">
          155  +      /// The <see cref="EntityConnection" /> to use.
          156  +      /// </param>
          157  +      /// <returns>
          158  +      /// The <see cref="DbConnection" /> -OR- null if it
          159  +      /// cannot be determined.
          160  +      /// </returns>
          161  +      private static DbConnection GetStoreConnection(
          162  +          EntityConnection entityConnection
          163  +          )
          164  +      {
          165  +          //
          166  +          // NOTE: No entity connection, no store connection.
          167  +          //
          168  +          if (entityConnection == null)
          169  +              return null;
          170  +
          171  +          //
          172  +          // HACK: We need the underlying store connection and
          173  +          //       the legacy versions of the .NET Framework do
          174  +          //       not expose it; therefore, attempt to grab it
          175  +          //       by force.
          176  +          //
          177  +          FieldInfo fieldInfo = typeof(EntityConnection).GetField(
          178  +              "_storeConnection", BindingFlags.Instance |
          179  +              BindingFlags.NonPublic);
          180  +
          181  +          //
          182  +          // NOTE: If the field is not found, just return null.
          183  +          //
          184  +          if (fieldInfo == null)
          185  +              return null;
          186  +
          187  +          return fieldInfo.GetValue(entityConnection) as DbConnection;
          188  +      }
   144    189   
   145    190         //
   146    191         // NOTE: Used to test the fix for ticket [8b7d179c3c].
   147    192         //
   148    193         private static int SkipTest(int pageSize)
   149    194         {
   150    195             using (northwindEFEntities db = new northwindEFEntities())
................................................................................
   489    534         //       of GUID values when the BinaryGUID connection property has been
   490    535         //       enabled).
   491    536         //
   492    537         private static int BinaryGuidTest()
   493    538         {
   494    539             using (northwindEFEntities db = new northwindEFEntities())
   495    540             {
   496         -              string sql = "SELECT VALUE GUID '25334ef0-bd18-43e6-863f-ae5d376ac75e' FROM Orders AS o WHERE o.OrderID = 10248;";
          541  +              DbConnection connection = GetStoreConnection(
          542  +                  db.Connection as EntityConnection);
          543  +
          544  +              string connectionString = connection.ConnectionString;
          545  +
          546  +              connection.ConnectionString = connectionString +
          547  +                  ";BinaryGUID=false;";
          548  +
          549  +              string sql = "SELECT VALUE GUID " +
          550  +                  "'2d3d2d3d-2d3d-2d3d-2d3d-2d3d2d3d2d3d' " +
          551  +                  "FROM Orders AS o WHERE o.OrderID = 10248;";
          552  +
   497    553                 ObjectQuery<string> query = db.CreateQuery<string>(sql);
   498    554   
   499    555                 foreach (string s in query)
   500    556                     Console.WriteLine(s);
   501    557   
   502         -              sql = "SELECT VALUE GUID '25334ef0-bd18-43e6-863f-ae5d376ac75e' FROM Orders AS o WHERE o.OrderID = 10248;";
          558  +              connection.ConnectionString = connectionString +
          559  +                  ";BinaryGUID=true;";
          560  +
          561  +              sql = "SELECT VALUE GUID " +
          562  +                  "'3d2d3d2d-3d2d-3d2d-3d2d-3d2d3d2d3d2d' " +
          563  +                  "FROM Orders AS o WHERE o.OrderID = 10248;";
          564  +
   503    565                 query = db.CreateQuery<string>(sql);
   504    566   
   505    567                 foreach (string s in query)
   506    568                     Console.WriteLine(s);
   507    569             }
   508    570   
   509    571             return 0;