/// <summary> /// Get a Datapoint from the database by its ID /// </summary> /// <returns> /// The DatapointNode instance or /// NULL if no datapoint node is present in the datbase /// </returns> public DatapointNode GetDatapointNodeByID(Int64 NodeID) { // Read the row with from the databse with the given ID ObjectTreeRow NodeRow = this.GetNodeByID(NodeID); // If there is no such row in the database return null if (NodeRow == null) { return(null); } // If there is such a row in the datbase create and return a DatapointNode Instance return(new DatapointNode(NodeRow)); }
/// <summary> /// A row of the object_tree table /// </summary> /// <param name="NodeID"> /// ID of the row in the database /// </param> /// <returns> /// A ObjectTreeRow instance that represents the database row or /// NULL if the row is not present in the datbase /// </returns> private ObjectTreeRow GetNodeByID(Int64 NodeID) { // Command that will be send to the databse MySqlCommand Command = this.Connection.CreateCommand(); // Reader to read the database answer MySqlDataReader Reader; // Get the row (tuple) from the datbase with a specific id // SELECT * > Get all columns of the table // FROM object_tree > Target table object_tree // WHERE object_id = {0} > Get all rows where the column object_id matches the given id // LIMIT 1 > Because the id is unique we can limit it to 1 row Command.CommandText = String.Format("SELECT * FROM object_tree WHERE object_id = {0} LIMIT 1", NodeID); Command.Connection = this.Connection; // Represents a row (tuple) of the object_tree table ObjectTreeRow NodeRow = null; // Execute the command and read the answer Reader = Command.ExecuteReader(); // Read the answer while (Reader.Read()) { string row = ""; for (int i = 0; i < (Reader.FieldCount); i++) { row += Reader.GetValue(i).ToString() + ","; } NodeRow = new ObjectTreeRow(row.Substring(0, row.Length - 1)); } Reader.Close(); // When there is no answer from the database (e.g. there is no row with the specific id) return null if (NodeRow == null) { return(null); } // Return the object that represents a row (tuple) of the object_tree table // Important: It is no Node Instance, that mean you have to create the corresponding Node Instance in a further step return(NodeRow); }
/// <summary> /// Get the root node from the database /// </summary> /// <returns> /// The RootNode Instance or /// NULL if no root node is present in the datbase /// </returns> public RootNode GetRootNode() { // Command that will be send to the databse MySqlCommand Command = this.Connection.CreateCommand(); // Reader to read the database answer MySqlDataReader Reader; // There can obly be one!!! root node so we can get the root node by the object type // SELECT * > Get all columns of the table // FROM object_tree > Target table object_tree // WHERE object_type = {0} > Get all rows where the column object_type matches the given id // LIMIT 1 > Because the id is unique we can limit it to 1 row Command.CommandText = "SELECT * FROM object_tree WHERE object_type = 1 LIMIT 1"; Command.Connection = this.Connection; // Represents a row (tuple) of the object_tree table ObjectTreeRow RootNodeRow = null; // Execute the command and read the answer Reader = Command.ExecuteReader(); // Read the answer while (Reader.Read()) { string row = ""; for (int i = 0; i < (Reader.FieldCount - 1); i++) { row += Reader.GetValue(i).ToString() + ","; } RootNodeRow = new ObjectTreeRow(row); } Reader.Close(); // When there is no answer from the database (e.g. there is no node root node) return null if (RootNodeRow == null) { return(null); } // Return the found root node as an RootNode Instance return(new RootNode(RootNodeRow)); }
public List <AbstractObjectNode> GetAllAbstractNodes() { // A list of all nodes in the database List <AbstractObjectNode> nodeList = new List <AbstractObjectNode>(); // Command that will be send to the databse MySqlCommand Command = this.Connection.CreateCommand(); // Reader to read the database answer MySqlDataReader Reader; // Get the row (tuple) from the datbase with a specific id // SELECT * > Get all columns of the table // FROM object_tree > Target table object_tree // WHERE object_id = {0} > Get all rows where the column object_id matches the given id // LIMIT 1 > Because the id is unique we can limit it to 1 row Command.CommandText = "SELECT * FROM object_tree ORDER BY object_name"; Command.Connection = this.Connection; // Represents a row (tuple) of the object_tree table ObjectTreeRow NodeRow = null; // Execute the command and read the answer Reader = Command.ExecuteReader(); // Read the answer while (Reader.Read()) { string row = ""; for (int i = 0; i < (Reader.FieldCount - 1); i++) { row += Reader.GetValue(i).ToString() + ","; } // RootNode = AbstracObjectNode nodeList.Add(new RootNode(new ObjectTreeRow(row))); } Reader.Close(); // Return the list with all nodes return(nodeList); }