Пример #1
0
        public override string BrowseConnectionString(string connstr)
        {
            OMetaPluginContext pluginContext = new OMetaPluginContext(this.DriverId, connstr);

            plugin.Initialize(pluginContext);
            return(plugin.GetDatabaseSpecificMetaData(null, "BrowseDatabase") as string);
        }
Пример #2
0
        protected IResultColumns ResultColumnsFromSQL(string sql, IDbConnection cn)
        {
            OMetaPluginContext context  = new OMetaPluginContext(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);
        }