System.Data.SQLite

Check-in [c43018f34e]
Login

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

Overview
Comment:More work on getting the design-time components to detect and use the EF6 enabled provider. Cherrypick of [30c1589da7] (check-in on wrong branch).
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c43018f34e4939182aeb3f25f7ff7b4aa35427e3
User & Date: mistachkin 2014-09-04 18:32:53.700
Context
2014-09-04
18:42
Fix for previous check-in: missed one place where the default provider should be EF6 enabled. check-in: 8d98582107 user: mistachkin tags: trunk
18:33
Merge updates from trunk. check-in: 0622da663d user: mistachkin tags: nugetChanges
18:32
More work on getting the design-time components to detect and use the EF6 enabled provider. Cherrypick of [30c1589da7] (check-in on wrong branch). check-in: c43018f34e user: mistachkin tags: trunk
18:31
Update imported SQLite core library documentation. check-in: 8e13c43294 user: mistachkin tags: trunk
17:45
More work on getting the design-time components to detect and use the EF6 enabled provider. check-in: 30c1589da7 user: mistachkin tags: nugetChanges
Changes
Unified Diff Ignore Whitespace Patch
Changes to SQLite.Designer/SQLiteDataAdapterToolboxItem.cs.
59
60
61
62
63
64
65

66
67


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

114
115
116
117
118
119
120
121
    /// <summary>
    /// Creates the necessary components associated with this data adapter instance
    /// </summary>
    /// <param name="host">The designer host</param>
    /// <returns>The components created by this toolbox item</returns>
    protected override IComponent[] CreateComponentsCore(IDesignerHost host)
    {

      DbProviderFactory fact = DbProviderFactories.GetFactory(SQLiteOptions.GetProviderName());



      DbDataAdapter dataAdapter = fact.CreateDataAdapter();
      IContainer container = host.Container;
      
      using (DbCommand adapterCommand = fact.CreateCommand())
      {
        ICloneable adapter = (ICloneable)adapterCommand;

        adapterCommand.DesignTimeVisible = false;
        dataAdapter.SelectCommand = (DbCommand)adapter.Clone();
        container.Add(dataAdapter.SelectCommand, GenerateName(container, "SelectCommand"));

        dataAdapter.InsertCommand = (DbCommand)adapter.Clone();
        container.Add(dataAdapter.InsertCommand, GenerateName(container, "InsertCommand"));

        dataAdapter.UpdateCommand = (DbCommand)adapter.Clone();
        container.Add(dataAdapter.UpdateCommand, GenerateName(container, "UpdateCommand"));

        dataAdapter.DeleteCommand = (DbCommand)adapter.Clone();
        container.Add(dataAdapter.DeleteCommand, GenerateName(container, "DeleteCommand"));
      }

      ITypeResolutionService typeResService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
      if (typeResService != null)
      {
        typeResService.ReferenceAssembly(dataAdapter.GetType().Assembly.GetName());
      }

      container.Add(dataAdapter);

      List<IComponent> list = new List<IComponent>();
      list.Add(dataAdapter);

      // Show the connection wizard if we have a type for it
      if (_wizard != null)
      {
        using (Form wizard = (Form)Activator.CreateInstance(_wizard, new object[] { host, dataAdapter }))
        {
          wizard.ShowDialog();
        }
      }

      if (dataAdapter.SelectCommand != null) list.Add(dataAdapter.SelectCommand);
      if (dataAdapter.InsertCommand != null) list.Add(dataAdapter.InsertCommand);
      if (dataAdapter.DeleteCommand != null) list.Add(dataAdapter.DeleteCommand);
      if (dataAdapter.UpdateCommand != null) list.Add(dataAdapter.UpdateCommand);


      return list.ToArray();      
    }

    /// <summary>
    /// Generates a unique name for the given object
    /// </summary>
    /// <param name="container">The container where we're being instantiated</param>
    /// <param name="baseName">The core name of the object to create a unique instance of</param>







>
|

>
>
|
|
|
|
|
|

|
|
|

|
|

|
|

|
|
|

|
|
|
|
|

|

<
|

|
|
|
|
|
|
|
|

|
|
|
|
|
>
|







