コード例 #1
0
 public void Dispose()
 {
     Utilities.ORM.ORM.Destroy();
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("ALTER DATABASE ORMTestDatabase3 SET OFFLINE WITH ROLLBACK IMMEDIATE", "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false", CommandType.Text))
     {
         Helper.ExecuteNonQuery();
         Helper.Command = "ALTER DATABASE ORMTestDatabase3 SET ONLINE";
         Helper.ExecuteNonQuery();
         Helper.Command = "DROP DATABASE ORMTestDatabase3";
         Helper.ExecuteNonQuery();
     }
 }
コード例 #2
0
        public void CommandInsertNullString()
        {
            Guid TempGuid = Guid.NewGuid();

            Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid);
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
            {
                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("This is a null string", Helper.GetParameter <string>("StringValue2", "This is a null string"));
                    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");
                }
            }
        }
コード例 #3
0
        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");
                }
            }
        }
コード例 #4
0
 public virtual void Dispose()
 {
     Utilities.ORM.ORM.Destroy();
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.Batch().AddCommand("ALTER DATABASE ORMTestDatabase3 SET OFFLINE WITH ROLLBACK IMMEDIATE", CommandType.Text)
             .AddCommand("ALTER DATABASE ORMTestDatabase3 SET ONLINE", CommandType.Text)
             .AddCommand("DROP DATABASE ORMTestDatabase3", CommandType.Text);
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.Batch().AddCommand("ALTER DATABASE ORMTestDatabase2 SET OFFLINE WITH ROLLBACK IMMEDIATE", CommandType.Text)
             .AddCommand("ALTER DATABASE ORMTestDatabase2 SET ONLINE", CommandType.Text)
             .AddCommand("DROP DATABASE ORMTestDatabase2", CommandType.Text);
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.Batch().AddCommand("ALTER DATABASE ORMTestDatabase SET OFFLINE WITH ROLLBACK IMMEDIATE", CommandType.Text)
             .AddCommand("ALTER DATABASE ORMTestDatabase SET ONLINE", CommandType.Text)
             .AddCommand("DROP DATABASE ORMTestDatabase", CommandType.Text);
         Helper.ExecuteNonQuery();
     }
 }
コード例 #5
0
        public void Execute()
        {
            Guid TempGuid = Guid.NewGuid();

            Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid);
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
            {
                for (int x = 0; x < 100; ++x)
                {
                    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"))
            {
                bool Inserted = false;
                foreach (dynamic Object in Helper.Execute())
                {
                    Inserted = true;
                    Assert.Equal("Test String", Object.StringValue1);
                    Assert.Equal <string>(null, (string)Object.StringValue2);
                    Assert.Equal(12345, Object.BigIntValue);
                    Assert.Equal(true, Object.BitValue);
                    Assert.Equal(1234.5678m, Object.DecimalValue);
                    Assert.Equal(12345.6534f, Object.FloatValue);
                    Assert.Equal(TempGuid, Object.GUIDValue);
                    Assert.Equal(new DateTime(1999, 12, 31), Object.DateTimeValue);
                }
                if (!Inserted)
                {
                    Assert.False(true, "Nothing was inserted");
                }
            }
        }
コード例 #6
0
 public void Dispose()
 {
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("", CommandType.Text, "Data Source=localhost;Initial Catalog=master;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.Batch().AddCommand("ALTER DATABASE TestDatabase SET OFFLINE WITH ROLLBACK IMMEDIATE", CommandType.Text)
         .AddCommand("ALTER DATABASE TestDatabase SET ONLINE", CommandType.Text)
         .AddCommand("DROP DATABASE TestDatabase", CommandType.Text);
         Helper.ExecuteNonQuery();
     }
 }
コード例 #7
0
 public SQLHelper()
 {
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Database TestDatabase", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Table TestTable(ID INT PRIMARY KEY IDENTITY,StringValue1 NVARCHAR(100),StringValue2 NVARCHAR(MAX),BigIntValue BIGINT,BitValue BIT,DecimalValue DECIMAL(12,6),FloatValue FLOAT,DateTimeValue DATETIME,GUIDValue UNIQUEIDENTIFIER)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteNonQuery();
     }
 }
コード例 #8
0
 public SQLHelper()
 {
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Database TestDatabase", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Table TestTable(ID INT PRIMARY KEY IDENTITY,StringValue1 NVARCHAR(100),StringValue2 NVARCHAR(MAX),BigIntValue BIGINT,BitValue BIT,DecimalValue DECIMAL(12,6),FloatValue FLOAT,DateTimeValue DATETIME,GUIDValue UNIQUEIDENTIFIER)", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteNonQuery();
     }
 }
