示例#1
0
        public void ExecTest()
        {
            // insert English
            string sqlInsert = "INSERT INTO " + csName + "." + cName +
                               " ( c, d, e, f ) values( 6.1, \"8.1\", \"aaa\", \"bbb\")";

            try
            {
                sdb.ExecUpdate(sqlInsert);
            }
            catch (BaseException e)
            {
                string errInfo = e.Message;
                Console.WriteLine("The error info is: " + errInfo);
                Assert.IsFalse(1 == 1);
            }
            // insert Chinese
            string sqlInsert1 = "INSERT INTO " + csName + "." + cName +
                                " ( 城市1, 城市2 ) values( \"广州\",\"上海\")";

            //string str = "INSERT into testfoo.testbar ( 城市1, 城市2 )  values( \"广州\",\"上海\" )";
            try
            {
                sdb.ExecUpdate(sqlInsert1);
            }
            catch (BaseException e)
            {
                string errInfo = e.Message;
                Console.WriteLine("The error info is: " + errInfo);
                Assert.IsFalse(1 == 1);
            }
            // select some
            string   sqlSelect = "SELECT 城市1 FROM " + csName + "." + cName;
            DBCursor cursor    = sdb.Exec(sqlSelect);

            Assert.IsNotNull(cursor);
            while (cursor.Next() != null)
            {
                BsonDocument bson = cursor.Current();
                string       temp = bson.ToString();
                Assert.IsNotNull(bson);
            }
            // select all
            string sqlSelect1 = "SELECT FROM " + csName + "." + cName;

            cursor = sdb.Exec(sqlSelect);
            Assert.IsNotNull(cursor);
            int count = 0;

            while (cursor.Next() != null)
            {
                count++;
                BsonDocument bson = cursor.Current();
                string       temp = bson.ToString();
                Assert.IsNotNull(bson);
            }
            Assert.AreEqual(count, 2);
            // remove all the record
            string sqlDel = "DELETE FROM " + csName + "." + cName;

            try
            {
                sdb.ExecUpdate(sqlDel);
            }
            catch (BaseException e)
            {
                string errInfo = e.Message;
                Console.WriteLine("The error info is: " + errInfo);
                Assert.IsFalse(1 == 1);
            }
        }