SQLite Insert Row


Node Information
Inserts a row into the specified table with the specified name from the specified SQLite database.
General Information
• This node doesn't have other available options.
• Some of the ports of this node can change their types and accept types automatically.
Visual
Visual

Ports
Text Type DataType Accepts IsList CustomAcception
Insert IN RUN MULTIPLE FALSE FALSE
Database IN Object ONE FALSE FALSE
TableName IN String ONE FALSE FALSE
Entries IN List<SQLiteEntry> ONE TRUE TRUE

Source
namespace Korduene.KGraph.Nodes.Database.SQLite
{
    [IsNode("Insert Row")]
    public class InsertRow : Node
    {
        Port create = new Port(PortType.IN, typeof(RUN), AcceptsLinks.MULTIPLE, "Insert");
        Port db = new Port(PortType.IN, typeof(object), AcceptsLinks.ONE, "Database");
        Port tname = new Port(PortType.IN, typeof(string), AcceptsLinks.ONE, "TableName");
        Port entries = new Port(PortType.IN, typeof(List<korduene.database.sqlite.sqliteentry>), AcceptsLinks.ONE, "Entries");
        public InsertRow()
        {
            NodeType = KGraph.NodeType.Method;
            Name = "SQLite Insert Row";
            Dependency = DependencyLibraries.SQLITE;
            AddPort(create);
            AddPort(db);
            AddPort(tname);
            AddPort(entries);
            entries.CustomAcception = Accepts;
            Information = "Inserts a row into the specified table with the specified name from the specified SQLite database.";
        }
        bool Accepts(Port port)
        {
            if (port.DataType == typeof(List<korduene.database.sqlite.sqliteentry>))
            {
                entries.DataType = typeof(List<korduene.database.sqlite.sqliteentry>);
                entries.Accepts = AcceptsLinks.ONE;
                return true;
            }
            if (port.DataType == typeof(Korduene.Database.SQLite.SQLiteEntry))
            {
                entries.DataType = typeof(Korduene.Database.SQLite.SQLiteEntry);
                entries.Accepts = AcceptsLinks.MULTIPLE;
                return true;
            }
            return false;
        }
        public override string Code()
        {
            string code = string.Empty;
            if (entries.Accepts == AcceptsLinks.ONE)
            {
                code = GetValue(db) + ".InsertRow(" + GetValue(tname) + ", " + GetValue(entries) + ");";
            }
            else
            {
                string l = string.Empty;
                foreach (var port in entries.ConnectedPorts)
                {
#warning this a quick hack and should be fixed,.
                    l += port.ParentNode.ID + "(), ";
                }
                code = GetValue(db) + ".Insert(" + GetValue(tname) + ", new List<korduene.database.sqlite.sqliteentry>(){" + l + "});";
            }
            return code;
        }
        public override void UpdateResults()
        {
            Code();
        }
    }
}

</korduene.database.sqlite.sqliteentry></korduene.database.sqlite.sqliteentry></korduene.database.sqlite.sqliteentry></korduene.database.sqlite.sqliteentry>