System.Data.SQLite

Check-in [d8ed5e99ae]
Login

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

Overview
Comment:More work on testability.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | tkt-8d928c3e88
Files: files | file ages | folders
SHA1: d8ed5e99aea5faee6231fe352710dd401a59c20c
User & Date: mistachkin 2015-01-08 17:42:25.799
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
Unified Diff Ignore Whitespace Patch
Changes to System.Data.SQLite.Linq/SQL Generation/SqlBuilder.cs.
97
98
99
100
101
102
103




104
105
106
107
108
109
110
          else
          {
            ISqlFragment sqlFragment = (o as ISqlFragment);
            if (null != sqlFragment)
            {
              sqlFragment.WriteSql(writer, sqlGenerator);
            }




            else
            {
              throw new InvalidOperationException();
            }
          }
        }
      }







>
>
>
>







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
          else
          {
            ISqlFragment sqlFragment = (o as ISqlFragment);
            if (null != sqlFragment)
            {
              sqlFragment.WriteSql(writer, sqlGenerator);
            }
            else if (o is char)
            {
              writer.Write((char)o);
            }
            else
            {
              throw new InvalidOperationException();
            }
          }
        }
      }
Changes to System.Data.SQLite.Linq/SQL Generation/SqlGenerator.cs.
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989

