예제 #1
0
        private static void Main()
        {
            string filename = Path.Combine(
                Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments),
                "test.sqlite"
                );

            using (var db = new SQLite3(filename))
            {
                try
                {
                    using (SQLite3Transaction transaction = db.BeginTransaction())
                    {
                        db.Query("CREATE TABLE User ( ID INTEGER PRIMARY KEY, Name TEXT UNIQUE );");

                        db.Query("INSERT INTO User (Name) VALUES ('John')");
                        db.Query("INSERT INTO User (Name) VALUES ('Jeff')");
                        db.Query("INSERT INTO User (Name) VALUES ('Jesus')");

                        transaction.Commit();
                    }
                }
                catch (SQLite3Exception ex)
                {
                    Console.WriteLine("EXCEPTION: " + ex.Message);
                }

                using (IEnumerator<User> enumerator = db.QueryEnumerator<User>("SELECT ID, Name FROM User"))
                {
                    enumerator.MoveNext();
                    enumerator.MoveNext();
                    Console.WriteLine(enumerator.Current);

                    enumerator.Reset();
                    while (enumerator.MoveNext())
                        Console.WriteLine(enumerator.Current);
                }
            }
        }