public void MultipleValues() { // Creating node hierarchy. var node = new Node(); node.Add(new Node("table", "foo")); var values = new Node("values"); values.Add(new Node("field1", "howdy")); values.Add(new Node("field2", "world")); node.Add(values); var builder = new SqlCreateBuilder(node, "'"); // Extracting SQL + params, and asserting correctness. var result = builder.Build(); var sql = result.Get <string>(); Assert.Equal("insert into 'foo' ('field1', 'field2') values (@0, @1)", sql); var arg1 = result.Children.First(); Assert.Equal("@0", arg1.Name); Assert.Equal("howdy", arg1.Get <string>()); var arg2 = result.Children.Skip(1).First(); Assert.Equal("@1", arg2.Name); Assert.Equal("world", arg2.Get <string>()); }
/// <summary> /// Implementation of your slot. /// </summary> /// <param name="signaler">Signaler used to raise the signal.</param> /// <param name="input">Arguments to your slot.</param> public void Signal(ISignaler signaler, Node input) { var builder = new SqlCreateBuilder(input, "'"); var result = builder.Build(); input.Value = result.Value; input.Clear(); input.AddRange(result.Children.ToList()); }
public void NoValuesContent_Throws() { // Creating node hierarchy. var node = new Node(); node.Add(new Node("table", "foo")); var values = new Node("values"); node.Add(values); var builder = new SqlCreateBuilder(node, "'"); // Extracting SQL + params, and asserting correctness. Assert.Throws <ArgumentException>(() => builder.Build()); }
public void Signal(Node input) { var builder = new SqlCreateBuilder(input, _signaler); var sqlNode = builder.Build(); // Checking if this is a "build only" invocation. if (builder.IsGenerateOnly) { input.Value = sqlNode.Value; input.Clear(); input.AddRange(sqlNode.Children.ToList()); return; } // Executing SQL, now parametrized. Executor.Execute(sqlNode, _connections, _signaler, (cmd) => { // Notice, create SQL returns last inserted ID! input.Value = cmd.ExecuteScalar(); input.Clear(); }); }
public void GenerateArgument() { // Creating node hierarchy. var node = new Node(); node.Add(new Node("generate", true)); node.Add(new Node("table", "foo")); var values = new Node("values"); values.Add(new Node("field1", "howdy")); node.Add(values); var builder = new SqlCreateBuilder(node, "'"); // Extracting SQL + params, and asserting correctness. Assert.True(builder.IsGenerateOnly); var result = builder.Build(); var sql = result.Get <string>(); var arg1 = result.Children.First(); Assert.Equal("insert into 'foo' ('field1') values (@0)", sql); Assert.Equal("@0", arg1.Name); Assert.Equal("howdy", arg1.Get <string>()); }