コード例 #9
0
 public Mapping()
 {
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Database TestDatabase", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Table TestTable(ID_ INT PRIMARY KEY IDENTITY,StringValue_ NVARCHAR(100),LongValue_ BIGINT,BoolValue_ BIT,FloatValue_ FLOAT,StringMaxValue_ NVARCHAR(MAX))", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteNonQuery();
     }
 }
コード例 #10
0
ファイル: Mapping.cs プロジェクト: ewin66/VilinCode
 public Mapping()
 {
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Database TestDatabase", CommandType.Text, "Data Source=localhost;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteNonQuery();
     }
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper("Create Table TestTable(ID_ INT PRIMARY KEY IDENTITY,StringValue_ NVARCHAR(100),LongValue_ BIGINT,BoolValue_ BIT,FloatValue_ FLOAT,StringMaxValue_ NVARCHAR(MAX))", CommandType.Text, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         Helper.ExecuteNonQuery();
     }
 }
コード例 #11
0
        public void LargeBatchInsert()
        {
            Guid TempGuid = Guid.NewGuid();

            Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", "Test String", 12345L, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid);
            using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
            {
                IBatchCommand Batch = Helper.Batch();
                for (int x = 0; x < 1000; ++x)
                {
                    Batch.AddCommands(new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", "Test String", 12345L, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid));
                }
                Assert.Throws <SqlException>(() => Helper.ExecuteNonQuery());
            }
        }
コード例 #12
0
        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");
                }
            }
        }
コード例 #13
0
 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());
     }
 }
コード例 #14
0
        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());
            }
        }
コード例 #15
0
        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));
            }
        }
コード例 #16
0
        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);
        }
コード例 #17
0
 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));
     }
 }
コード例 #18
0
 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);
 }
コード例 #19
0
 public void CommandInsertNullString()
 {
     Guid TempGuid = Guid.NewGuid();
     Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid);
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         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("This is a null string", Helper.GetParameter<string>("StringValue2", "This is a null string"));
             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");
         }
     }
 }
コード例 #20
0
 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");
         }
     }
 }
コード例 #21
0
 public void Execute()
 {
     Guid TempGuid = Guid.NewGuid();
     Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", null, 12345, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid);
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         for (int x = 0; x < 100; ++x)
             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"))
     {
         bool Inserted = false;
         foreach (dynamic Object in Helper.Execute())
         {
             Inserted = true;
             Assert.Equal("Test String", Object.StringValue1);
             Assert.Equal<string>(null, (string)Object.StringValue2);
             Assert.Equal(12345, Object.BigIntValue);
             Assert.Equal(true, Object.BitValue);
             Assert.Equal(1234.5678m, Object.DecimalValue);
             Assert.Equal(12345.6534f, Object.FloatValue);
             Assert.Equal(TempGuid, Object.GUIDValue);
             Assert.Equal(new DateTime(1999, 12, 31), Object.DateTimeValue);
         }
         if (!Inserted)
         {
             Assert.False(true, "Nothing was inserted");
         }
     }
 }
コード例 #22
0
 public void LargeBatchInsert()
 {
     Guid TempGuid = Guid.NewGuid();
     Utilities.SQL.MicroORM.Command TempCommand = new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", "Test String", 12345L, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid);
     using (Utilities.SQL.SQLHelper Helper = new Utilities.SQL.SQLHelper(TempCommand, "Data Source=localhost;Initial Catalog=TestDatabase;Integrated Security=SSPI;Pooling=false"))
     {
         IBatchCommand Batch = Helper.Batch();
         for (int x = 0; x < 1000; ++x)
         {
             Batch.AddCommands(new Utilities.SQL.MicroORM.Command("insert into TestTable(StringValue1,StringValue2,BigIntValue,BitValue,DecimalValue,FloatValue,DateTimeValue,GUIDValue) VALUES (@0,@1,@2,@3,@4,@5,@6,@7)", CommandType.Text, "@", "Test String", "Test String", 12345L, true, 1234.5678m, 12345.6534f, new DateTime(1999, 12, 31), TempGuid));
         }
         Assert.Throws<SqlException>(() => Helper.ExecuteNonQuery());
     }
 }
コード例 #23
0
 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");
         }
     }
 }