/// <summary>
        /// Get table names for selected database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void lstDatabaseNames_SelectedIndexChanged(object sender, EventArgs e)
        {
            var databaseTables = new SqlTables(DatabaseNameListBox.Text);

            DatabaseTableNamesListBox.DataSource = null;
            DatabaseTableNamesListBox.DataSource = databaseTables.TableNames();
        }
        /// <summary>
        /// Get databases for server
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Shown(object sender, EventArgs e)
        {
            var ops = new SqlDatabases();

            DatabaseNameListBox.DataSource = ops.DatabaseNames();

            var dOperations = new SqlTables("master");

            if (!dOperations.NorthWindDemoExists())
            {
                return;
            }

            DatabaseNameListBox.SelectedIndex       = DatabaseNameListBox.FindString("NorthWindDemo");
            DatabaseTableNamesListBox.SelectedIndex = DatabaseTableNamesListBox.FindString("Customer");

            var databaseTables = new SqlTables("NorthWindDemo");

            _countryColumnList = databaseTables.CountrySelected;

            foreach (var item in _countryColumnList)
            {
                SelectedTableColumnCheckedListBox.FindItemAndSetChecked(item);
            }
        }
Beispiel #3
0
		public static DataTable GetSchema(SqlConnection con, string collectionName, object[] restrictions)
		{
			var filter = String.Format("CollectionName = '{0}'", collectionName);

			var ds = new DataSet();
			ds.ReadXml(new StringReader(Resources.MetaData));

			var collection = ds.Tables[DbMetaDataCollectionNames.MetaDataCollections].Select(filter);

			if (collection.Length != 1)
				throw new NotSupportedException("Unsupported collection name.");

			if (restrictions != null && restrictions.Length > (int)collection[0]["NumberOfRestrictions"])
				throw new InvalidOperationException("The number of specified restrictions is not valid.");

			if (ds.Tables[DbMetaDataCollectionNames.Restrictions].Select(filter).Length !=
				(int)collection[0]["NumberOfRestrictions"])
				throw new InvalidOperationException("Incorrect restriction definition.");

			SqlDbSchema returnSchema;
			switch (collectionName.ToLower(CultureInfo.CurrentCulture))
			{
				case "checkconstraints":
					returnSchema = new SqlCheckConstraints();
					break;
				case "columns":
					returnSchema = new SqlColumns();
					break;
				case "defaultconstraints":
					returnSchema = new SqlDefaultConstraints();
					break;
				case "foreignkeys":
					returnSchema = new SqlForeignKeys();
					break;
				case "indexes":
					returnSchema = new SqlIndexes();
					break;
				case "primarykeys":
					returnSchema = new SqlPrimaryKeys();
					break;
				case "tables":
					returnSchema = new SqlTables();
					break;
				case "triggers":
					returnSchema = new SqlTriggers();
					break;
				case "uniquekeys":
					returnSchema = new SqlUniqueKeys();
					break;
				default:
					throw new NotSupportedException("The specified metadata collection is not supported.");
			}

			return returnSchema.GetSchema(con, collectionName, restrictions);
		}
Beispiel #4
0
        public override string ToString()
        {
            var sb = new StringBuilder("SELECT ");

            if (IsDistinctQuery)
            {
                sb.Append("DISTINCT ");
            }
            if (TopExpression != null)
            {
                sb.Append("TOP (").Append(TopExpression).Append(") ");
            }
            if (SelectProjection != null)
            {
                sb.Append(SelectProjection);
            }
            if (SqlTables.Count > 0)
            {
                sb.Append(" FROM ");
                sb.Append(SqlTables.First());
                SqlTables.Skip(1).Aggregate(sb, (builder, table) => builder.Append(", ").Append(table));
            }
            if (WhereCondition != null)
            {
                sb.Append(" WHERE ").Append(WhereCondition);
            }
            if (GroupByExpression != null)
            {
                sb.Append(" GROUP BY ").Append(GroupByExpression);
            }
            if (Orderings.Count > 0)
            {
                sb.Append(" ORDER BY ");
                Orderings.Aggregate(
                    sb,
                    (builder, ordering) => builder
                    .Append(ordering.Expression)
                    .Append(" ")
                    .Append(ordering.OrderingDirection.ToString().ToUpper()));
            }

            foreach (var combinedStatement in SetOperationCombinedStatements)
            {
                sb
                .Append(" ")
                .Append(combinedStatement.SetOperation.ToString().ToUpper())
                .Append(" (")
                .Append(combinedStatement.SqlStatement)
                .Append(")");
            }

            return(sb.ToString());
        }
