public FromSelectClause (SelectStatement source)
		{
			Source = source;
		}
		protected void OnSelectAllCommand ()
		{
			TableNode node = (TableNode)CurrentNode.DataItem;
			
			IdentifierExpression tableId = new IdentifierExpression (node.Table.Name);
			SelectStatement sel = new SelectStatement (new FromTableClause (tableId));

			IPooledDbConnection conn = node.ConnectionContext.ConnectionPool.Request ();
			IDbCommand command = conn.CreateCommand (sel);
			conn.ExecuteTableAsync (command, new ExecuteCallback<DataTable> (OnSelectCommandThreaded), null);
		}
Esempio n. 3
0
		public UnionClause (SelectStatement union)
		{
			Union = union;
		}
		private void OnSelectColumnsCommandGetColumns (object state)
		{
			TableNode node = (TableNode)state;
			
			ColumnSchemaCollection columns = node.Table.Columns; //this can invoke the schema provider, so it must be in bg thread
			
			DispatchService.GuiDispatch (delegate () {
				SelectColumnDialog dlg = new SelectColumnDialog (true, columns);
				if (dlg.Run () == (int)Gtk.ResponseType.Ok) {
					IdentifierExpression tableId = new IdentifierExpression (node.Table.Name);
					List<IdentifierExpression> cols = new List<IdentifierExpression> ();
					foreach (ColumnSchema schema in dlg.CheckedColumns)
						cols.Add (new IdentifierExpression (schema.Name));
					
					SelectStatement sel = new SelectStatement (new FromTableClause (tableId), cols);

					IPooledDbConnection conn = node.ConnectionContext.ConnectionPool.Request ();
					IDbCommand command = conn.CreateCommand (sel);
					
					conn.ExecuteTableAsync (command, new ExecuteCallback<DataTable> (OnSelectCommandThreaded), null);
				}
				dlg.Destroy ();
			});
		}
		protected void OnQueryCommand ()
		{
			TableNode node = (TableNode)CurrentNode.DataItem;
			
			IdentifierExpression tableId = new IdentifierExpression (node.Table.Name);
			SelectStatement sel = new SelectStatement (new FromTableClause (tableId));
			
			SqlQueryView view = new SqlQueryView ();
			view.SelectedConnectionContext = node.ConnectionContext;
			
			IDbFactory fac = DbFactoryService.GetDbFactory (node.ConnectionContext.ConnectionSettings);
			view.Text = fac.Dialect.GetSql (sel);

			IdeApp.Workbench.OpenDocument (view, true);
		}
Esempio n. 6
0
		protected virtual string GetStatementSql (SelectStatement statement)
		{
			StringBuilder sb = new StringBuilder ();
			
			sb.Append ("SELECT ");
			bool first = true;
			foreach (IdentifierExpression expr in statement.Columns) {
				if (first)
					first = false;
				else
					sb.Append (',');
				
				sb.Append (GetSql (expr));
			}
			
			sb.Append (' ');
			sb.Append (Environment.NewLine);
			sb.Append (GetSql (statement.From));
			
			if (statement.Where != null) {
				sb.Append (GetSql (statement.Where));
				sb.Append (' ');
				sb.Append (Environment.NewLine);
			}
			
			if (statement.OrderBy != null) {
				sb.Append (GetSql (statement.OrderBy));
				sb.Append (' ');
				sb.Append (Environment.NewLine);
			}
			
			if (statement.GroupBy != null) {
				sb.Append (GetSql (statement.GroupBy));
				sb.Append (' ');
				sb.Append (Environment.NewLine);
			}
			
			if (statement.Having != null) {
				sb.Append (GetSql (statement.Having));
				sb.Append (' ');
				sb.Append (Environment.NewLine);
			}
			
			if (statement.Union != null) {
				sb.Append (GetSql (statement.Union));
				sb.Append (' ');
				sb.Append (Environment.NewLine);
			}
			
			if (statement.Join != null) {
				sb.Append (GetSql (statement.Join));
				sb.Append (' ');
				sb.Append (Environment.NewLine);
			}
			
			sb.Append (';');
			
			return sb.ToString ();
		}
		public virtual string GetSelectQuery (TableSchema table)
		{
			ISqlDialect dialect =  this.ConnectionPool.DbFactory.Dialect;
			IdentifierExpression tableId = new IdentifierExpression (table.Name);
			List<IdentifierExpression> columns = new List<IdentifierExpression>();
			
			foreach (ColumnSchema col in table.Columns) {
				columns.Add(new IdentifierExpression(col.Name));
			}
			
			SelectStatement sel = new SelectStatement (new FromTableClause (tableId),columns);
			return dialect.GetSql(sel);
		}
Esempio n. 8
0
        protected virtual string GetStatementSql(SelectStatement statement)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("SELECT ");
            bool first = true;

            foreach (IdentifierExpression expr in statement.Columns)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    sb.Append(',');
                }

                sb.Append(GetSql(expr));
            }

            sb.Append(' ');
            sb.Append(Environment.NewLine);
            sb.Append(GetSql(statement.From));

            if (statement.Where != null)
            {
                sb.Append(GetSql(statement.Where));
                sb.Append(' ');
                sb.Append(Environment.NewLine);
            }

            if (statement.OrderBy != null)
            {
                sb.Append(GetSql(statement.OrderBy));
                sb.Append(' ');
                sb.Append(Environment.NewLine);
            }

            if (statement.GroupBy != null)
            {
                sb.Append(GetSql(statement.GroupBy));
                sb.Append(' ');
                sb.Append(Environment.NewLine);
            }

            if (statement.Having != null)
            {
                sb.Append(GetSql(statement.Having));
                sb.Append(' ');
                sb.Append(Environment.NewLine);
            }

            if (statement.Union != null)
            {
                sb.Append(GetSql(statement.Union));
                sb.Append(' ');
                sb.Append(Environment.NewLine);
            }

            if (statement.Join != null)
            {
                sb.Append(GetSql(statement.Join));
                sb.Append(' ');
                sb.Append(Environment.NewLine);
            }

            sb.Append(';');

            return(sb.ToString());
        }