3990
3991
3992
3993
3994
3995
3996
        //result.Append(".");
        result.Append(QuoteIdentifier(storeFunctionName));
      }
    }

    /// <summary>
    /// Appends the literal BLOB string representation of the specified
    /// byte array to the <see cref="StringBuilder" />, creating it if
    /// necessary.
    /// </summary>
    /// <param name="bytes">
    /// The byte array to be formatted as a literal BLOB string.
    /// </param>
    /// <param name="builder">
    /// The <see cref="StringBuilder" /> object to use.  If null, a new
    /// instance will be created.
    /// </param>
    private static void ToBlobLiteral(
        byte[] bytes,
        SqlBuilder builder
        )
    {
        int capacity = (bytes != null) ? (bytes.Length * 2) + 3 : 4;


        if (bytes == null)
        {
            builder.Append("NULL"); /* TODO: Reasonable? */
            return;
        }








|
<





|
|






|
>







3967
3968
3969
3970
3971
3972
3973
3974

3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
        //result.Append(".");
        result.Append(QuoteIdentifier(storeFunctionName));
      }
    }

    /// <summary>
    /// Appends the literal BLOB string representation of the specified
    /// byte array to the <see cref="SqlBuilder" />.

    /// </summary>
    /// <param name="bytes">
    /// The byte array to be formatted as a literal BLOB string.
    /// </param>
    /// <param name="builder">
    /// The <see cref="SqlBuilder" /> object to use.  If null, an exception
    /// will be thrown.
    /// </param>
    private static void ToBlobLiteral(
        byte[] bytes,
        SqlBuilder builder
        )
    {
        if (builder == null)
            throw new ArgumentNullException("builder");

        if (bytes == null)
        {
            builder.Append("NULL"); /* TODO: Reasonable? */
            return;
        }

Changes to testlinq/Program.cs.
1
2
3
4
5
6
7
8

9
10

11
12
13
14

15
16

17
18
19
20
21
22
23
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

using System;

using System.Diagnostics;
using System.Linq;

using System.Text;
using System.Transactions;

#if USE_ENTITY_FRAMEWORK_6

using System.Data.Entity.Core.Objects;
#else

using System.Data.Objects;
#endif

namespace testlinq
{
  class Program
  {








>


>




>


>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

using System;
using System.Data.Common;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Transactions;

#if USE_ENTITY_FRAMEWORK_6
using System.Data.Entity.Core.EntityClient;
using System.Data.Entity.Core.Objects;
#else
using System.Data.EntityClient;
using System.Data.Objects;
#endif

namespace testlinq
{
  class Program
  {
137
138
139
140
141
142
143









































144
145
146
147
148
149
150
              default:
                  {
                      Console.WriteLine("unknown test \"{0}\"", arg);
                      return 1;
                  }
          }
      }










































      //
      // NOTE: Used to test the fix for ticket [8b7d179c3c].
      //
      private static int SkipTest(int pageSize)
      {
          using (northwindEFEntities db = new northwindEFEntities())







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
              default:
                  {
                      Console.WriteLine("unknown test \"{0}\"", arg);
                      return 1;
                  }
          }
      }

      /// <summary>
      /// Attempts to obtain the underlying store connection
      /// (a <see cref="DbConnection" />) from the specified
      /// <see cref="EntityConnection" />.
      /// </summary>
      /// <param name="entityConnection">
      /// The <see cref="EntityConnection" /> to use.
      /// </param>
      /// <returns>
      /// The <see cref="DbConnection" /> -OR- null if it
      /// cannot be determined.
      /// </returns>
      private static DbConnection GetStoreConnection(
          EntityConnection entityConnection
          )
      {
          //
          // NOTE: No entity connection, no store connection.
          //
          if (entityConnection == null)
              return null;

          //
          // HACK: We need the underlying store connection and
          //       the legacy versions of the .NET Framework do
          //       not expose it; therefore, attempt to grab it
          //       by force.
          //
          FieldInfo fieldInfo = typeof(EntityConnection).GetField(
              "_storeConnection", BindingFlags.Instance |
              BindingFlags.NonPublic);

          //
          // NOTE: If the field is not found, just return null.
          //
          if (fieldInfo == null)
              return null;

          return fieldInfo.GetValue(entityConnection) as DbConnection;
      }

      //
      // NOTE: Used to test the fix for ticket [8b7d179c3c].
      //
      private static int SkipTest(int pageSize)
      {
          using (northwindEFEntities db = new northwindEFEntities())
489
490
491
492
493
494
495








496



497
498
499
500
501





502

503
504
505
506
507
508
509
      //       of GUID values when the BinaryGUID connection property has been
      //       enabled).
      //
      private static int BinaryGuidTest()
      {
          using (northwindEFEntities db = new northwindEFEntities())
          {








              string sql = "SELECT VALUE GUID '25334ef0-bd18-43e6-863f-ae5d376ac75e' FROM Orders AS o WHERE o.OrderID = 10248;";



              ObjectQuery<string> query = db.CreateQuery<string>(sql);

              foreach (string s in query)
                  Console.WriteLine(s);






              sql = "SELECT VALUE GUID '25334ef0-bd18-43e6-863f-ae5d376ac75e' FROM Orders AS o WHERE o.OrderID = 10248;";

              query = db.CreateQuery<string>(sql);

              foreach (string s in query)
                  Console.WriteLine(s);
          }

          return 0;







>
>
>
>
>
>
>
>
|
>
>
>





>
>
>
>
>
|
>







534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
      //       of GUID values when the BinaryGUID connection property has been
      //       enabled).
      //
      private static int BinaryGuidTest()
      {
          using (northwindEFEntities db = new northwindEFEntities())
          {
              DbConnection connection = GetStoreConnection(
                  db.Connection as EntityConnection);

              string connectionString = connection.ConnectionString;

              connection.ConnectionString = connectionString +
                  ";BinaryGUID=false;";

              string sql = "SELECT VALUE GUID " +
                  "'2d3d2d3d-2d3d-2d3d-2d3d-2d3d2d3d2d3d' " +
                  "FROM Orders AS o WHERE o.OrderID = 10248;";

              ObjectQuery<string> query = db.CreateQuery<string>(sql);

              foreach (string s in query)
                  Console.WriteLine(s);

              connection.ConnectionString = connectionString +
                  ";BinaryGUID=true;";

              sql = "SELECT VALUE GUID " +
                  "'3d2d3d2d-3d2d-3d2d-3d2d-3d2d3d2d3d2d' " +
                  "FROM Orders AS o WHERE o.OrderID = 10248;";

              query = db.CreateQuery<string>(sql);

              foreach (string s in query)
                  Console.WriteLine(s);
          }

          return 0;