Ejemplo n.º 1
1
        public static void Test(IMyMetaTestContext criteria)
        {
            IMyMetaPlugin plugin = null;

            try
            {
                plugin = dbRoot.Plugins[criteria.ProviderType] as IMyMetaPlugin;

                IMyMetaPluginContext context = new MyMetaPluginContext(plugin.ProviderUniqueKey, criteria.ConnectionString);

                plugin.Initialize(context);
                using (IDbConnection conn = plugin.NewConnection)
                {
                    conn.Open();
                    conn.Close();
                }
                criteria.AppendLog("Connection Test Successful.");
            }
            catch (Exception ex)
            {
                criteria.AppendLog("Error testing connection", ex);
            }

            _databases = null;
            TestDatabases(criteria, plugin);
            TestTables(criteria, plugin);
            TestViews(criteria, plugin);
            TestProcedures(criteria, plugin);
            _databases = null;
        }
Ejemplo n.º 2
0
        public override string BrowseConnectionString(string connstr)
        {
            MyMetaPluginContext pluginContext = new MyMetaPluginContext(this.DriverId, connstr);

            plugin.Initialize(pluginContext);
            return(plugin.GetDatabaseSpecificMetaData(null, "BrowseDatabase") as string);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// A Plugin ConnectionString is a special feature for external assemblies.
        /// </summary>
        /// <param name="pluginConnectionString">Sample: PluginName;Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Data Source=localhost</param>
        /// <param name="plugin">Returns the plugin object.</param>
        /// <returns></returns>
        private IDbConnection GetConnectionFromPlugin(string providerName, string pluginConnectionString, out IMyMetaPlugin plugin)
        {
            MyMetaPluginContext pluginContext = new MyMetaPluginContext(providerName, pluginConnectionString);

            IDbConnection connection = null;
            if (!Plugins.ContainsKey(providerName))
            {
                throw new Exception("MyMeta Plugin \"" + providerName + "\" not registered.");
            }
            else
            {
                plugin = Plugins[providerName] as IMyMetaPlugin;
                plugin.Initialize(pluginContext);

                connection = plugin.NewConnection;
            }

            return connection;
        }
Ejemplo n.º 4
0
 public override string BrowseConnectionString(string connstr)
 {
     MyMetaPluginContext pluginContext = new MyMetaPluginContext(this.DriverId, connstr);
     plugin.Initialize(pluginContext);
     return plugin.GetDatabaseSpecificMetaData(null, "BrowseDatabase") as string;
 }
Ejemplo n.º 5
0
        protected IResultColumns ResultColumnsFromSQL(string sql, IDbConnection cn)
        {
            MyMetaPluginContext context  = new MyMetaPluginContext(null, null);
            DataTable           metaData = context.CreateResultColumnsDataTable();

            Plugin.PluginResultColumns resultCols = new Plugin.PluginResultColumns(null);
            resultCols.dbRoot = dbRoot;

            IDbCommand command = cn.CreateCommand();

            command.CommandText = sql;
            command.CommandType = CommandType.Text;

            using (IDataReader reader = command.ExecuteReader())
            {
                DataTable schema;
                //DataTable data;
                string dataType, fieldname;
                int    length;

                // Skip columns contains the index of any columns that we cannot handle, array types and such ...
                Hashtable skipColumns = null;

                reader.Read();
                schema = reader.GetSchemaTable();

                IProviderType provType = null;
                int           columnOrdinal = 0, numericPrecision = 0, numericScale = 0, providerTypeInt = -1, colID = 0;
                bool          isLong = false;
                string        dbTypeName = string.Empty, dbTypeNameComplete = string.Empty;

                foreach (DataRow row in schema.Rows)
                {
                    DataRow metarow = metaData.NewRow();
                    fieldname = row["ColumnName"].ToString();
                    dataType  = row["DataType"].ToString();
                    length    = 0;

                    provType         = null;
                    columnOrdinal    = 0;
                    numericPrecision = 0;
                    numericScale     = 0;
                    providerTypeInt  = -1;
                    isLong           = false;

                    if (row["ColumnSize"] != DBNull.Value)
                    {
                        length = Convert.ToInt32(row["ColumnSize"]);
                    }
                    if (row["ColumnOrdinal"] != DBNull.Value)
                    {
                        columnOrdinal = Convert.ToInt32(row["ColumnOrdinal"]);
                    }
                    if (row["NumericPrecision"] != DBNull.Value)
                    {
                        numericPrecision = Convert.ToInt32(row["NumericPrecision"]);
                    }
                    if (row["NumericScale"] != DBNull.Value)
                    {
                        numericScale = Convert.ToInt32(row["NumericScale"]);
                    }
                    if (row["IsLong"] != DBNull.Value)
                    {
                        isLong = Convert.ToBoolean(row["IsLong"]);
                    }
                    if (row["ProviderType"] != DBNull.Value)
                    {
                        providerTypeInt = Convert.ToInt32(row["ProviderType"]);
                    }

                    OleDbType oledbType;
                    try { oledbType = (OleDbType)providerTypeInt; }
                    catch { oledbType = OleDbType.IUnknown; }

                    this.GetNativeType(oledbType, providerTypeInt, dataType, length, numericPrecision, numericScale, isLong, out dbTypeName, out dbTypeNameComplete);

                    metarow["COLUMN_NAME"]        = fieldname;
                    metarow["ORDINAL_POSITION"]   = columnOrdinal;
                    metarow["DATA_TYPE"]          = providerTypeInt;
                    metarow["TYPE_NAME"]          = dbTypeName;
                    metarow["TYPE_NAME_COMPLETE"] = dbTypeNameComplete;

                    metaData.Rows.Add(metarow);
                }

                resultCols.Populate(metaData);
            }

            return(resultCols);
        }
Ejemplo n.º 6
0
        protected IResultColumns ResultColumnsFromSQL(string sql, IDbConnection cn)
        {
            MyMetaPluginContext context = new MyMetaPluginContext(null, null);
            DataTable metaData = context.CreateResultColumnsDataTable();
            Plugin.PluginResultColumns resultCols = new Plugin.PluginResultColumns(null);
            resultCols.dbRoot = dbRoot;

            IDbCommand command = cn.CreateCommand();
            command.CommandText = sql;
            command.CommandType = CommandType.Text;

            using (IDataReader reader = command.ExecuteReader())
            {
                DataTable schema;
                //DataTable data;
                string dataType, fieldname;
                int length;

                // Skip columns contains the index of any columns that we cannot handle, array types and such ...
                Hashtable skipColumns = null;

                reader.Read();
                schema = reader.GetSchemaTable();

                IProviderType provType = null;
                int columnOrdinal = 0, numericPrecision = 0, numericScale = 0, providerTypeInt = -1, colID = 0;
                bool isLong = false;
                string dbTypeName = string.Empty, dbTypeNameComplete = string.Empty;

                foreach (DataRow row in schema.Rows)
                {
                    DataRow metarow = metaData.NewRow();
                    fieldname = row["ColumnName"].ToString();
                    dataType = row["DataType"].ToString();
                    length = 0;

                    provType = null;
                    columnOrdinal = 0; 
                    numericPrecision = 0; 
                    numericScale = 0; 
                    providerTypeInt = -1;
                    isLong = false;

                    if (row["ColumnSize"] != DBNull.Value) length = Convert.ToInt32(row["ColumnSize"]);
                    if (row["ColumnOrdinal"] != DBNull.Value) columnOrdinal = Convert.ToInt32(row["ColumnOrdinal"]);
                    if (row["NumericPrecision"] != DBNull.Value) numericPrecision = Convert.ToInt32(row["NumericPrecision"]);
                    if (row["NumericScale"] != DBNull.Value) numericScale = Convert.ToInt32(row["NumericScale"]);
                    if (row["IsLong"] != DBNull.Value) isLong = Convert.ToBoolean(row["IsLong"]);
                    if (row["ProviderType"] != DBNull.Value) providerTypeInt = Convert.ToInt32(row["ProviderType"]);

                    OleDbType oledbType;
                    try { oledbType = (OleDbType)providerTypeInt; }
                    catch { oledbType = OleDbType.IUnknown; }

                    this.GetNativeType(oledbType, providerTypeInt, dataType, length, numericPrecision, numericScale, isLong, out dbTypeName, out dbTypeNameComplete);

                    metarow["COLUMN_NAME"] = fieldname;
                    metarow["ORDINAL_POSITION"] = columnOrdinal;
                    metarow["DATA_TYPE"] = providerTypeInt;
                    metarow["TYPE_NAME"] = dbTypeName;
                    metarow["TYPE_NAME_COMPLETE"] = dbTypeNameComplete;

                    metaData.Rows.Add(metarow);
                }

                resultCols.Populate(metaData);
            }

            return resultCols;
        }