/// <summary> /// Adds a new parameter with the specified name and value. The name will be /// parsed to extract table and keyspace information (if any). The parameter type /// will be guessed from the object value. /// </summary> /// <param name="name">The name.</param> /// <param name="value">The value.</param> /// <returns>The created <see cref="CqlParameter"/>.</returns> public CqlParameter Add(string name, object value) { var parameter = new CqlParameter(name, value); Add(parameter); return(parameter); }
public void TestCqlParameter() { var name = "p1"; var value = 1; var target = new CqlParameter(name, value); // test ParameterName var formattedName = ":p1"; var name2 = ":p2"; Assert.AreEqual(formattedName, target.ParameterName); target.ParameterName = name2; Assert.AreEqual(name2, target.ParameterName); // test IsNullable & SourceColumnNullMapping Assert.IsTrue(target.IsNullable); Assert.IsTrue(target.SourceColumnNullMapping); target.IsNullable = false; Assert.IsFalse(target.IsNullable); Assert.IsFalse(target.SourceColumnNullMapping); // test Direction, only Input is supported Assert.AreEqual(ParameterDirection.Input, target.Direction); Exception ex = null; try { target.Direction = ParameterDirection.Output; } catch (Exception e) { ex = e; } Assert.IsNotNull(ex); // test Value Assert.AreEqual(value, target.Value); var value2 = "2"; target.Value = value2; Assert.AreEqual(value2, target.Value); // test Size, it should always return 0 Assert.AreEqual(0, target.Size); target.Size = 1; Assert.AreEqual(0, target.Size); }
private void SetParameter(int index, CqlParameter value) { _parameters[index] = value; }
private void SetParameter(string parameterName, CqlParameter value) { int index = GetIndex(parameterName); _parameters[index] = value; }
/// <summary> /// Adds the specified parameter. /// </summary> /// <param name="parameter">The parameter.</param> /// <returns> </returns> public int Add(CqlParameter parameter) { _parameters.Add(parameter); return(_parameters.Count - 1); }
/// <summary> /// Adds a new parameter with the specified name and value. The name will be /// parsed to extract table and keyspace information (if any). The parameter type /// will be guessed from the object value. /// </summary> /// <param name="name">The name.</param> /// <param name="value">The value.</param> /// <returns>The created <see cref="CqlParameter"/>.</returns> public CqlParameter Add(string name, object value) { var parameter = new CqlParameter(name, value); Add(parameter); return parameter; }
/// <summary> /// Adds the specified parameter. /// </summary> /// <param name="parameter">The parameter.</param> /// <returns> </returns> public int Add(CqlParameter parameter) { _parameters.Add(parameter); return _parameters.Count - 1; }
public void TestCqlParameterCollection() { var target = new CqlParameterCollection(); // test Count NUnit.Framework.Assert.AreEqual(0, target.Count); var p1 = target.Add("p1", 1); Assert.AreEqual(1, target.Count); // test SyncRoot Assert.IsNotNull(target.SyncRoot); Assert.AreEqual(target.SyncRoot, target.SyncRoot); // test IsFixedSize Assert.IsFalse(target.IsFixedSize); // test IsReadOnly Assert.IsFalse(target.IsReadOnly); // test IsSynchronized Assert.IsFalse(target.IsSynchronized); // test Add() var p2Index = target.Add(new CqlParameter("p2")); Assert.AreEqual(2, target.Count); Assert.AreEqual(1, p2Index); // test Contains() var p3 = new CqlParameter("p3"); Assert.IsTrue(target.Contains(p1)); Assert.IsFalse(target.Contains(p3)); // test IndexOf() Assert.AreEqual(0, target.IndexOf(p1)); // test Insert(); target.Insert(0, p3); Assert.AreEqual(0, target.IndexOf(p3)); Assert.AreEqual(1, target.IndexOf(p1)); // test Remove() var toBeRemove = new CqlParameter("toberemoved"); target.Add(toBeRemove); Assert.IsTrue(target.Contains(toBeRemove)); target.Remove(toBeRemove); Assert.IsFalse(target.Contains(toBeRemove)); // test RemoveAt() target.RemoveAt(0); Assert.AreEqual(2, target.Count); target.RemoveAt("p2"); Assert.IsFalse(target.Contains("p2")); // test CopyTo() var arr = new CqlParameter[1]; target.CopyTo(arr, 0); Assert.AreEqual(arr[0], target[0]); // test AddRange() var p4p5 = new[] { new CqlParameter("p4"), new CqlParameter("p5") }; target.AddRange(p4p5); Assert.AreEqual(3, target.Count); Assert.IsTrue(target.Contains(p4p5[0])); Assert.IsTrue(target.Contains(p4p5[1])); // test Clear() target.Clear(); Assert.AreEqual(0, target.Count); }