示例#1
0
 public void test_explicit_prepare()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.exec("CREATE TABLE foo (x int);");
         const int num = 7;
         using (sqlite3_stmt stmt = db.prepare("INSERT INTO foo (x) VALUES (?)"))
         {
             for (int i = 0; i < num; i++)
             {
                 stmt.reset();
                 stmt.clear_bindings();
                 stmt.bind(1, i);
                 stmt.step();
             }
         }
         int c = db.query_scalar <int>("SELECT COUNT(*) FROM foo");
         Assert.AreEqual(c, num);
     }
 }
        // this implementation of a sqlite rowlist is only appropriate if there is
        // a bind parameter which will return a result for every row.  unless you
        // don't mind empty rows in the grid, gaps where nothing is displayed.
        // however, this will be much faster than the IEnumish one, and doesn't
        // require a cache in front of it.

        public bool get_value(int row, out TRow val)
        {
            // TODO or should the reset be done AFTER?
            _stmt.reset();

            _stmt.clear_bindings();              // TODO probably not safe to clear bindings here because we only own one of them

            _stmt.bind_int(1, row);              // TODO the ndx of the bind param should be a param to the constructor of this class

            int rc = _stmt.step();

            if (raw.SQLITE_ROW != rc)
            {
                val = default(TRow);
                return(false);
            }

            val = get_row();
            return(true);
        }
 private void Reset()
 {
     _stmt.reset();
     _cur  = -1;
     _done = false;
 }