Beispiel #1
0
        private static string Db(HttpListenerRequest request, HttpListenerResponse response)
        {
            var rnd = new Random();
            var id  = rnd.Next(10000);

            using (var conn = SqliteContext.GetConnection())
            {
                conn.Open();

                var result = conn.Query <RandomNumber>(@"SELECT * FROM World WHERE id=@id", new { id = id }).FirstOrDefault();

                return(JSON.Serialize <RandomNumber>(result));
            }
        }
Beispiel #2
0
        private static void initDb()
        {
            var rnd = new Random();

            using (var conn = SqliteContext.GetConnection())
            {
                conn.Open();

                using (var trans = conn.BeginTransaction())
                {
                    for (var i = 0; i < 10000; i++)
                    {
                        conn.Execute(@"INSERT INTO World (randomNumber) VALUES (@randomNumber)", new { randomNumber = rnd.Next(Int16.MaxValue) }, transaction: trans);
                    }
                    trans.Commit();
                }
            }
        }
Beispiel #3
0
        private static string Queries(HttpListenerRequest request, HttpListenerResponse response)
        {
            var count   = GetQueries(request);
            var results = new List <RandomNumber>();

            var rnd = new Random();

            using (var conn = SqliteContext.GetConnection())
            {
                conn.Open();
                for (var i = 0; i < count; i++)
                {
                    var id = rnd.Next(10000) + 1;
                    var n  = conn.Query <RandomNumber>(@"SELECT * FROM World WHERE id=@id", new { id = id }).FirstOrDefault();

                    results.Add(n);
                }
            }

            return(JSON.Serialize <List <RandomNumber> >(results));
        }