Ejemplo n.º 1
0
        public void MSSQLStoreTest()
        {
            SQLStore LSQLStore;

            LSQLStore = new MSSQLStore();
            LSQLStore.ConnectionString = "Data Source=HUITZILOPOCHTLI;Initial Catalog=Tests;Integrated Security=True;";
            SQLStoreConnection LConnection = LSQLStore.Connect();
            string             ATableName  = "TableTest";
            List <string>      AColumns    = new List <string>();

            AColumns.Add("ID");
            AColumns.Add("NAME");
            SQLIndex AIndex = new SQLIndex("PK_TableTest", new[] { new SQLIndexColumn("ID") });

            //The table has 2 columns ID (integer) and NAME (nvarchar 50)

                        #if USESQLCONNECTION
            LConnection.BeginTransaction(SQLIsolationLevel.ReadCommitted);
                        #else
            LConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            #endif

            SQLStoreCursor LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            var            LRow    = new object[] { 1, "Hi" };
            LCursor.Insert(LRow);
            LCursor.Dispose();

            LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            LRow    = new object[] { 2, "Bye" };
            LCursor.Insert(LRow);
            LCursor.Dispose();

            LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            LCursor.SetRange(null, null);
            LCursor.Dispose();


            LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            LCursor.Next();
            LCursor.Dispose();

            SQLStoreCursor LOtherCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);

            LCursor.SetRange(null, null);


            LCursor.Dispose();
            LOtherCursor.Dispose();

            LConnection.CommitTransaction();
        }
Ejemplo n.º 2
0
        public void SQLCEStoreTest()
        {
            SQLStore LSQLStore = new SQLCEStore();

            LSQLStore.ConnectionString = @"Data Source=E:\Users\Luxspes\Documents\Visual Studio 2008\SqlCE\MyDatabase1.sdf";
            SQLStoreConnection LConnection = LSQLStore.Connect();
            string             ATableName  = "TableTest";
            List <string>      AColumns    = new List <string>();

            AColumns.Add("ID");
            AColumns.Add("NAME");
            SQLIndex AIndex = new SQLIndex("PK_TableTest", new[] { new SQLIndexColumn("ID") });

            //The table has 2 columns ID (integer) and NAME (nvarchar 50)

                        #if USESQLCONNECTION
            LConnection.BeginTransaction(SQLIsolationLevel.ReadCommitted);
                        #else
            LConnection.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
            #endif

            SQLStoreCursor LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            var            LRow    = new object[] { 1, "Hi" };
            LCursor.Insert(LRow);
            LCursor.Dispose();

            LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            LRow    = new object[] { 2, "Bye" };
            LCursor.Insert(LRow);
            LCursor.Dispose();

            LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            LCursor.SetRange(null, null);
            LCursor.Dispose();


            LCursor = LConnection.OpenCursor(ATableName, AColumns, AIndex, true);
            LCursor.Next();
            LCursor.Dispose();


            LConnection.CommitTransaction();
        }
Ejemplo n.º 3
0
        private void SQLStoreReadAfterUpdateTest(SQLStore ASQLStore)
        {
            using (SQLStoreConnection LConnection = ASQLStore.Connect())
            {
                List <string> LColumns = new List <string>()
                {
                    "ID", "Name"
                };
                SQLIndex LIndex = new SQLIndex("PK_Test", new[] { new SQLIndexColumn("ID") });

                if (LConnection.HasTable("Test"))
                {
                    LConnection.ExecuteStatement("drop table Test");
                }
                if (!LConnection.HasTable("Test"))
                {
                    LConnection.ExecuteStatement("create table Test ( ID int not null, Name nvarchar(20), constraint PK_Test primary key ( ID ) )");
                }

                LConnection.BeginTransaction(SQLIsolationLevel.ReadCommitted);
                try
                {
                    using (SQLStoreCursor LCursor = LConnection.OpenCursor("Test", LColumns, LIndex, true))
                    {
                        LCursor.Insert(new object[] { 1, "Joe" });
                        LCursor.Insert(new object[] { 2, "Martha" });
                        //LCursor.Insert(new object[] { 3, "Clair" });
                    }
                    LConnection.CommitTransaction();
                }
                catch
                {
                    LConnection.RollbackTransaction();
                    throw;
                }

                LConnection.BeginTransaction(SQLIsolationLevel.ReadCommitted);
                try
                {
                    using (SQLStoreCursor LCursor = LConnection.OpenCursor("Test", LColumns, LIndex, true))
                    {
                        if (!LCursor.Next())
                        {
                            throw new Exception("Expected row");
                        }

                        if ((string)LCursor[1] != "Joe")
                        {
                            throw new Exception("Excepted Joe row");
                        }

                        LCursor[1] = "Joes";
                        LCursor.Update();

                        LCursor.SetRange(null, null);
                        if (!LCursor.Next())
                        {
                            throw new Exception("Expected row");
                        }

                        if ((string)LCursor[1] != "Joes")
                        {
                            throw new Exception(String.Format("Expected Joes row, found '{0}'.", (string)LCursor[1]));
                        }

                        LCursor[1] = "Joe";
                        LCursor.Update();
                    }

                    LConnection.CommitTransaction();
                }
                catch
                {
                    LConnection.RollbackTransaction();
                    throw;
                }
            }
        }