59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
    /// <summary>
    /// Creates the necessary components associated with this data adapter instance
    /// </summary>
    /// <param name="host">The designer host</param>
    /// <returns>The components created by this toolbox item</returns>
    protected override IComponent[] CreateComponentsCore(IDesignerHost host)
    {
        List<IComponent> list = new List<IComponent>();
        DbProviderFactory fact;

        if (SQLiteOptions.GetProviderFactory(SQLiteOptions.GetProviderName(), true, out fact))
        {
            DbDataAdapter dataAdapter = fact.CreateDataAdapter();
            IContainer container = host.Container;

            using (DbCommand adapterCommand = fact.CreateCommand())
            {
                ICloneable adapter = (ICloneable)adapterCommand;

                adapterCommand.DesignTimeVisible = false;
                dataAdapter.SelectCommand = (DbCommand)adapter.Clone();
                container.Add(dataAdapter.SelectCommand, GenerateName(container, "SelectCommand"));

                dataAdapter.InsertCommand = (DbCommand)adapter.Clone();
                container.Add(dataAdapter.InsertCommand, GenerateName(container, "InsertCommand"));

                dataAdapter.UpdateCommand = (DbCommand)adapter.Clone();
                container.Add(dataAdapter.UpdateCommand, GenerateName(container, "UpdateCommand"));

                dataAdapter.DeleteCommand = (DbCommand)adapter.Clone();
                container.Add(dataAdapter.DeleteCommand, GenerateName(container, "DeleteCommand"));
            }

            ITypeResolutionService typeResService = (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));
            if (typeResService != null)
            {
                typeResService.ReferenceAssembly(dataAdapter.GetType().Assembly.GetName());
            }

            container.Add(dataAdapter);


            list.Add(dataAdapter);

            // Show the connection wizard if we have a type for it
            if (_wizard != null)
            {
                using (Form wizard = (Form)Activator.CreateInstance(_wizard, new object[] { host, dataAdapter }))
                {
                    wizard.ShowDialog();
                }
            }

            if (dataAdapter.SelectCommand != null) list.Add(dataAdapter.SelectCommand);
            if (dataAdapter.InsertCommand != null) list.Add(dataAdapter.InsertCommand);
            if (dataAdapter.DeleteCommand != null) list.Add(dataAdapter.DeleteCommand);
            if (dataAdapter.UpdateCommand != null) list.Add(dataAdapter.UpdateCommand);
        }

        return list.ToArray();
    }

    /// <summary>
    /// Generates a unique name for the given object
    /// </summary>
    /// <param name="container">The container where we're being instantiated</param>
    /// <param name="baseName">The core name of the object to create a unique instance of</param>
Changes to SQLite.Designer/SQLiteOptions.cs.
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80







81
82
83
84
85
86
87
        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// This is the legacy provider name used by the System.Data.SQLite
        /// design-time components.  It is also the default value for the
        /// associated option key.
        /// </summary>
        private static readonly string DefaultProviderName = "System.Data.SQLite";

        ///////////////////////////////////////////////////////////////////////

#if NET_40 || NET_45 || NET_451
        /// <summary>
        /// This is the provider name used when Entity Framework 6.x support is
        /// required for use with the System.Data.SQLite design-time components.
        /// This provider name is only available when this class is compiled for
        /// the .NET Framework 4.0 or later.
        /// </summary>
        private static readonly string Ef6ProviderName = "System.Data.SQLite.EF6";
#endif
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Static Data
        /// <summary>
        /// This is used to synchronize access to the static dictionary of
        /// options (just below).
        /// </summary>
        private static readonly object syncRoot = new object();

        /// <summary>
        /// This dictionary contains the key/value pairs representing the
        /// per-solution options configured for the current solution.  When
        /// a new solution is loaded by Visual Studio, this dictionary must
        /// be reset.
        /// </summary>
        private static Dictionary<string, string> options;







        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Static Methods
        /// <summary>
        /// This method initializes (or resets) the per-solution configuration







|



















|










>
>
>
>
>
>
>







43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// This is the legacy provider name used by the System.Data.SQLite
        /// design-time components.  It is also the default value for the
        /// associated option key.
        /// </summary>
        private static readonly string LegacyProviderName = "System.Data.SQLite";

        ///////////////////////////////////////////////////////////////////////

#if NET_40 || NET_45 || NET_451
        /// <summary>
        /// This is the provider name used when Entity Framework 6.x support is
        /// required for use with the System.Data.SQLite design-time components.
        /// This provider name is only available when this class is compiled for
        /// the .NET Framework 4.0 or later.
        /// </summary>
        private static readonly string Ef6ProviderName = "System.Data.SQLite.EF6";
