public void Update(BaseEntity entity) { SqlStringGenerator stringgenerator = new SqlStringGenerator(this.mapinfo); Query updatequery = stringgenerator.GenerateUpdateQuery(entity, entity.Table.Name); updatequery.Excute(); }
public void GenerateInsertStringCanHandleGeometryObjects() { SqlStringGenerator gen = new SqlStringGenerator(); MappableEntity entity = new MappableEntity(); entity.obj = new Line(); string updatestring = gen.GenerateInsertString(entity, "DummyTable"); string expected = "INSERT INTO DummyTable (obj) VALUES (CreateLine(0,0,0,0))"; Assert.AreEqual(expected, updatestring); }
public void GenerateInsertStringCanHandleNullDatesAndStrings() { SqlStringGenerator gen = new SqlStringGenerator(); DummyEntity entity = new DummyEntity(); entity.ID = 100; entity.Name = null; entity.Time = null; string updatestring = gen.GenerateInsertString(entity, "DummyTable"); string expected = "INSERT INTO DummyTable (ID,Name,Time) VALUES (100,{0},{0})".FormatWith("".InQuotes()); Assert.AreEqual(expected, updatestring); }
public void GenerateInsertStringReturnsVaildString() { SqlStringGenerator gen = new SqlStringGenerator(); DummyEntity entity = new DummyEntity(); entity.ID = 100; entity.Name = "TestValue"; entity.Time = new DateTime(2009, 12, 01); string updatestring = gen.GenerateInsertString(entity, "DummyTable"); string expected = "INSERT INTO DummyTable (ID,Name,Time) VALUES (100,{0},{1})".FormatWith("TestValue".InQuotes(), "1/12/2009 12:00:00 AM".InQuotes()); Assert.AreEqual(expected, updatestring); }
/// <summary> /// Inserts a new row into the table. /// </summary> /// <param name="newRow"></param> public TEntity InsertRow(TEntity newRow) { Guard.AgainstNull(newRow, "newRow"); SqlStringGenerator sqlstringgen = new SqlStringGenerator(); string insertstring = sqlstringgen.GenerateInsertString(newRow, this.Name); this.tablecommandrunner.RunCommand(insertstring); IDataReader reader = ServiceLocator.GetInstance <IFactoryBuilder>().BuildDataReader(this.Name); reader.FetchLast(); TEntity row = new TEntity(); row.RowId = Convert.ToInt32(reader.Get("rowId")); return(row); }
public void GenerateInsertStringCanHandleGeometryObjects( [Values("DummyVar", "DummyTable.Obj")] string variableName) { Mock <IGeometry> mockobj = new Mock <IGeometry>(); mockobj.Setup(obj => obj.Variable.GetExpression()) .Returns(variableName); SqlStringGenerator gen = new SqlStringGenerator(); MappableEntity entity = new MappableEntity(); entity.obj = mockobj.Object; string updatestring = gen.GenerateInsertString(entity, "DummyTable"); string expected = "INSERT INTO DummyTable (obj) VALUES ({0})".FormatWith(variableName); Assert.AreEqual(expected, updatestring); }
/// <summary> /// Returns the Mapbasic insert commands needed to insert the supplied entity into the current table. /// </summary> /// <param name="entity">The entity that needs to be inserted, entity is not inserted just used to generate insert commands.</param> /// <returns>A string containing the needed Mapbasic commands to insert the entity into the current table.</returns> public string GetInsertString(BaseEntity entity) { SqlStringGenerator stringgenerator = new SqlStringGenerator(this.mapinfo); return(stringgenerator.GenerateInsertString(entity, this.Name)); }