public void Delete() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <string>("@StringValue1", "Test String"); Helper.AddParameter <string>("@StringValue2", "Test String"); Helper.AddParameter <long>("@BigIntValue", 12345); Helper.AddParameter <bool>("@BitValue", true); Helper.AddParameter <decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter <float>("@FloatValue", 12345.6534f); Helper.AddParameter <Guid>("@GUIDValue", TempGuid); Helper.AddParameter <DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("delete from TestTable where @ID=ID", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <int>("@ID", 1); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.False(true, "Nothing was deleted"); } } }
public void CreateDatabase() { Database Database = new Database("TestDatabase"); Table TestTable = Database.AddTable("TestTable"); TestTable.AddColumn<string>("ID_", DbType.Int32); TestTable.AddColumn<string>("Value1", DbType.String, 100); TestTable.AddColumn<string>("Value2", DbType.Double); Utilities.SQL.SQLServer.SQLServer.CreateDatabase(Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(ID_,Value1,Value2) VALUES (@ID_,@Value1,@Value2)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<int>("@ID_", 1); Helper.AddParameter<string>("@Value1", "Test String"); Helper.AddParameter<float>("@Value2", 3.0f); Assert.Equal(1, Helper.ExecuteNonQuery()); } }
public void CreateDatabase() { Database Database = new Database("TestDatabase"); Table TestTable = Database.AddTable("TestTable"); TestTable.AddColumn <string>("ID_", DbType.Int32); TestTable.AddColumn <string>("Value1", DbType.String, 100); TestTable.AddColumn <string>("Value2", DbType.Double); Utilities.SQL.SQLServer.SQLServer.CreateDatabase(Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(ID_,Value1,Value2) VALUES (@ID_,@Value1,@Value2)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <int>("@ID_", 1); Helper.AddParameter <string>("@Value1", "Test String"); Helper.AddParameter <float>("@Value2", 3.0f); Assert.Equal(1, Helper.ExecuteNonQuery()); } }
public void CachedQuery() { Utilities.SQL.SQLHelper.ClearCache(); Guid TempGuid = Guid.NewGuid(); for (int x = 0; x < 100; ++x) { using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Assert.Equal(1, Helper.AddParameter <string>("@StringValue1", "Test String") .AddParameter <string>("@StringValue2", "Test String") .AddParameter <long>("@BigIntValue", 12345) .AddParameter <bool>("@BitValue", true) .AddParameter <decimal>("@DecimalValue", 1234.5678m) .AddParameter <float>("@FloatValue", 12345.6534f) .AddParameter <Guid>("@GUIDValue", TempGuid) .AddParameter <DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)) .ExecuteNonQuery()); } } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(Cache: true); int Count = 0; while (Helper.Read()) { ++Count; Assert.Equal("Test String", Helper.GetParameter <string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter <string>("StringValue2", "")); Assert.Equal(12345, Helper.GetParameter <long>("BigIntValue", 0)); Assert.Equal(true, Helper.GetParameter <bool>("BitValue", false)); Assert.Equal(1234.5678m, Helper.GetParameter <decimal>("DecimalValue", 0)); Assert.Equal(12345.6534f, Helper.GetParameter <float>("FloatValue", 0)); Assert.Equal(TempGuid, Helper.GetParameter <Guid>("GUIDValue", TempGuid)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter <DateTime>("DateTimeValue", DateTime.Now)); } Assert.Equal(100, Count); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(Cache: true); int Count = 0; while (Helper.Read()) { ++Count; Assert.Equal("Test String", Helper.GetParameter <string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter <string>("StringValue2", "")); Assert.Equal(12345, Helper.GetParameter <long>("BigIntValue", 0)); Assert.Equal(true, Helper.GetParameter <bool>("BitValue", false)); Assert.Equal(1234.5678m, Helper.GetParameter <decimal>("DecimalValue", 0)); Assert.Equal(12345.6534f, Helper.GetParameter <float>("FloatValue", 0)); Assert.Equal(TempGuid, Helper.GetParameter <Guid>("GUIDValue", TempGuid)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter <DateTime>("DateTimeValue", DateTime.Now)); } Assert.Equal(100, Count); } }
public void Creation() { Utilities.SQL.ParameterTypes.AndParameter TestObject = new Utilities.SQL.ParameterTypes.AndParameter(new EqualParameter<int>(1, "Left"), new EqualParameter<int>(2, "Right")); Assert.Equal("(Left=@Left AND Right=@Right)", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter(TestObject); } }
public void Creation() { Utilities.SQL.ParameterTypes.AndParameter TestObject = new Utilities.SQL.ParameterTypes.AndParameter(new EqualParameter <int>(1, "Left"), new EqualParameter <int>(2, "Right")); Assert.Equal("(Left=@Left AND Right=@Right)", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Assert.DoesNotThrow(() => Helper.AddParameter(TestObject)); } }
public void Creation() { EqualParameter<int> TestObject = new EqualParameter<int>(12, "ID"); Assert.Equal("ID", TestObject.ID); Assert.Equal(12, TestObject.Value); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID=@ID", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Assert.DoesNotThrow(() => Helper.AddParameter(TestObject)); } }
public void ClearParameters() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <string>("@StringValue1", "Test") .AddParameter <string>("@StringValue2", "Test") .AddParameter <long>("@BigIntValue", 123) .AddParameter <bool>("@BitValue", false) .AddParameter <decimal>("@DecimalValue", 1234) .AddParameter <float>("@FloatValue", 12345) .AddParameter <Guid>("@GUIDValue", Guid.NewGuid()) .AddParameter <DateTime>("@DateTimeValue", new DateTime(1999, 1, 1)) .ClearParameters(); Helper.AddParameter <string>("@StringValue1", "Test String"); Helper.AddParameter <string>("@StringValue2", "Test String"); Helper.AddParameter <long>("@BigIntValue", 12345); Helper.AddParameter <bool>("@BitValue", true); Helper.AddParameter <decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter <float>("@FloatValue", 12345.6534f); Helper.AddParameter <Guid>("@GUIDValue", TempGuid); Helper.AddParameter <DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter <string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter <string>("StringValue2", "")); Assert.Equal(12345, Helper.GetParameter <long>("BigIntValue", 0)); Assert.Equal(true, Helper.GetParameter <bool>("BitValue", false)); Assert.Equal(1234.5678m, Helper.GetParameter <decimal>("DecimalValue", 0)); Assert.Equal(12345.6534f, Helper.GetParameter <float>("FloatValue", 0)); Assert.Equal(TempGuid, Helper.GetParameter <Guid>("GUIDValue", Guid.Empty)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter <DateTime>("DateTimeValue", DateTime.Now)); } else { Assert.False(true, "Nothing was inserted"); } } }
public void Creation() { NotEqualParameter <int> TestObject = new NotEqualParameter <int>(12, "ID"); Assert.Equal("ID", TestObject.ID); Assert.Equal(12, TestObject.Value); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID<>@ID", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter(TestObject); } }
public void Creation() { BetweenParameter<int> TestObject = new BetweenParameter<int>(10, 12, "ID"); Assert.Equal("ID", TestObject.ID); Assert.Equal(10, TestObject.Min); Assert.Equal(12, TestObject.Max); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID BETWEEN @IDMin AND @IDMax", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter(TestObject); } }
public void Creation() { Utilities.SQL.ParameterTypes.StringEqualParameter TestObject = new Utilities.SQL.ParameterTypes.StringEqualParameter("ASDF", "ID", 100); Assert.Equal("ID", TestObject.ID); Assert.Equal("ASDF", TestObject.Value); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID=@ID", TestObject.ToString()); Assert.Equal(100, TestObject.Length); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter(TestObject); } }
public void Creation() { BetweenParameter <int> TestObject = new BetweenParameter <int>(10, 12, "ID"); Assert.Equal("ID", TestObject.ID); Assert.Equal(10, TestObject.Min); Assert.Equal(12, TestObject.Max); Assert.Equal("@", TestObject.ParameterStarter); Assert.Equal("ID BETWEEN @IDMin AND @IDMax", TestObject.ToString()); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false")) { Assert.DoesNotThrow(() => Helper.AddParameter(TestObject)); } }
public void MBDBug() { string ConnectionString = string.Format("Data Source=localhost;Initial Catalog=Master;Integrated Security=SSPI;Pooling=false"); string CommandString = "SELECT database_id FROM Master.sys.Databases WHERE name=@Name"; using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(CommandString, CommandType.Text, ConnectionString)) { Utilities.SQL.MicroORM.Parameter <string> Parameter = new Utilities.SQL.MicroORM.Parameter <string>("@Name", DbType.String, "TestDatabase", ParameterDirection.Input, "@"); Helper.AddParameter(Parameter); int DbID = Helper.ExecuteScalar <int>(); Assert.True(DbID > 0); } Assert.True(Utilities.SQL.SQLServer.SQLServer.DoesDatabaseExist("TestDatabase", ConnectionString)); Assert.False(Utilities.SQL.SQLServer.SQLServer.DoesDatabaseExist(null, ConnectionString)); }
public void UpdateDatabase() { Database Database = new Database("TestDatabase"); Table TestTable = Database.AddTable("TestTable"); TestTable.AddColumn <string>("ID_", DbType.Int32); TestTable.AddColumn <string>("Value1", DbType.String, 100); TestTable.AddColumn <string>("Value2", DbType.Double); Utilities.SQL.SQLServer.SQLServer.CreateDatabase(Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Database Database2 = new Database("TestDatabase"); TestTable = Database2.AddTable("TestTable"); TestTable.AddColumn <string>("ID_", DbType.Int32); TestTable.AddColumn <string>("Value1", DbType.String, 100); TestTable.AddColumn <string>("Value2", DbType.Double); TestTable.AddColumn <string>("Value3", DbType.Boolean); Utilities.SQL.SQLServer.SQLServer.UpdateDatabase(Database2, Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(ID_,Value1,Value2,Value3) VALUES (@ID_,@Value1,@Value2,@Value3)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <int>("@ID_", 1); Helper.AddParameter <string>("@Value1", "Test String"); Helper.AddParameter <float>("@Value2", 3.0f); Helper.AddParameter <bool>("@Value3", true); Assert.Equal(1, Helper.ExecuteNonQuery()); } Database Database3 = Utilities.SQL.SQLServer.SQLServer.GetDatabaseStructure("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Assert.Equal(Database2.Tables.First().Name, Database3.Tables.First().Name); Assert.Equal(Database2.Tables.First().Columns.Count, Database3.Tables.First().Columns.Count); Assert.Equal(DbType.Int32, Database3.Tables.First().Columns.First(x => x.Name == "ID_").DataType); Assert.Equal(DbType.String, Database3.Tables.First().Columns.First(x => x.Name == "Value1").DataType); Assert.Equal(DbType.Double, Database3.Tables.First().Columns.First(x => x.Name == "Value2").DataType); Assert.Equal(100, Database3.Tables.First().Columns.First(x => x.Name == "Value1").Length); Assert.Equal(4, Database3.Tables.First().Columns.First(x => x.Name == "ID_").Length); Assert.Equal(8, Database3.Tables.First().Columns.First(x => x.Name == "Value2").Length); }
public void OutputParamter() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <string>("@StringValue1", "Test String"); Helper.AddParameter <string>("@StringValue2", "Test String"); Helper.AddParameter <long>("@BigIntValue", 12345); Helper.AddParameter <bool>("@BitValue", true); Helper.AddParameter <decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter <float>("@FloatValue", 12345.6534f); Helper.AddParameter <Guid>("@GUIDValue", TempGuid); Helper.AddParameter <DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SET @ASD=12345", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter <long>("@ASD", Direction: ParameterDirection.Output); Helper.ExecuteNonQuery(); Assert.Equal(12345, Helper.GetParameter <long>("@ASD", 0, ParameterDirection.Output)); } }
public void OutputParamter() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<string>("@StringValue1", "Test String"); Helper.AddParameter<string>("@StringValue2", "Test String"); Helper.AddParameter<long>("@BigIntValue", 12345); Helper.AddParameter<bool>("@BitValue", true); Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter<float>("@FloatValue", 12345.6534f); Helper.AddParameter<Guid>("@GUIDValue", TempGuid); Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SET @ASD=12345", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<long>("@ASD", Direction: ParameterDirection.Output); Helper.ExecuteNonQuery(); Assert.Equal(12345, Helper.GetParameter<long>("@ASD", 0, ParameterDirection.Output)); } }
public void UpdateDatabase() { Database Database = new Database("TestDatabase"); Table TestTable = Database.AddTable("TestTable"); TestTable.AddColumn<string>("ID_", DbType.Int32); TestTable.AddColumn<string>("Value1", DbType.String, 100); TestTable.AddColumn<string>("Value2", DbType.Double); Utilities.SQL.SQLServer.SQLServer.CreateDatabase(Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Database Database2 = new Database("TestDatabase"); TestTable = Database2.AddTable("TestTable"); TestTable.AddColumn<string>("ID_", DbType.Int32); TestTable.AddColumn<string>("Value1", DbType.String, 100); TestTable.AddColumn<string>("Value2", DbType.Double); TestTable.AddColumn<string>("Value3", DbType.Boolean); Utilities.SQL.SQLServer.SQLServer.UpdateDatabase(Database2, Database, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(ID_,Value1,Value2,Value3) VALUES (@ID_,@Value1,@Value2,@Value3)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<int>("@ID_", 1); Helper.AddParameter<string>("@Value1", "Test String"); Helper.AddParameter<float>("@Value2", 3.0f); Helper.AddParameter<bool>("@Value3", true); Assert.Equal(1, Helper.ExecuteNonQuery()); } Database Database3 = Utilities.SQL.SQLServer.SQLServer.GetDatabaseStructure("Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"); Assert.Equal(Database2.Tables.First().Name, Database3.Tables.First().Name); Assert.Equal(Database2.Tables.First().Columns.Count, Database3.Tables.First().Columns.Count); Assert.Equal(DbType.Int32, Database3.Tables.First().Columns.First(x => x.Name == "ID_").DataType); Assert.Equal(DbType.String, Database3.Tables.First().Columns.First(x => x.Name == "Value1").DataType); Assert.Equal(DbType.Double, Database3.Tables.First().Columns.First(x => x.Name == "Value2").DataType); Assert.Equal(100, Database3.Tables.First().Columns.First(x => x.Name == "Value1").Length); Assert.Equal(4, Database3.Tables.First().Columns.First(x => x.Name == "ID_").Length); Assert.Equal(8, Database3.Tables.First().Columns.First(x => x.Name == "Value2").Length); }
public void CachedQuery() { Utilities.SQL.SQLHelper.ClearCache(); Guid TempGuid = Guid.NewGuid(); for (int x = 0; x < 100; ++x) { using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Assert.Equal(1, Helper.AddParameter<string>("@StringValue1", "Test String") .AddParameter<string>("@StringValue2", "Test String") .AddParameter<long>("@BigIntValue", 12345) .AddParameter<bool>("@BitValue", true) .AddParameter<decimal>("@DecimalValue", 1234.5678m) .AddParameter<float>("@FloatValue", 12345.6534f) .AddParameter<Guid>("@GUIDValue", TempGuid) .AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)) .ExecuteNonQuery()); } } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(Cache: true); int Count = 0; while (Helper.Read()) { ++Count; Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", "")); Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0)); Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false)); Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0)); Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0)); Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", TempGuid)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now)); } Assert.Equal(100, Count); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(Cache: true); int Count = 0; while (Helper.Read()) { ++Count; Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", "")); Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0)); Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false)); Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0)); Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0)); Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", TempGuid)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now)); } Assert.Equal(100, Count); } }
public void Delete() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<string>("@StringValue1", "Test String"); Helper.AddParameter<string>("@StringValue2", "Test String"); Helper.AddParameter<long>("@BigIntValue", 12345); Helper.AddParameter<bool>("@BitValue", true); Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter<float>("@FloatValue", 12345.6534f); Helper.AddParameter<Guid>("@GUIDValue", TempGuid); Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("delete from TestTable where @ID=ID", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<int>("@ID", 1); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.False(true, "Nothing was deleted"); } } }
public void Update() { Guid TempGuid = Guid.NewGuid(); using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@StringValue1,@StringValue2,@BigIntValue,@BitValue,@DecimalValue,@FloatValue,@DateTimeValue,@GUIDValue)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<string>("@StringValue1", "Test"); Helper.AddParameter<string>("@StringValue2", "Test"); Helper.AddParameter<long>("@BigIntValue", 123); Helper.AddParameter<bool>("@BitValue", false); Helper.AddParameter<decimal>("@DecimalValue", 1234); Helper.AddParameter<float>("@FloatValue", 12345); Helper.AddParameter<Guid>("@GUIDValue", Guid.NewGuid()); Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 1, 1)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("update TestTable set StringValue1=@StringValue1,StringValue2=@StringValue2,BigIntValue=@BigIntValue,BitValue=@BitValue,DecimalValue=@DecimalValue,FloatValue=@FloatValue,DateTimeValue=@DateTimeValue,GUIDValue=@GUIDValue", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.AddParameter<string>("@StringValue1", "Test String"); Helper.AddParameter<string>("@StringValue2", "Test String"); Helper.AddParameter<long>("@BigIntValue", 12345); Helper.AddParameter<bool>("@BitValue", true); Helper.AddParameter<decimal>("@DecimalValue", 1234.5678m); Helper.AddParameter<float>("@FloatValue", 12345.6534f); Helper.AddParameter<Guid>("@GUIDValue", TempGuid); Helper.AddParameter<DateTime>("@DateTimeValue", new DateTime(1999, 12, 31)); Helper.ExecuteNonQuery(); } using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("SELECT * FROM TestTable", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false")) { Helper.ExecuteReader(); if (Helper.Read()) { Assert.Equal("Test String", Helper.GetParameter<string>("StringValue1", "")); Assert.Equal("Test String", Helper.GetParameter<string>("StringValue2", "")); Assert.Equal(12345, Helper.GetParameter<long>("BigIntValue", 0)); Assert.Equal(true, Helper.GetParameter<bool>("BitValue", false)); Assert.Equal(1234.5678m, Helper.GetParameter<decimal>("DecimalValue", 0)); Assert.Equal(12345.6534f, Helper.GetParameter<float>("FloatValue", 0)); Assert.Equal(TempGuid, Helper.GetParameter<Guid>("GUIDValue", Guid.Empty)); Assert.Equal(new DateTime(1999, 12, 31), Helper.GetParameter<DateTime>("DateTimeValue", DateTime.Now)); } else { Assert.False(true, "Nothing was inserted"); } } }
public void MBDBug() { string ConnectionString = string.Format("Data Source=localhost;Initial Catalog=Master;Integrated Security=SSPI;Pooling=false"); string CommandString = "SELECT database_id FROM Master.sys.Databases WHERE name=@Name"; using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(CommandString, CommandType.Text, ConnectionString)) { Utilities.SQL.MicroORM.Parameter<string> Parameter = new Utilities.SQL.MicroORM.Parameter<string>("@Name", DbType.String, "TestDatabase", ParameterDirection.Input, "@"); Helper.AddParameter(Parameter); int DbID = Helper.ExecuteScalar<int>(); Assert.True(DbID > 0); } Assert.True(Utilities.SQL.SQLServer.SQLServer.DoesDatabaseExist("TestDatabase", ConnectionString)); Assert.False(Utilities.SQL.SQLServer.SQLServer.DoesDatabaseExist(null, ConnectionString)); }