Beispiel #5
0
        public ResourceManagerDatabaseSchema(string databaseLocation, SqlSchemaVerifier schemaVerifier)
            : base(databaseLocation, schemaVerifier)
        {
            ProjectTable        = new ProjectTable(this);
            PersonTable         = new PersonTable(this);
            WeeklyScheduleTable = new WeeklyScheduleTable(this);
            ResourceBlockTable  = new ResourceBlockTable(this);

            SqlTables.Add(ProjectTable);
            SqlTables.Add(PersonTable);
            SqlTables.Add(WeeklyScheduleTable);
            SqlTables.Add(ResourceBlockTable);
        }
Beispiel #6
0
        public override string ToString()
        {
            var sb = new StringBuilder("SELECT ");

            if (IsDistinctQuery)
            {
                sb.Append("DISTINCT ");
            }
            if (TopExpression != null)
            {
                sb.Append("TOP (").Append(FormattingExpressionTreeVisitor.Format(TopExpression)).Append(") ");
            }
            if (SelectProjection != null)
            {
                sb.Append(FormattingExpressionTreeVisitor.Format(SelectProjection));
            }
            if (SqlTables.Count > 0)
            {
                sb.Append(" FROM ");
                sb.Append(SqlTables.First());
                SqlTables.Skip(1).Aggregate(sb, (builder, table) => builder.Append(", ").Append(table));
            }
            if (WhereCondition != null)
            {
                sb.Append(" WHERE ").Append(FormattingExpressionTreeVisitor.Format(WhereCondition));
            }
            if (GroupByExpression != null)
            {
                sb.Append(" GROUP BY ").Append(FormattingExpressionTreeVisitor.Format(GroupByExpression));
            }
            if (Orderings.Count > 0)
            {
                sb.Append(" ORDER BY ");
                Orderings.Aggregate(
                    sb,
                    (builder, ordering) => builder
                    .Append(FormattingExpressionTreeVisitor.Format(ordering.Expression))
                    .Append(" ")
                    .Append(ordering.OrderingDirection.ToString().ToUpper()));
            }

            return(sb.ToString());
        }
        private void ApplyConfiguration()
        {
            switch (_configuration.StoreFullName)
            {
            case "Rosetta.DataStores.CommaSeperatedFileDataStore":
            case "Rosetta.DataStores.FlatFileDataStore":
                FileConnectionString.Text = _configuration.ConnectionString;
                FileName.Text             = string.IsNullOrWhiteSpace(_configuration.ConnectionString)
                                                ? "Select File" : Path.GetFileName(FileConnectionString.Text);
                break;

            case "Rosetta.DataStores.SqlDataStore":
                SqlConnectionString.Text = string.IsNullOrWhiteSpace(_configuration.ConnectionString)
                                                ? "Data Source=localhost;Initial Catalog=Rosetta;Integrated Security=True;"
                                                : _configuration.ConnectionString;
                SqlTables.LoadItems(_configuration.Columns.Select(x => x.Source).Distinct().Where(x => x.Length > 0));
                break;
            }

            Headers.LoadItems(_configuration.Columns.Select(x => x.Name));

            UpdateControlState();
        }