/// <summary> /// If any commands are present within the input string, then the command portion is /// replaced with the results of the command. Note that this is to work like a template. /// <para> /// • We're dealing with schema-info in the dataset and must convert from the schema info to /// a XML string of data that can be used as a DatabaseCollection with tables and fields. /// </para> /// <para> /// • The idea is to support SqlServer and Access databases (using OLE) natively /// </para> /// <remarks> /// I believe that this method is to parse a data-schema into a DataConfig. /// </remarks> /// </summary> /// <param name="input">is a string which might contain commands</param> /// <param name="ds">The DataSet containing relevant Schema information (Tables, Columns & DataType tables are required)</param> /// <returns>All recognized tags are replaced with the command values.</returns> static public string ParseSqlTemplate(string input, DataSet ds) { // Starting out with a clone of our input. string output = string.Copy(input); // Loop through and find all the matches foreach (Match m in input.getmatches()) { var list = new List <string>(); var tm = new tempmatch(m); if (tm.MethodsArray.Length != 3) { continue; } if ((tm.MethodsArray[0] == "list") && (tm.MethodsArray[1] == "columns")) { System.Windows.Forms.MessageBox.Show("listing cols"); foreach (DataRowView row in ds.Tables[Strings.Schema_Columns].DefaultView) { if (row["TABLE_NAME"].ToString().ToLower().Equals(tm.MethodsArray[2].ToLower())) { list.Add(string.Format("{0}", row["COLUMN_NAME"])); } } } else if ((tm.MethodsArray[0] == "list") && (tm.MethodsArray[1] == "tables")) { System.Windows.Forms.MessageBox.Show("listing tables"); foreach (DataRowView row in ds.Tables[Strings.Schema_Tables].DefaultView) { string tname = row["TABLE_NAME"].ToString(); if (ds.DataSetName == SchemaExtension.ole_ace12) { if (!IsNotAceSystem(tname)) { list.Add(string.Format("{0}", tname)); } else if (row["TABLE_CATALOG"].ToString().ToLower().Equals(tm.MethodsArray[2].ToLower())) { list.Add(string.Format("{0}", tname)); } } } } // PRIMARY SECTION else if ((tm.MethodsArray[0] == "show") && (tm.MethodsArray[1] == "tables")) { System.Windows.Forms.MessageBox.Show("show tables"); //%TABLE_CATALOG%,%TABLE_NAME%,%COLUMN_NAME%,%IS_NULLABLE% //%TABLE_SCHEMA%,%TABLE_NAME%,%TABLE_TYPE% foreach (DataRowView row in ds.Tables[Strings.Schema_Tables].DefaultView) { if (IsNotAceSystem(row["TABLE_NAME"].ToString())) { FieldElementLineFromRow(ds, row, list, tm); } } } string noob = string.Join("", list.ToArray()); output = output.Replace(tm.Range.Substring(input), noob); } return(Strings.Xml_DatabaseCollection.Replace( "{inner-content}", Strings.Xml_Database.Replace("{inner-content}", output) )); // list.Add(tm.Range.Substring(input),string.Format("{0}",ds.Tables[tm.Params])); }
/// <summary> /// This is the most important part of converting data from a schema to a DatabaseElement. /// It acts on a row that represents a table. /// </summary> /// <remarks> /// Used in ParseSqlTemplate; This only seems to work for SqlServer. /// </remarks> /// <param name="ds"></param> /// <param name="row">Schema: “Tables”</param> /// <param name="list"></param> /// <param name="tm"></param> static public void FieldElementLineFromRow(DataSet ds, DataRowView row, IList <string> list, tempmatch tm) { if (ds.DataSetName == SchemaExtension.ole_ace12) { // we need to know the data types; // var customers = CompiledQuery.Compile( // (ds.Tables["DATA_TYPES"] context, string filterCountry) => // from c in context.Customers // where c.Orders.Count > 5 // select c); string newport = Strings.Xml_Table .ReplaceFieldsT(ds, row, "TABLE_NAME", "TABLE_SCHEMA", "TABLE_TYPE") .Replace("{inner-content}", "".FilterColumns(ds, row["TABLE_NAME"].ToString(), true)); list.Add(newport); } // if this is the table that we're looking for else if (row["TABLE_CATALOG"].ToString().ToLower().Equals(tm.MethodsArray[2].ToLower())) { string newport = Strings.Tbl_TableElement .ReplaceFieldsT(ds, row, "TABLE_NAME", "TABLE_SCHEMA", "TABLE_TYPE") .Replace("{inner-content}", "".FilterColumns(ds, row["TABLE_NAME"].ToString())); list.Add(newport); } // this is not sound: a default action else { list.Add( "\n{tcatalog}, {tschema}, {tname}" .REPLACE( new REPLACEMENT("{tcatalog}", row.GetString("TABLE_CATALOG")), new REPLACEMENT("{tschema}", row.GetString("TABLE_SCHEMA")), new REPLACEMENT("{tname}", row.GetString("TABLE_NAME")) ) ); } }