System.Data.SQLite
Check-in [592e679ca6]
Not logged in

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

Overview
Comment:Improve the robustness of the new provider name option handling in the design-time components.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | designOptions
Files: files | file ages | folders
SHA1: 592e679ca6f4e1af9520950d402669c2f7421f4f
User & Date: mistachkin 2014-09-03 18:38:09
Context
2014-09-04
03:30
Merge updates from trunk. Closed-Leaf check-in: 8dba4cc370 user: mistachkin tags: designOptions
2014-09-03
18:38
Improve the robustness of the new provider name option handling in the design-time components. check-in: 592e679ca6 user: mistachkin tags: designOptions
2014-08-20
19:40
Merge updates from trunk. check-in: e3dd6dc7e0 user: mistachkin tags: designOptions
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to SQLite.Designer/SQLiteOptions.cs.

     3      3    * Written by Joe Mistachkin (joe@mistachkin.com)
     4      4    *
     5      5    * Released to the public domain, use at your own risk!
     6      6    ********************************************************/
     7      7   
     8      8   using System;
     9      9   using System.Collections.Generic;
           10  +using System.Data.Common;
    10     11   using System.IO;
    11     12   using System.Runtime.InteropServices;
    12     13   using System.Windows.Forms;
    13     14   using Microsoft.VisualStudio.Shell;
    14     15   
    15     16   namespace SQLite.Designer
    16     17   {
................................................................................
   124    125           /// </summary>
   125    126           /// <returns>
   126    127           /// The configured ADO.NET provider name for System.Data.SQLite -OR-
   127    128           /// the default ADO.NET provider name for System.Data.SQLite in the
   128    129           /// event of any failure.  This method cannot return null.
   129    130           /// </returns>
   130    131           public static string GetProviderName()
          132  +        {
          133  +            return GetProviderName(DefaultProviderName);
          134  +        }
          135  +
          136  +        ///////////////////////////////////////////////////////////////////////
          137  +
          138  +        /// <summary>
          139  +        /// This method determines the name of the ADO.NET provider for the
          140  +        /// System.Data.SQLite design-time components to use.
          141  +        /// </summary>
          142  +        /// <param name="default">
          143  +        /// The value to return from this method if the name of the ADO.NET
          144  +        /// provider is unavailable -OR- cannot be determined.
          145  +        /// </param>
          146  +        /// <returns>
          147  +        /// The configured ADO.NET provider name for System.Data.SQLite -OR-
          148  +        /// the default ADO.NET provider name for System.Data.SQLite in the
          149  +        /// event of any failure.
          150  +        /// </returns>
          151  +        private static string GetProviderName(
          152  +            string @default
          153  +            )
   131    154           {
   132    155               string key = ProviderNameKey;
   133    156               string value;
   134    157   
   135    158               if (GetValue(key, out value) && IsValidValue(key, value))
   136    159                   return value;
   137    160   
   138         -            return DefaultProviderName;
          161  +            return @default;
   139    162           }
   140    163   
   141    164           ///////////////////////////////////////////////////////////////////////
   142    165   
   143    166           /// <summary>
   144    167           /// This method attempts to set the name of the ADO.NET provider for
   145    168           /// the System.Data.SQLite design-time components to use.
................................................................................
   181    204           public static bool SelectProviderName(
   182    205               ComboBox comboBox
   183    206               )
   184    207           {
   185    208               if (comboBox == null)
   186    209                   return false;
   187    210   
   188         -            string value = GetProviderName();
   189         -
   190         -            if (value == null)
   191         -                return false;
          211  +            string value = GetProviderName(null);
   192    212   
   193    213               for (int index = 0; index < comboBox.Items.Count; index++)
   194    214               {
   195    215                   object item = comboBox.Items[index];
   196    216   
   197    217                   if (item == null)
   198    218                       continue;
   199    219   
   200         -                if (String.Equals(
          220  +                if ((value == null) || String.Equals(
   201    221                           item.ToString(), value, StringComparison.Ordinal))
   202    222                   {
   203    223                       comboBox.SelectedIndex = index;
   204    224                       return true;
   205    225                   }
   206    226               }
          227  +
          228  +            return false;
          229  +        }
          230  +
          231  +        ///////////////////////////////////////////////////////////////////////
          232  +
          233  +        private static bool CheckProviderName(
          234  +            string name
          235  +            )
          236  +        {
          237  +            DbProviderFactory dbProviderFactory = null;
          238  +
          239  +            try
          240  +            {
          241  +                dbProviderFactory = DbProviderFactories.GetFactory(
          242  +                    name); /* throw */
          243  +
          244  +                return (dbProviderFactory != null);
          245  +            }
          246  +            catch
          247  +            {
          248  +                // do nothing.
          249  +            }
          250  +            finally
          251  +            {
          252  +                if (dbProviderFactory != null)
          253  +                {
          254  +                    IDisposable disposable = dbProviderFactory as IDisposable;
          255  +
          256  +                    if (disposable != null)
          257  +                    {
          258  +                        disposable.Dispose();
          259  +                        disposable = null;
          260  +                    }
          261  +
          262  +                    dbProviderFactory = null;
          263  +                }
          264  +            }
   207    265   
   208    266               return false;
   209    267           }
   210    268   
   211    269           ///////////////////////////////////////////////////////////////////////
   212    270   
   213    271           /// <summary>
................................................................................
   227    285               )
   228    286           {
   229    287               int result = 0;
   230    288   
   231    289               if (items == null)
   232    290                   return result;
   233    291   
   234         -            items.Add(DefaultProviderName);
   235         -            result++;
          292  +            IList<string> names = new List<string>();
   236    293   
   237    294   #if NET_40 || NET_45 || NET_451
   238         -            items.Add(Ef6ProviderName);
   239         -            result++;
          295  +            names.Add(Ef6ProviderName);
   240    296   #endif
          297  +
          298  +            names.Add(DefaultProviderName);
          299  +
          300  +            foreach (string name in names)
          301  +            {
          302  +                if (CheckProviderName(name))
          303  +                {
          304  +                    items.Add(name);
          305  +                    result++;
          306  +                }
          307  +            }
   241    308   
   242    309               return result;
   243    310           }
   244    311           #endregion
   245    312           #endregion
   246    313   
   247    314           ///////////////////////////////////////////////////////////////////////