Ejemplo n.º 1
0
        GetDbConnectionTypeNames()
        {
            DbConnectionTypeStringDictionary result =
                new DbConnectionTypeStringDictionary();

            result.Add(DbConnectionType.None,
                       typeof(object).AssemblyQualifiedName);

            result.Add(DbConnectionType.Odbc,
                       typeof(OdbcConnection).AssemblyQualifiedName);

            result.Add(DbConnectionType.OleDb,
                       typeof(OleDbConnection).AssemblyQualifiedName);

            result.Add(DbConnectionType.Sql,
                       typeof(SqlConnection).AssemblyQualifiedName);

            return(result);
        }
Ejemplo n.º 2
0
        GetOtherDbConnectionTypeNames(bool full, bool copy)
        {
            lock (syncRoot)
            {
                //
                // NOTE: One-time initialization, these are not per-interpreter
                //       datums and never change.
                //
                if (DbConnectionTypeFullNames == null)
                {
                    DbConnectionTypeFullNames =
                        new DbConnectionTypeStringDictionary();

                    //
                    // NOTE: This type name is optional because it requires the
                    //       System.Data.OracleClient assembly to be loaded.
                    //
                    DbConnectionTypeFullNames.Add(DbConnectionType.Oracle,
                                                  "System.Data.OracleClient.OracleConnection, " +
                                                  "System.Data.OracleClient, Version=2.0.0.0, " +
                                                  "Culture=neutral, PublicKeyToken=b77a5c561934e089");

                    //
                    // NOTE: This type name is optional because it requires the
                    //       .NET Framework v3.5 (SP1 or higher?) to be installed.
                    //
                    DbConnectionTypeFullNames.Add(DbConnectionType.SqlCe,
                                                  "System.Data.SqlServerCe.SqlCeConnection, " +
                                                  "System.Data.SqlServerCe, Version=3.5.1.0, " +
                                                  "Culture=neutral, PublicKeyToken=89845dcd8080cc91");

                    //
                    // NOTE: This type name is optional because it requires
                    //       the System.Data.SQLite assembly to be loaded
                    //       (i.e. from "https://system.data.sqlite.org/" OR
                    //       "https://sf.net/projects/sqlite-dotnet2/").
                    //
                    DbConnectionTypeFullNames.Add(DbConnectionType.SQLite,
                                                  "System.Data.SQLite.SQLiteConnection, " +
                                                  "System.Data.SQLite, Version=1.0, " +
                                                  "Culture=neutral, PublicKeyToken=db937bc2d44ff139");
                }

                if (DbConnectionTypeNames == null)
                {
                    DbConnectionTypeNames =
                        new DbConnectionTypeStringDictionary();

                    //
                    // NOTE: This type name is optional because it requires
                    //       the System.Data.SQLite assembly to be loaded
                    //       (i.e. from "https://system.data.sqlite.org/" OR
                    //       "https://sf.net/projects/sqlite-dotnet2/").
                    //
                    DbConnectionTypeNames.Add(DbConnectionType.SQLite,
                                              "System.Data.SQLite.SQLiteConnection");
                }

                if (copy)
                {
                    return(new DbConnectionTypeStringDictionary(full ?
                                                                DbConnectionTypeFullNames : DbConnectionTypeNames));
                }
                else
                {
                    return(full ?
                           DbConnectionTypeFullNames : DbConnectionTypeNames);
                }
            }
        }
Ejemplo n.º 3
0
        ///////////////////////////////////////////////////////////////////////

        public static ReturnCode CreateDbConnection(
            Interpreter interpreter,
            DbConnectionType dbConnectionType,
            string connectionString,
            string typeFullName,
            string typeName,
            ValueFlags valueFlags,
            DbConnectionTypeStringDictionary dbConnectionTypeFullNames,
            DbConnectionTypeStringDictionary dbConnectionTypeNames,
            ref IDbConnection connection,
            ref Result error
            )
        {
            try
            {
                switch (dbConnectionType)
                {
                case DbConnectionType.None:
                {
                    //
                    // NOTE: The caller explicitly requested an invalid
                    //       database connection; therefore, return one.
                    //
                    connection = null;
                    return(ReturnCode.Ok);
                }

                case DbConnectionType.Odbc:
                {
                    connection = new OdbcConnection(connectionString);
                    return(ReturnCode.Ok);
                }

                case DbConnectionType.OleDb:
                {
                    connection = new OleDbConnection(connectionString);
                    return(ReturnCode.Ok);
                }

                case DbConnectionType.Sql:
                {
                    connection = new SqlConnection(connectionString);
                    return(ReturnCode.Ok);
                }

                case DbConnectionType.Other:
                {
                    return(CreateOtherDbConnection(
                               interpreter, dbConnectionType, connectionString,
                               typeFullName, typeName, valueFlags, ref connection,
                               ref error));
                }

                default:
                {
                    //
                    // NOTE: Lookup the type name and/or full name and
                    //       then go to the "other" case (for database
                    //       connection types that are not "built-in").
                    //
                    bool found = false;

                    if ((dbConnectionTypeFullNames != null) &&
                        dbConnectionTypeFullNames.TryGetValue(
                            dbConnectionType, out typeFullName))
                    {
                        found = true;
                    }

                    if ((dbConnectionTypeNames != null) &&
                        dbConnectionTypeNames.TryGetValue(
                            dbConnectionType, out typeName))
                    {
                        found = true;
                    }

                    if (found)
                    {
                        goto case DbConnectionType.Other;
                    }

                    error = String.Format(
                        "unsupported database connection type \"{0}\"",
                        dbConnectionType);

                    break;
                }
                }
            }
            catch (Exception e)
            {
                error = e;
            }

            return(ReturnCode.Error);
        }