//c# //These statements load code libraries that make basic functions (in this case, arrays for instance) work. //You will know to add more when you reference and object and which throws and error that asks if you are //missing a reference. using System; using System.Collections.Generic; //This is the class that contains all the code. This is what you need to put all of the example code in to //make it run. The name "Script" is not important, its the container that counts. class Script { //This helps set up the Manifold environment (probably not stated exactly correctly). static Manifold.Context Manifold; //This is the entry point for the whole program. Every C# program has to have one. static void Main() { //Declare the Manifold Application object and name it app. Manifold.Application app = Manifold.Application; //Declare the Manifold Database object and name it db. //Also use the 'using' keyword for quick garbage disposal. Different reason for using the same //"using" statement at the top. using (Manifold.Database db = app.GetDatabaseRoot()) { //Declare the Manifold Schema object and name it schema. Manifold.Schema schema = app.CreateSchema(); //Create a string variable to hold the table name. string nameOfTableToAdd = "tableProperties"; //Add TableName, ColumnName, and ColumnType column names to schema. schema.AddField("TableName", "nvarchar"); schema.AddField("ColumnName", "nvarchar"); schema.AddField("ColumnType", "nvarchar"); //Create a table calling Database Insert and name the table tableProperties. db.Insert(nameOfTableToAdd, "table", schema); //Declare another table (different to the mfd_root table we are going to read from) to write to. Manifold.Table propsTable = db.Search(nameOfTableToAdd); //Get a handle on the Manifold Root table and name it rootTable. //Using "using" again here is totally not necessary as the outer one will call garbage soon enough. //Just left them in here from the examples. using (Manifold.Table rootTable = db.Search("mfd_root")) { //Create a string array named fields with two fields, Name and Type to hold data from the root table. string[] fields = new string[] { "Name", "Type" }; //Get a sequence call it sequence and then make a call to SearchAll and dump the data into the fields array. using (Manifold.Sequence sequence = rootTable.SearchAll(fields)) { //Call Fetch repeatedly. while (sequence.Fetch()) { //Get the first and second values from fetch and put them in compName and compType respectively. string compName = sequence.GetValues()[0].Data.ToString(); string compType = sequence.GetValues()[1].Data.ToString(); //Check for the two Manifold tables at the root and skip them. if(compName.StartsWith("mfd_")) { //Message box for troubleshooting. Comment out when no longer needed. //app.MessageBox("Found root table " + compName + ".", "Message"); } //Check to make sure the component is of type table. Other possible component types are in the mfd_root table. //If you wanted to look for a different component type, you would change it here. else if(compType == "table") { //Log compName for troubleshooting. Comment it out when no longer needed. app.Log(compName + " is a table."); //Search the table compName and put it's schema into the tableSchema variable. using (Manifold.Table tableSchema = db.Search(compName)) { //Get a handle on a schema named schemaTwo to hold the table components from the GetSchema function. Manifold.Schema schemaTwo = tableSchema.GetSchema(); //Call the fields function of the schema once for each row that exists. foreach (Manifold.Schema.Field field in schemaTwo.Fields) { //Log for troubleshooting. Comment out when no longer needed. //app.Log(field.Name + " : " + field.Type); //Set up a valueSet named values. Manifold.ValueSet values = app.CreateValueSet(); //Start adding values to the valueSet values. values.AddValue("TableName", compName); values.AddValue("ColumnName", field.Name); values.AddValue("ColumnType", field.Type); //Add the values to the table. long result = propsTable.Insert(values); } } } } } } //Message Box for end of process notification. Update as necessary. app.MessageBox("Table created!", "Message"); } } }
|