/// <summary>
        /// Recupera a descrição da tabela disponíveis no catalogo.
        /// </summary>
        /// <param name="catalog">Nome do catalogo que contem as tabelas.</param>
        /// <param name="schemaPattern">Padrão que será usado para filtrar os esquemas.</param>
        /// <param name="tableNamePattern">Padrão que será usado para filtrar as tabelas.</param>
        /// <returns></returns>
        public virtual System.Data.DataTable GetTables(string catalog, string schemaPattern, string tableNamePattern)
        {
            var restrictions = new[] {
                catalog,
                schemaPattern,
                tableNamePattern,
                null
            };

            return(_connection.GetSchema("Tables", restrictions));
        }
示例#2
0
 public virtual DataTable GetSchema(string collectionName, params string[] restrictionValues)
 {
     using (System.Data.Common.DbConnection conn = (System.Data.Common.DbConnection)_dialect.CreateConnection(_ConnectionString))
     {
         conn.Open();
         try
         {
             return(restrictionValues != null && restrictionValues.Length > 0 ?
                    conn.GetSchema(collectionName, restrictionValues) :
                    conn.GetSchema(collectionName));
         }
         finally
         {
             conn.Close();
         }
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="pFileString"></param>
        /// <param name="pTableName"></param>
        /// <param name="pIsConnectionString"></param>
        /// <returns></returns>
        public override bool CheckDatabaseExistance(string pFileString, string pTableName, bool pIsConnectionString = false)
        {
            if (pIsConnectionString)
            {
                System.Data.Common.DbConnection Conn = null;
                //System.Data.Common.DbDataAdapter Adapter = null;
                System.Data.DataTable DataTable = new System.Data.DataTable();
                bool result = false;

                string connString = pFileString;

                string[] restrictions = new string[] { null, null, pTableName };

                if (DataSource != null)
                {
                    IDbDriver driver = this;
                    driver.ConnectionString = connString;
                    Conn = (System.Data.Common.DbConnection)driver.GetConnection();
                    try
                    {
                        Conn.Open();

                        DataTable = Conn.GetSchema("Tables", restrictions);

                        if (DataTable.Rows.Count == 0)
                        {
                            //Table does not exist
                            result = false;
                        }

                        else
                        {
                            //Table exists
                            result = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        // do nothing
                    }
                    finally
                    {
                        Conn.Close();
                    }
                }

                return(result);
            }
            else
            {
                return(System.IO.File.Exists(pFileString));
            }
        }
示例#4
0
        /// <summary>
        /// Gets metadata data set from connection string
        /// </summary>
        /// <param name="connectionString">The connection</param>
        /// <returns>The metadata data set</returns>
        DataSet IDataSetFactory.GetData(string connectionString)
        {
            IDataSetFactory f = this;

            System.Data.Common.DbConnection connection = f.Connection;
            connection.ConnectionString = connectionString;
            DataSet s = new DataSet();

            connection.Open();
            DataTable table = connection.GetSchema("Columns");

            s.Tables.Add(table);
            return(s);
        }
示例#5
0
 public virtual DataTable GetSchema()
 {
     using (System.Data.Common.DbConnection conn = (System.Data.Common.DbConnection)_dialect.CreateConnection(_ConnectionString))
     {
         conn.Open();
         try
         {
             return(conn.GetSchema());
         }
         finally
         {
             conn.Close();
         }
     }
 }
示例#6
0
        public static List <SQLTableName> GetSQLList(string list)
        {
            Kit.CheckDataBase();
            List <SQLTableName> lsttab = null;

            if (Keel.DB.Common.NowDataBase.GetType() == typeof(Keel.DB.SQLServer))
            {
                DBHelper <SQLTableName> dbt = new DBHelper <SQLTableName>();
                lsttab = dbt.GetDataViewForObjectList(list);
            }
            else if (Keel.DB.Common.NowDataBase.GetType() == typeof(Keel.DB.MSAccess))
            {
                lsttab = new List <SQLTableName>();
                KeelKit.Core.DBInformer dbi = new DBInformer(Kit.SlnKeel.ConnectString);
                Hashtable dtm = list != "ViewInfo" ? dbi.GetUserTables() : dbi.GetUserViews();
                foreach (DictionaryEntry tb in dtm)
                {
                    SQLTableName st = new SQLTableName();
                    st.name = tb.Key.ToString();
                    lsttab.Add(st);
                }
            }
            else
            {
                lsttab = new List <SQLTableName>();
                System.Data.Common.DbConnection dbc = Keel.DB.Common.NowDataBase.GetProviderFactory().CreateConnection();
                dbc.ConnectionString = Keel.DB.Common.NowDataBase.ConnectString;
                dbc.Open();
                DataTable dt = dbc.GetSchema(list != "ViewInfo" ? "Tables" : "Views");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    lsttab.Add(new SQLTableName()
                    {
                        name = (string)dt.Rows[i]["TABLE_NAME"]
                    });
                }
                dbc.Close();
            }
            return(lsttab);
        }
示例#7
0
文件: Entity.cs 项目: jank3/RestSql
        public virtual void Load(System.Data.Common.DbConnection dbConn)
        {
            System.Data.DataTable schema = dbConn.GetSchema("Tables",
                                                            new String[]
            {
                null,    // database
                null,    // owner
                Name     // table name
            });
            foreach (System.Data.DataColumn col in schema.Columns)
            {
                Property prop = new Property();
                prop.Name        = col.ColumnName;
                prop.Type        = col.DataType.ToString();
                prop.Description = col.Caption;

                if (!this.Properties.Contains(prop))
                {
                    this.Properties.Add(prop);
                }
            }
        }
示例#8
0
        /// <summary>
        /// Gets metadata data set from connection
        /// </summary>
        /// <param name="connection">The connection</param>
        /// <returns>The metadata data set</returns>
        DataSet IDataSetFactory.GetData(System.Data.Common.DbConnection connection)
        {
            DataSet s = new DataSet();

            connection.Open();
            DataTable table = connection.GetSchema("Columns");

            connection.Close();
            Dictionary <string, Dictionary <string, DataRow> > dic = DataSetFactoryChooser.GetTables("TABLE_NAME", "COLUMN_NAME", table);

            foreach (string name in dic.Keys)
            {
                Dictionary <string, DataRow> d = dic[name];
                DataTable dt = new DataTable();
                dt.TableName = name;
                int length = 1;
                foreach (string cn in d.Keys)
                {
                    DataRow row = d[cn];
                    string  ty  = row["DATA_TYPE"] + "";
                    object  o   = null;
                    if (ty.Equals("uniqueidentifier"))
                    {
                        o = new Guid();
                    }
                    if (ty.Equals("image"))
                    {
                        o = new byte[2];
                    }
                    if (ty.Equals("nvarchar"))
                    {
                        string str = "";
                        o = str;
                    }
                    if (ty.Equals("varchar"))
                    {
                        o = new char[2];
                    }
                    if (ty.Equals("char"))
                    {
                        o      = new char[2];
                        length = (int)row["CHARACTER_MAXIMUM_LENGTH"];
                    }
                    if (ty.Equals("bigint"))
                    {
                        long a = 0;
                        o = a;
                    }
                    if (ty.Equals("int"))
                    {
                        int a = 0;
                        o = a;
                    }
                    if (ty.Equals("datetime"))
                    {
                        o = new DateTime();
                    }
                    if (ty.Equals("float"))
                    {
                        byte prec = (byte)row["NUMERIC_PRECISION"];
                        if (prec == 53)
                        {
                            double a = 0;
                            o = a;
                        }
                    }
                    if (o != null)
                    {
                        Type type = o.GetType();
                        if (o is char[])
                        {
                            type = "".GetType();
                        }
                        DataColumn col = new DataColumn();
                        col.ColumnName = cn;
                        col.DataType   = type;
                        string on = row["IS_NULLABLE"] + "";
                        col.AllowDBNull = on.Equals("YES");
                        try
                        {
                            col.MaxLength = length;
                        }
                        catch (Exception)
                        {
                        }
                        dt.Columns.Add(col);
                    }
                }
                s.Tables.Add(dt);
            }
            return(s);
        }
示例#9
0
        public static List <SQLTableInfo> GetSqlTableInfoList()
        {
            List <SQLTableInfo> dbix = new List <SQLTableInfo>();

            if (Keel.DB.Common.NowDataBase.GetType() == typeof(Keel.DB.SQLServer))
            {
                DBHelper <SQLTableInfo> dbi = new DBHelper <SQLTableInfo>();
                dbix = dbi.GetDataViewForObjectList();
                dbix.AddRange(dbi.GetDataViewForObjectList("ViewInfo"));
            }
            else if (Keel.DB.Common.NowDataBase.GetType() == typeof(Keel.DB.MSAccess))
            {
                KeelKit.Core.DBInformer dbi = new DBInformer(Kit.SlnKeel.ConnectString);
                //Hashtable dtm = list != "ViewInfo" ? dbi.GetUserTables() : dbi.GetUserViews();
                Hashtable dtm = dbi.GetUserTables();
                foreach (DictionaryEntry tb in dtm)
                {
                    ArrayList al   = dbi.GetTableColumns(tb.Key.ToString());
                    DataTable pk   = dbi.GetPrimaryKeys(tb.Key.ToString());
                    string    keyx = "";
                    if (pk != null && pk.Rows.Count > 0)
                    {
                        keyx = pk.Rows[0]["COLUMN_NAME"].ToString();
                        //  t_identity=pk.Rows[0]["COLUMN_NAME"].ToString ()
                    }
                    DataTable fk = dbi.GetForeignKeys(tb.Key.ToString());
                    foreach (var item in al)
                    {
                        SQLTableInfo      st  = new SQLTableInfo();
                        DataFieldMetadata dfm = item as DataFieldMetadata;
                        st.t_fieldbitcount     = dfm.Size;
                        st.t_fieldcannull      = dfm.IsNullable ? OK : "";
                        st.t_fielddefaultvalue = dfm.DefaultValueStr as string;
                        //st.t_fielddesc =
                        //st.t_fieldindex =
                        //st.t_fieldiscomputed
                        st.t_fieldlenght = dfm.Size;
                        st.t_fieldname   = dfm.Name;
                        //st.t_fieldscale =

                        st.t_fieldtype = dbi.ConvertDataType2DBType(dfm.FieldType);
                        st.t_identity  = dfm.Name == keyx ? OK : "";
                        st.t_tablekey  = dfm.Name == keyx ? OK : "";
                        st.t_tablename = dfm.Table;
                        dbix.Add(st);
                    }
                }
            }
            else
            {
                System.Data.Common.DbConnection dbc = Keel.DB.Common.NowDataBase.GetProviderFactory().CreateConnection();
                dbc.ConnectionString = Keel.DB.Common.NowDataBase.ConnectString;
                dbc.Open();
                DataTable dt = dbc.GetSchema("Columns");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow      dr  = dt.Rows[i];
                    SQLTableInfo sti = new SQLTableInfo();

                    try
                    {
                        sti.t_fieldbitcount     = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? 0 : (int)(ulong)dr["CHARACTER_MAXIMUM_LENGTH"];
                        sti.t_fieldcannull      = ((string)dr["IS_NULLABLE"] != "NO" ? OK : "");
                        sti.t_fielddefaultvalue = dr["COLUMN_DEFAULT"] as string;
                        sti.t_fielddesc         = (string)dr["COLUMN_COMMENT"];
                        sti.t_fieldindex        = (int)((ulong)dr["ORDINAL_POSITION"]);
                        sti.t_fieldiscomputed   = "";
                        sti.t_fieldlenght       = dr["CHARACTER_MAXIMUM_LENGTH"] == DBNull.Value ? 0 : (int)(ulong)dr["CHARACTER_MAXIMUM_LENGTH"];
                        sti.t_fieldname         = (string)dr["COLUMN_NAME"];
                        sti.t_fieldscale        = dr["NUMERIC_SCALE"] == DBNull.Value ? 0 : (int)(ulong)dr["NUMERIC_SCALE"];
                        sti.t_fieldtype         = (string)dr["DATA_TYPE"];
                        sti.t_identity          = dr["EXTRA"] == DBNull.Value ? "" : (((string)dr["EXTRA"]).Contains("auto_increment") ? OK : "");
                        sti.t_tabledesc         = (dr["TABLE_CATALOG"] as string + "," + dr["CHARACTER_SET_NAME"] as string);
                        sti.t_tablekey          = ((string)dr["COLUMN_KEY"] == "PRI" ? OK : "");
                        sti.t_tablename         = (string)dr["TABLE_NAME"];
                    }
                    catch (Exception ex)
                    {
                        Common.ShowInfo(ex.Message + "\r\n" + ex.StackTrace);
                    }
                    dbix.Add(sti);
                }
                dbc.Close();
            }
            return(dbix);
        }