//CUT:STD{{ protected void Page_Load(object sender, EventArgs e) { // Get an instance of the QueryBuilder object var qb = QueryBuilderStore.Get("UserDefinedFields"); if (qb == null) { qb = CreateQueryBuilder(); } QueryBuilderControl1.QueryBuilder = qb; ObjectTreeView1.QueryBuilder = qb; Canvas1.QueryBuilder = qb; Grid1.QueryBuilder = qb; SubQueryNavigationBar1.QueryBuilder = qb; SqlEditor1.QueryBuilder = qb; StatusBar1.QueryBuilder = qb; }
protected void UpdateDataGrid(object sender, EventArgs e) { var qb = QueryBuilderStore.Get("QueryResults"); var qt = QueryTransformerStore.Get("QueryResults"); if (string.IsNullOrEmpty(qt.SQL)) { GridView1.DataSource = null; GridView1.DataBind(); aspPage.Text = "Page: 0"; recordsCount.Text = "Records count: 0"; return; } UpdateRecordCount(qt); if (_page < 0) { _page = 0; } if (10 * _page > _recordsCount) { _page -= 1; } qt.Skip((10 * _page).ToString()); qt.Take("10"); using (var conn = DataBaseHelper.CreateSqLiteConnection("SqLiteDataBase")) { conn.Open(); using (var cmd = conn.CreateCommand()) { cmd.CommandText = qt.SQL; var reader = cmd.ExecuteReader(); GridView1.DataSource = reader; GridView1.DataBind(); } } aspPage.Text = "Page: " + _page; }
/// <summary> /// Creates and initializes new instance of the QueryBuilder object if it doesn't exist. /// </summary> /// <param name="httpContext"></param> private void CreateQueryBuilder(IHttpContext httpContext) { // Create an instance of the QueryBuilder object var queryBuilder = QueryBuilderStore.Create(httpContext, InstanceId); queryBuilder.SyntaxProvider = new MSSQLSyntaxProvider(); // Denies metadata loading requests from the metadata provider queryBuilder.MetadataLoadingOptions.OfflineMode = true; // Load MetaData from XML document. File name is stored in the "Web.config" file in [/configuration/appSettings/NorthwindXmlMetaData] key var path = ConfigurationManager.AppSettings["QueryBuilderXmlMetaData"]; var xml = Path.Combine(HostingEnvironment.MapPath("~"), path); queryBuilder.MetadataContainer.ImportFromXML(xml); //Set default query queryBuilder.SQL = GetDefaultOfflineSql(); }
public void Change(string name) { var queryBuilder = QueryBuilderStore.Get(InstanceId); queryBuilder.MetadataContainer.Clear(); if (name == "NorthwindXmlMetaData") { SetNorthwindXml(queryBuilder); } else if (name == "SQLite") { SetSqLite(queryBuilder); } else { SetDb2Xml(queryBuilder); } }
protected void Page_Load(object sender, EventArgs e) { // Get an instance of the QueryBuilder object var qb = QueryBuilderStore.Get("LoadMetadata"); if (qb == null) { qb = QueryBuilderStore.Create("LoadMetadata"); qb.SyntaxProvider = new GenericSyntaxProvider(); } QueryBuilderControl1.QueryBuilder = qb; ObjectTreeView1.QueryBuilder = qb; Canvas1.QueryBuilder = qb; Grid1.QueryBuilder = qb; SubQueryNavigationBar1.QueryBuilder = qb; SqlEditor1.QueryBuilder = qb; StatusBar1.QueryBuilder = qb; }
protected void Page_Load(object sender, EventArgs e) { // Get an instance of the QueryBuilder object var qb = QueryBuilderStore.GetOrCreate(InstanceId, InitializeQueryBuilder); var qt = QueryTransformerStore.GetOrCreate(InstanceId, q => { q.QueryProvider = qb.SQLQuery; q.AlwaysExpandColumnsInQuery = true; }); QueryBuilderControl1.QueryBuilder = qb; ObjectTreeView1.QueryBuilder = qb; Canvas1.QueryBuilder = qb; Grid1.QueryBuilder = qb; SubQueryNavigationBar1.QueryBuilder = qb; SqlEditor1.QueryBuilder = qb; StatusBar1.QueryBuilder = qb; CriteriaBuilder1.QueryTransformer = qt; }
public void OnSQLUpdated(object sender, EventArgs e) { var queryBuilder = QueryBuilderStore.Get("QueryAnalysis"); var data = new ExchangeClass(); data.Statistics = GetQueryStatistic(queryBuilder.QueryStatistics); data.SubQueries = DumpSubQueries(queryBuilder); data.QueryStructure = DumpQueryStructureInfo(queryBuilder.ActiveSubQuery); data.UnionSubQuery = new UnionSubQueryExchangeClass(); data.UnionSubQuery.SelectedExpressions = DumpSelectedExpressionsInfoFromUnionSubQuery(queryBuilder.ActiveUnionSubQuery); data.UnionSubQuery.DataSources = DumpDataSourcesInfoFromUnionSubQuery(queryBuilder.ActiveUnionSubQuery); ; data.UnionSubQuery.Links = DumpLinksInfoFromUnionSubQuery(queryBuilder.ActiveUnionSubQuery); data.UnionSubQuery.Where = GetWhereInfo(queryBuilder.ActiveUnionSubQuery); queryBuilder.ExchangeData = data; }
/// <summary> /// Creates and initializes new instance of the QueryBuilder object if it doesn't exist. /// </summary> private void CreateQueryBuilder() { // Get an instance of the QueryBuilder object QueryBuilderStore.GetOrCreate("Webpack", queryBuilder => { queryBuilder.SyntaxProvider = new MSSQLSyntaxProvider(); // Denies metadata loading requests from live database connection queryBuilder.MetadataLoadingOptions.OfflineMode = true; // Load MetaData from XML document. File name is stored in the "Web.config" file in [/configuration/appSettings/NorthwindXmlMetaData] key var path = ConfigurationManager.AppSettings["NorthwindXmlMetaData"]; var xml = Path.Combine(Server.MapPath("~"), path); queryBuilder.MetadataContainer.ImportFromXML(xml); //Set default query queryBuilder.SQL = GetDefaultSql(); }); }
/// <summary> /// Creates and initializes new instance of the QueryBuilder object for the given identifier if it doesn't exist. /// </summary> /// <param name="name">Instance identifier of object in the current session.</param> /// <returns></returns> public ActionResult Create(string name) { try { // Create an instance of the QueryBuilder object QueryBuilderStore.GetOrCreate(name, qb => qb.SQL = GetDefaultSql()); // The necessary initialization procedures to setup SQL syntax and the source of metadata will be performed automatically // according to directives in the special configuration section of 'Web.config' file. // This behavior is enabled by the QueryBuilderStore.WebConfig() method call in the Application_Start method in Global.asax.cs file. // See qb.ConfiguredBy to get information about actual default settings } catch (Exception e) { return(new HttpStatusCodeResult(500, e.Message)); } return(new EmptyResult()); }
public IndexModule() { Get["/"] = parameters => { // Custom context based on the NancyContext to define data interchange rules with the client part of Active Query Builder IHttpContext httpContext = new NancyHttpContext(Context); // Get an instance of the QueryBuilder object according to the SessionID from the context. if (QueryBuilderStore.Get(httpContext, InstanceId) == null) { CreateQueryBuilder(httpContext); } return(View["index"]); }; // handling queries from the Active Query Builder clients Get["/{ActiveQueryBuilder*}"] = Handler; Post["/{ActiveQueryBuilder*}"] = Handler; }
public ActionResult Index() { // Get an instance of the QueryBuilder object var qb = QueryBuilderStore.Get(instanceId); var qt = QueryTransformerStore.Get(instanceId); if (qb == null) { qb = CreateQueryBuilder(); } if (qt == null) { qt = CreateQueryTransformer(qb.SQLQuery); } ViewBag.QueryTransformer = qt; return(View(qb)); }
private void SqlQueryOnSqlUpdated(object sender, EventArgs e) { var qb = QueryBuilderStore.Get(InstanceId); if (qb == null) { return; } var isRequiredPresent = qb.SQLQuery.QueryRoot.Items.OfType <UnionSubQuery>().Any(IsRequiredItemsPresent); if (!isRequiredPresent) { qb.Message.Warning("Required table and field is not present in the query."); } else { qb.Message.Clear(); } }
/// <summary> /// Creates and initializes new instance of the QueryBuilder object for the given identifier if it doesn't exist. /// </summary> /// <param name="name">Instance identifier of object in the current session.</param> /// <returns></returns> public ActionResult CreateQueryBuilder(string name) { // Get an instance of the QueryBuilder object var qb = QueryBuilderStore.Get(name); if (qb != null) { return(new HttpStatusCodeResult(200)); } try { // Create an instance of the QueryBuilder object QueryBuilderStore.Create(name); return(new HttpStatusCodeResult(200)); } catch (QueryBuilderException e) { return(new HttpStatusCodeResult(400, e.Message)); } }
public QueryBuilder ChangeConnection(string name) { var queryBuilder = QueryBuilderStore.Get(_instanceId); queryBuilder.MetadataContainer.Clear(); if (name == "NorthwindXmlMetaData") { SetNorthwindXml(queryBuilder); } else if (name == "SQLite") { SetSqLite(queryBuilder); } else { SetDb2Xml(queryBuilder); } return(queryBuilder); }
public override object GetDataForModel(Param[] _params) { var qb = QueryBuilderStore.Get("QueryResults"); var qt = QueryTransformerStore.Get("QueryResults"); var qtForSelectRecordsCount = QueryTransformerStore.Create("QueryResults_for_select_records_count"); qtForSelectRecordsCount.QueryProvider = qb.SQLQuery; qtForSelectRecordsCount.Assign(qt); qtForSelectRecordsCount.Skip(""); qtForSelectRecordsCount.Take(""); qtForSelectRecordsCount.SelectRecordsCount("recCount"); try { var data = GetData(qtForSelectRecordsCount, _params); return(data.First().Values.First()); } finally { QueryTransformerStore.Remove("QueryResults_for_select_records_count"); } }
/// <summary> /// Creates and initializes the second instance of the QueryBuilder object if it doesn't exist. /// </summary> private void CreateSecondQueryBuilder() { // Get an instance of the QueryBuilder object var queryBuilder = QueryBuilderStore.Get("SecondClient"); if (queryBuilder != null) { return; } // Create an instance of the QueryBuilder object queryBuilder = QueryBuilderStore.Factory.DB2("SecondClient"); // Denies metadata loading requests from the metadata provider queryBuilder.MetadataLoadingOptions.OfflineMode = true; // Load MetaData from XML document. File name is stored in the "Web.config" file in [/configuration/appSettings/db2_sample_with_alt_names] key var path = ConfigurationManager.AppSettings["Db2XmlMetaData"]; var xml = Path.Combine(Server.MapPath("~"), path); queryBuilder.MetadataContainer.ImportFromXML(xml); }
/// <summary> /// Creates and initializes new instance of the QueryBuilder object if it doesn't exist. /// </summary> private void CreateQueryBuilder() { // Get an instance of the QueryBuilder object if (QueryBuilderStore.Get("SimpleClient") != null) { return; } // Create an instance of the QueryBuilder object var queryBuilder = QueryBuilderStore.Factory.MsSql("SimpleClient"); // Denies metadata loading requests from the metadata provider queryBuilder.MetadataLoadingOptions.OfflineMode = true; // Load MetaData from XML document. File name is stored in the "Web.config" file in [/configuration/appSettings/NorthwindXmlMetaData] key var path = ConfigurationManager.AppSettings["NorthwindXmlMetaData"]; var xml = Path.Combine(Server.MapPath("~"), path); queryBuilder.MetadataContainer.ImportFromXML(xml); //Set default query queryBuilder.SQL = GetDefaultSql(); }
public override object GetDataForModel(Param[] _params) { var qb = QueryBuilderStore.Get("QueryResults"); var qt = QueryTransformerStore.Get("QueryResults"); var qtForSelectRecordsCount = new QueryTransformer { QueryProvider = qt.QueryProvider }; try { qtForSelectRecordsCount.Assign(qt); qtForSelectRecordsCount.Skip(""); qtForSelectRecordsCount.Take(""); qtForSelectRecordsCount.SelectRecordsCount("recCount"); var data = GetData(qtForSelectRecordsCount, _params); return(data.First().Values.First()); } finally { qtForSelectRecordsCount.Dispose(); } }
public void OnSQLUpdated(object sender, EventArgs e) { var qb = QueryBuilderStore.Get("AlternateNames"); var opts = new SQLFormattingOptions(); opts.Assign(qb.SQLFormattingOptions); opts.KeywordFormat = KeywordFormat.UpperCase; // get SQL query with real object names opts.UseAltNames = false; var plainSql = FormattedSQLBuilder.GetSQL(qb.SQLQuery.QueryRoot, opts); // get SQL query with alternate names opts.UseAltNames = true; var sqlWithAltNames = FormattedSQLBuilder.GetSQL(qb.SQLQuery.QueryRoot, opts); // prepare additional data to be sent to the client qb.ExchangeData = new { SQL = plainSql, AlternateSQL = sqlWithAltNames }; }
public void OnSQLUpdated(object sender, EventArgs e) { var qb = QueryBuilderStore.Get(InstanceId); var opts = new SQLFormattingOptions(); opts.Assign(qb.SQLFormattingOptions); opts.KeywordFormat = KeywordFormat.UpperCase; // get query with virtual objects and fields opts.ExpandVirtualObjects = false; var sqlWithVirtObjects = FormattedSQLBuilder.GetSQL(qb.SQLQuery.QueryRoot, opts); // get SQL query with real object names opts.ExpandVirtualObjects = true; var plainSql = FormattedSQLBuilder.GetSQL(qb.SQLQuery.QueryRoot, opts); // prepare additional data to be sent to the client qb.ExchangeData = new { SQL = plainSql, VirtualObjectsSQL = sqlWithVirtObjects }; }
////////////////////////////////////////////////////////////////////////// /// 3rd way: /// /// This method demonstrates loading of metadata through .NET data providers /// unsupported by our QueryBuilder component. If such data provider is able /// to execute SQL queries, you can use our EventMetadataProvider with handling /// it's ExecSQL event. In this event the EventMetadataProvider will provide /// you SQL queries it use for the metadata retrieval. You have to execute /// a query and return resulting data reader object. /// /// Note: In this sample we are using SQLiteSyntaxProvider. You have to use specific syntax providers in your application, /// e.g. MySQLSyntaxProver, OracleSyntaxProvider, etc. ////////////////////////////////////////////////////////////////////////// public void Way3() { var queryBuilder1 = QueryBuilderStore.Get(InstanceId); try { _conn.Close(); _conn.Open(); // allow QueryBuilder to request metadata queryBuilder1.MetadataLoadingOptions.OfflineMode = false; ResetQueryBuilderMetadata(queryBuilder1); queryBuilder1.SyntaxProvider = new SQLiteSyntaxProvider(); queryBuilder1.MetadataProvider = new EventMetadataProvider(); ((EventMetadataProvider)queryBuilder1.MetadataProvider).ExecSQL += way3EventMetadataProvider_ExecSQL; queryBuilder1.MetadataStructure.Refresh(); } catch (Exception ex) { queryBuilder1.Message.Error(ex.Message); } }
protected void Page_Load(object sender, EventArgs e) { // Get an instance of the QueryBuilder object var qb = QueryBuilderStore.GetOrCreate(InstanceId, InitializeQueryBuilder); QueryBuilderControl1.QueryBuilder = qb; ObjectTreeView1.QueryBuilder = qb; Canvas1.QueryBuilder = qb; Grid1.QueryBuilder = qb; SubQueryNavigationBar1.QueryBuilder = qb; SqlEditor1.QueryBuilder = qb; StatusBar1.QueryBuilder = qb; cbCompanyName.Enabled = cbCustomers.Checked; tbCompanyName.Enabled = cbCompanyName.Checked; cbOrderDate.Enabled = cbOrders.Checked; tbOrderDate.Enabled = cbOrderDate.Checked; //prepare parsed names _joinFieldName = qb.SQLContext.ParseQualifiedName(CusomerId); _companyNameFieldName = qb.SQLContext.ParseQualifiedName(CustomersCompanyName); _orderDateFieldName = qb.SQLContext.ParseQualifiedName(OrderDate); }
public void ApplyChanges(Model m) { var queryBuilder1 = QueryBuilderStore.Get(InstanceId); DataSource customers = null; DataSource orders = null; QueryColumnListItem _companyName = null; QueryColumnListItem _orderDate = null; //prepare parsed names SQLQualifiedName joinFieldName = queryBuilder1.SQLContext.ParseQualifiedName(CusomerId); SQLQualifiedName companyNameFieldName = queryBuilder1.SQLContext.ParseQualifiedName(CustomersCompanyName); SQLQualifiedName orderDateFieldName = queryBuilder1.SQLContext.ParseQualifiedName(OrderDate); // get the active SELECT var usq = queryBuilder1.ActiveUnionSubQuery; #region actualize stored references (if query is modified in GUI) #region actualize datasource references // if user removed previously added datasources then clear their references if (customers != null && !IsTablePresentInQuery(usq, customers)) { // user removed this table in GUI customers = null; } if (orders != null && !IsTablePresentInQuery(usq, orders)) { // user removed this table in GUI orders = null; } #endregion // clear CompanyName conditions if (_companyName != null) { // if user removed entire row OR cleared expression cell in GUI, clear the stored reference if (!IsQueryColumnListItemPresentInQuery(usq, _companyName)) _companyName = null; } // clear all condition cells for CompanyName row if (_companyName != null) { ClearConditionCells(usq, _companyName); } // clear OrderDate conditions if (_orderDate != null) { // if user removed entire row OR cleared expression cell in GUI, clear the stored reference if (!IsQueryColumnListItemPresentInQuery(usq, _orderDate)) _orderDate = null; } // clear all condition cells for OrderDate row if (_orderDate != null) { ClearConditionCells(usq, _orderDate); } #endregion #region process Customers table if (m.Customers) { // if we have no previously added Customers table, try to find one already added by the user if (customers == null) { customers = FindTableInQueryByName(usq, CustomersName); } // there is no Customers table in query, add it if (customers == null) { customers = AddTable(usq, CustomersName, CustomersAlias); } #region process CompanyName condition if (m.CompanyName && !String.IsNullOrEmpty(m.CompanyNameText)) { // if we have no previously added grid row for this condition, add it if (_companyName == null || _companyName.IsDisposing) { _companyName = usq.QueryColumnList.AddField(customers, companyNameFieldName.QualifiedName); // do not append it to the select list, use this row for conditions only _companyName.Selected = false; } // write condition from edit box to all needed grid cells AddWhereCondition(usq.QueryColumnList, _companyName, m.CompanyNameText); } else { // remove previously added grid row if (_companyName != null) { _companyName.Dispose(); } _companyName = null; } #endregion } else { // remove previously added datasource if (customers != null) { customers.Dispose(); } customers = null; } #endregion #region process Orders table if (m.Orders) { // if we have no previosly added Orders table, try to find one already added by the user if (orders == null) { orders = FindTableInQueryByName(usq, OrdersName); } // there are no Orders table in query, add one if (orders == null) { orders = AddTable(usq, OrdersName, OrdersAlias); } #region link between Orders and Customers // we added Orders table, // check if we have Customers table too, // and if there are no joins between them, create such join string joinFieldNameStr = joinFieldName.QualifiedName; if (customers != null && usq.FromClause.FindLink(orders, joinFieldNameStr, customers, joinFieldNameStr) == null && usq.FromClause.FindLink(customers, joinFieldNameStr, orders, joinFieldNameStr) == null) { queryBuilder1.SQLQuery.AddLink(customers, joinFieldName, orders, joinFieldName); } #endregion #region process OrderDate condition if (m.OrderDate && !String.IsNullOrEmpty(m.OrderDateText)) { // if we have no previously added grid row for this condition, add it if (_orderDate == null) { _orderDate = usq.QueryColumnList.AddField(orders, orderDateFieldName.QualifiedName); // do not append it to the select list, use this row for conditions only _orderDate.Selected = false; } // write condition from edit box to all needed grid cells AddWhereCondition(usq.QueryColumnList, _orderDate, m.OrderDateText); } else { // remove prviously added grid row if (_orderDate != null) { _orderDate.Dispose(); } _orderDate = null; } #endregion } else { if (orders != null) { orders.Dispose(); orders = null; } } #endregion }
private void OnPreLoad(object sender, EventArgs eventArgs) { QueryBuilderStore.Remove(); QueryTransformerStore.Remove(); }
private QueryBuilder GetOrCreateQueryBuilder() { // Get an instance of the QueryBuilder object return(QueryBuilderStore.GetOrCreate(qbId, InitializeQueryBuilder)); }
public void LoadUserQueries(string xml) { var qb = QueryBuilderStore.Get(id); qb.UserQueries.XML = xml; }
public void GetUserQueriesXml() { var qb = QueryBuilderStore.Get(id); qb.UserQueries.ExportToXML(Response.OutputStream); }
//CUT:PRO{{ public void DisposeStates() { QueryBuilderStore.Remove(); QueryTransformerStore.Remove(); }
////////////////////////////////////////////////////////////////////////// /// 4th way: /// This method demonstrates manual filling of metadata structure from /// stored DataSet. ////////////////////////////////////////////////////////////////////////// public void Way4(object sender, EventArgs e) { ActiveTabs = 3; var queryBuilder1 = QueryBuilderStore.Get("LoadMetadata"); ResetQueryBuilderMetadata(queryBuilder1); queryBuilder1.MetadataLoadingOptions.OfflineMode = true; // prevent QueryBuilder to request metadata from connection DataSet dataSet = new DataSet(); // Load sample dataset created in the Visual Studio with Dataset Designer // and exported to XML using WriteXmlSchema() method. var xml = Path.Combine(Server.MapPath("~"), "../Sample databases/StoredDataSetSchema.xml"); dataSet.ReadXmlSchema(xml); queryBuilder1.MetadataContainer.BeginUpdate(); try { queryBuilder1.ClearMetadata(); // add tables foreach (DataTable table in dataSet.Tables) { // add new metadata table MetadataObject metadataTable = queryBuilder1.MetadataContainer.AddTable(table.TableName); // add metadata fields (columns) foreach (DataColumn column in table.Columns) { // create new field MetadataField metadataField = metadataTable.AddField(column.ColumnName); // setup field metadataField.FieldType = TypeToDbType(column.DataType); metadataField.Nullable = column.AllowDBNull; metadataField.ReadOnly = column.ReadOnly; if (column.MaxLength != -1) { metadataField.Size = column.MaxLength; } // detect the field is primary key foreach (DataColumn pkColumn in table.PrimaryKey) { if (column == pkColumn) { metadataField.PrimaryKey = true; } } } // add relations foreach (DataRelation relation in table.ParentRelations) { // create new relation on the parent table MetadataForeignKey metadataRelation = metadataTable.AddForeignKey(relation.RelationName); // set referenced table using (MetadataQualifiedName referencedName = new MetadataQualifiedName()) { referencedName.Add(relation.ParentTable.TableName); metadataRelation.ReferencedObjectName = referencedName; } // set referenced fields foreach (DataColumn parentColumn in relation.ParentColumns) { metadataRelation.ReferencedFields.Add(parentColumn.ColumnName); } // set fields foreach (DataColumn childColumn in relation.ChildColumns) { metadataRelation.Fields.Add(childColumn.ColumnName); } } } } finally { queryBuilder1.MetadataContainer.EndUpdate(); } queryBuilder1.MetadataStructure.Refresh(); }
public ChangeConnectionController() { QueryBuilderStore.GetOrCreate(_instanceId); }