Menu

GetRecNo results in access violation

Help
Henry Liu
2008-10-14
2013-04-09
  • Henry Liu

    Henry Liu - 2008-10-14

    Hi,

    First of all, great job on the package. We've been looking for something exactly like this.

    We're running into issues with BdBTreeCursor.GetRecNo. We created a database with the RECNUM flag and as far as we can tell everything else works but we end up with a memory access violation when we call the GetRecNo method. Also trying to Get a record by a RecNo also results in null DbEntry outputs.

    Is this a pending issue or am I doing it wrong?

     
    • Karl Waclawek

      Karl Waclawek - 2008-10-14

      I am not aware of an open issue.
      Could you please post the code you are using?
      Also, make sure you are using BDB 4.3.29 or BDB4.5.20.

       
    • Henry Liu

      Henry Liu - 2008-10-14

      I'm using BDB 4.5.20.

      Using your example project:

            Db db = new Db(DbCreateFlags.None);
            db.ErrorPrefix = appName;
            db.ErrorStream = errStream;
            db.SetFlags(DbFlags.RecNum);
            vendorDb = (DbBTree)db.Open(null, VendorDbName, null, DbType.BTree, Db.OpenFlags.Create, 0);

            Databases dbs = Databases.Instance;
            List<Vendor> vendors = new List<Vendor>();

            DbBTreeCursor cursor = dbs.VendorDb.OpenCursor(null, DbFileCursor.CreateFlags.None);
            foreach (KeyDataPair entry in cursor) {
              Vendor vendor = null;
              dbs.Fmt.FromDbEntry<Vendor>(ref vendor, ref entry.Data);
              vendors.Add(vendor);
              cursor.GetAt(ref entry.Key, ref entry.Data, DbFileCursor.GetAtMode.Set, DbFileCursor.ReadFlags.None);

              int boo = cursor.GetRecNo(DbFileCursor.ReadFlags.None); // Results in access violation!
            }

       
      • Karl Waclawek

        Karl Waclawek - 2008-10-15

        I put a fix for the access violation into CVS, it affects DBC_Wrap.cs.
        Please check it out and test your code.

        Striktly speaking this is a documentation bug in BDB, as the docs claim that the key parameter passed to DBC->Get is ignored, but it isn't actually, so I have to pass a dummy key.

        Btw, about the code you posted: I would not use code that could potentially change the cursor position while looping over the cursor.
        Even if the key is the same as in the loop, it could move the cursor if the key has duplicate entries.

         
    • Henry Liu

      Henry Liu - 2008-10-14

      I am still new to BerkeleyDb. Is it because if you use the RecNum flag your key must be a UINT32? I had assumed that it will apply record numbers to a database even if the key is something different.. ie a string.

       
      • Karl Waclawek

        Karl Waclawek - 2008-10-15

        No, the key does not have to be UInt32.

         
    • Henry Liu

      Henry Liu - 2008-10-16

      Works great now. Thanks.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.