Esempio n. 1
0
        /// <summary>
        ///		Insert a DatapointNode into the database
        /// </summary>
        /// <param name="Node">
        ///		DatapointNode that should be insert
        /// </param>
        /// <returns>
        ///		true, if a row was inserted
        ///		false, if no row was inserted
        /// </returns>
        public Boolean InsertNode(DatapointNode Node)
        {
            // Command that will be send to the databse
            MySqlCommand Command = this.Connection.CreateCommand();

            // Update a row in the databse with the given node id
            // UPDATE						> Update rows of a table
            // SET	[colum name] = [value],	> Set a column to the given value
            //		[colum name] = [value]	> Set a column to the given value
            // WHERE object_id = {0}		> Update all rows where the column object_id matches the given id
            Command.CommandText = String.Format(
                "INSERT INTO object_tree ( object_parent_id , object_type ,  object_name , object_description , object_last_updated , datapoint_type , datapoint_unit , datapoint_last_value , datapoint_last_updated ) Values( {0} , {1} , '{2}' , '{3}' , '{4}' , '{5}' , '{6}' , '{7}' , '{8}' )",
                Node.GetParentID(), DatapointNode.NODE_TYPE, Node.GetName(), Node.GetDescription(), Node.GetLastUpdated().ToString("yyyy-MM-dd HH:mm:ss"), Node.GetDatapointType().ToString(), Node.GetUnit(), Node.GetLastValue(), Node.GetLastValueUpdate().ToString("yyyy-MM-dd HH:mm:ss")
                );
            Command.Connection = this.Connection;

            // Execute the command and get the number of rows that are affected by the command
            Int32 AffectedRows = Command.ExecuteNonQuery();

            // Set the ID of the node to the ID that was provided by the database
            Node.SetID(Command.LastInsertedId);

            // If no rows where affected return false
            if (AffectedRows == 0)
            {
                return(false);
            }

            // Row successfully insert
            return(true);
        }