#endif
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Static Data
        /// <summary>
        /// This is used to synchronize access to the static dictionary of
        /// options and <see cref="DbProviderFactory" /> objects.
        /// </summary>
        private static readonly object syncRoot = new object();

        /// <summary>
        /// This dictionary contains the key/value pairs representing the
        /// per-solution options configured for the current solution.  When
        /// a new solution is loaded by Visual Studio, this dictionary must
        /// be reset.
        /// </summary>
        private static Dictionary<string, string> options;

        /// <summary>
        /// This dictionary contains the <see cref="DbProviderFactory" />
        /// objects cached by this class.
        /// </summary>
        private static Dictionary<string, DbProviderFactory>
            dbProviderFactories;
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Private Static Methods
        /// <summary>
        /// This method initializes (or resets) the per-solution configuration
105
106
107
108
109
110
111

112
113

114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

                string key = ProviderNameKey;
                string value = Environment.GetEnvironmentVariable(
                    ProviderNameEnvVarName);

                if (IsValidValue(key, value))
                    options[key] = value;

                else
                    options[key] = DefaultProviderName;

            }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Public Static Methods
        #region Provider Name Handling
        /// <summary>
        /// This method determines the name of the ADO.NET provider for the
        /// System.Data.SQLite design-time components to use.
        /// </summary>
        /// <returns>
        /// The configured ADO.NET provider name for System.Data.SQLite -OR-
        /// the default ADO.NET provider name for System.Data.SQLite in the
        /// event of any failure.  This method cannot return null.
        /// </returns>
        public static string GetProviderName()
        {
            return GetProviderName(DefaultProviderName);
        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// This method determines the name of the ADO.NET provider for the
        /// System.Data.SQLite design-time components to use.
        /// </summary>
        /// <param name="default">
        /// The value to return from this method if the name of the ADO.NET
        /// provider is unavailable -OR- cannot be determined.
        /// </param>
        /// <returns>
        /// The configured ADO.NET provider name for System.Data.SQLite -OR-
        /// the default ADO.NET provider name for System.Data.SQLite in the
        /// event of any failure.
        /// </returns>
        private static string GetProviderName(







>

|
>



















|










|







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160

                string key = ProviderNameKey;
                string value = Environment.GetEnvironmentVariable(
                    ProviderNameEnvVarName);

                if (IsValidValue(key, value))
                    options[key] = value;
#if !NET_40 && !NET_45 && !NET_451
                else
                    options[key] = LegacyProviderName;
#endif
            }
        }
        #endregion

        ///////////////////////////////////////////////////////////////////////

        #region Public Static Methods
        #region Provider Name Handling
        /// <summary>
        /// This method determines the name of the ADO.NET provider for the
        /// System.Data.SQLite design-time components to use.
        /// </summary>
        /// <returns>
        /// The configured ADO.NET provider name for System.Data.SQLite -OR-
        /// the default ADO.NET provider name for System.Data.SQLite in the
        /// event of any failure.  This method cannot return null.
        /// </returns>
        public static string GetProviderName()
        {
            return GetProviderName(LegacyProviderName);
        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// This method determines the name of the ADO.NET provider for the
        /// System.Data.SQLite design-time components to use.
        /// </summary>
        /// <param name="default">
        /// The value to return from this method if the name of the ADO.NET
        /// provider is unavailable or cannot be determined.
        /// </param>
        /// <returns>
        /// The configured ADO.NET provider name for System.Data.SQLite -OR-
        /// the default ADO.NET provider name for System.Data.SQLite in the
        /// event of any failure.
        /// </returns>
        private static string GetProviderName(
226
227
228
229
230
231
232












233
234
235
236
237
238























































239
240
241



242
243


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
            }

            return false;
        }

        ///////////////////////////////////////////////////////////////////////













        private static bool CheckProviderName(
            string name
            )
        {
            DbProviderFactory dbProviderFactory = null;
























































            try
            {
                dbProviderFactory = DbProviderFactories.GetFactory(



                    name); /* throw */



                return (dbProviderFactory != null);
            }
            catch
            {
                // do nothing.
            }
            finally
            {
                if (dbProviderFactory != null)
                {
                    IDisposable disposable = dbProviderFactory as IDisposable;

                    if (disposable != null)
                    {
                        disposable.Dispose();
                        disposable = null;
                    }

                    dbProviderFactory = null;
                }
            }

            return false;
        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// This method populates the specified <see cref="ComboBox" /> item
        /// list with the recognized ADO.NET provider names.  This method will







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




|

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


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326





















327
328
329
330
331
332
333
            }

            return false;
        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Determines if the specified ADO.NET provider name appears to be
        /// usable.
        /// </summary>
        /// <param name="name">
        /// The invariant name of the ADO.NET provider to create.  Using null
        /// or an empty string will cause this method to return false.
        /// </param>
        /// <returns>
        /// Non-zero if the <see cref="DbProviderFactory" /> was created or
        /// queried successfully; otherwise, zero.
        /// </returns>
        private static bool CheckProviderName(
            string name
            )
        {
            DbProviderFactory dbProviderFactory; /* NOT USED */

            return GetProviderFactory(name, true, out dbProviderFactory);
        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Gets the cached <see cref="DbProviderFactory" /> object associated
        /// with the specified name, creating a new instance if necessary.
        /// </summary>
        /// <param name="name">
        /// The invariant name of the ADO.NET provider to create.  Using null
        /// or an empty string will cause this method to return false.
        /// </param>
        /// <param name="create">
        /// Non-zero to create a new instance of the ADO.NET provider, if
        /// necessary.
        /// </param>
        /// <param name="dbProviderFactory">
        /// The newly created <see cref="DbProviderFactory" /> object or null
        /// if it is unavailable or could not be created.
        /// </param>
        /// <returns>
        /// Non-zero if the <see cref="DbProviderFactory" /> was created or
        /// queried successfully; otherwise, zero.
        /// </returns>
        public static bool GetProviderFactory(
            string name,
            bool create,
            out DbProviderFactory dbProviderFactory
            )
        {
            lock (syncRoot)
            {
                dbProviderFactory = null;

                if (dbProviderFactories == null)
                {
                    dbProviderFactories =
                        new Dictionary<string, DbProviderFactory>();
                }

                if (String.IsNullOrEmpty(name))
                    return false;

                if (dbProviderFactories.TryGetValue(
                        name, out dbProviderFactory))
                {
                    return (dbProviderFactory != null);
                }

                if (!create)
                    return false;

                dbProviderFactory = null; /* NOTE: Pedantic. */

                try
                {
                    dbProviderFactory = DbProviderFactories.GetFactory(name);
                }
                catch
                {
                    // do nothing.
                }

                dbProviderFactories.Add(name, dbProviderFactory);
                return (dbProviderFactory != null);
            }





















        }

        ///////////////////////////////////////////////////////////////////////

        /// <summary>
        /// This method populates the specified <see cref="ComboBox" /> item
        /// list with the recognized ADO.NET provider names.  This method will
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305

            IList<string> names = new List<string>();

#if NET_40 || NET_45 || NET_451
            names.Add(Ef6ProviderName);
#endif

            names.Add(DefaultProviderName);

            foreach (string name in names)
            {
                if (CheckProviderName(name))
                {
                    items.Add(name);
                    result++;







|







351
352
353
354
355
356
357
358
359
360
361
362
363
364
365

            IList<string> names = new List<string>();

#if NET_40 || NET_45 || NET_451
            names.Add(Ef6ProviderName);
#endif

            names.Add(LegacyProviderName);

            foreach (string name in names)
            {
                if (CheckProviderName(name))
                {
                    items.Add(name);
                    result++;
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
            string key,
            string value
            )
        {
            if (String.Equals(
                    key, ProviderNameKey, StringComparison.Ordinal) &&
                String.Equals(
                    value, DefaultProviderName, StringComparison.Ordinal))
            {
                return true;
            }

            return false;
        }








|







391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
            string key,
            string value
            )
        {
            if (String.Equals(
                    key, ProviderNameKey, StringComparison.Ordinal) &&
                String.Equals(
                    value, LegacyProviderName, StringComparison.Ordinal))
            {
                return true;
            }

            return false;
        }

363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
            string key,
            string value
            )
        {
            if (String.Equals(
                    key, ProviderNameKey, StringComparison.Ordinal) &&
                (String.Equals(
                    value, DefaultProviderName, StringComparison.Ordinal)
#if NET_40 || NET_45 || NET_451
                || String.Equals(
                    value, Ef6ProviderName, StringComparison.Ordinal)
#endif
                ))
            {
                return true;







|







423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
            string key,
            string value
            )
        {
            if (String.Equals(
                    key, ProviderNameKey, StringComparison.Ordinal) &&
                (String.Equals(
                    value, LegacyProviderName, StringComparison.Ordinal)
#if NET_40 || NET_45 || NET_451
                || String.Equals(
                    value, Ef6ProviderName, StringComparison.Ordinal)
#endif
                ))
            {
                return true;