Ejemplo n.º 1
0
        /// <summary>
        /// List all tables in the database.
        /// </summary>
        /// <returns>List of strings, each being a table name.</returns>
        public List <string> ListTables()
        {
            string        query      = null;
            DataTable     result     = null;
            List <string> tableNames = new List <string>();

            switch (_DbType)
            {
            case DbTypes.MsSql:
                query = MssqlHelper.LoadTableNamesQuery(_DatabaseName);
                break;

            case DbTypes.MySql:
                query = MysqlHelper.LoadTableNamesQuery();
                break;

            case DbTypes.PgSql:
                query = PgsqlHelper.LoadTableNamesQuery();
                break;
            }

            result = Query(query);

            if (result != null && result.Rows.Count > 0)
            {
                switch (_DbType)
                {
                case DbTypes.MsSql:
                    foreach (DataRow curr in result.Rows)
                    {
                        tableNames.Add(curr["TABLE_NAME"].ToString());
                    }
                    break;

                case DbTypes.MySql:
                    foreach (DataRow curr in result.Rows)
                    {
                        tableNames.Add(curr["Tables_in_" + _DatabaseName].ToString());
                    }
                    break;

                case DbTypes.PgSql:
                    foreach (DataRow curr in result.Rows)
                    {
                        tableNames.Add(curr["tablename"].ToString());
                    }
                    break;
                }
            }

            return(tableNames);
        }
Ejemplo n.º 2
0
        private void LoadTableNames()
        {
            lock (LoadingTablesLock)
            {
                string    query  = "";
                DataTable result = new DataTable();

                #region Build-Query

                switch (DbType)
                {
                case DbTypes.MsSql:
                    query = MssqlHelper.LoadTableNamesQuery(Database);
                    break;

                case DbTypes.MySql:
                    query = MysqlHelper.LoadTableNamesQuery();
                    break;

                case DbTypes.PgSql:
                    query = PgsqlHelper.LoadTableNamesQuery();
                    break;
                }

                #endregion

                #region Process-Results

                result = RawQuery(query);
                List <string> tableNames = new List <string>();

                if (result != null && result.Rows.Count > 0)
                {
                    switch (DbType)
                    {
                    case DbTypes.MsSql:
                        foreach (DataRow curr in result.Rows)
                        {
                            tableNames.Add(curr["TABLE_NAME"].ToString());
                        }
                        break;

                    case DbTypes.MySql:
                        foreach (DataRow curr in result.Rows)
                        {
                            tableNames.Add(curr["Tables_in_" + Database].ToString());
                        }
                        break;

                    case DbTypes.PgSql:
                        foreach (DataRow curr in result.Rows)
                        {
                            tableNames.Add(curr["tablename"].ToString());
                        }
                        break;
                    }
                }

                if (tableNames != null && tableNames.Count > 0)
                {
                    TableNames = new ConcurrentList <string>();
                    foreach (string curr in tableNames)
                    {
                        TableNames.Add(curr);
                    }
                }

                #endregion

                return;
            }
        }