public BSONIterator FinOne(string cname = null, int qflags = 0) { using (EJDBQCursor cur = Find(cname, qflags | JBQRYFINDONE_FLAG)) { return(cur.Next()); } }
public int Update(string cname = null, int qflags = 0) { using (EJDBQCursor cur = Find(cname, qflags | JBQRYCOUNT_FLAG)) { return(cur.Length); } }
public EJDBQCursor Find(string cname = null, int qflags = 0) { CheckDisposed(); if (cname == null) { cname = _defaultcollection; } if (cname == null) { throw new ArgumentException("Collection name must be provided"); } IntPtr cptr = EJDB._ejdbgetcoll(_jb.DBPtr, cname); if (cptr == IntPtr.Zero) { return(new EJDBQCursor(IntPtr.Zero, 0)); } if (_dutyhints) { SetHints(_hints); _dutyhints = false; } int count; IntPtr logsptr = IntPtr.Zero; if ((qflags & EXPLAIN_FLAG) != 0) { //static extern IntPtr _tcxstrnew(); logsptr = _tcxstrnew(); //Create dynamic query execution log buffer } EJDBQCursor cur = null; try { //static extern IntPtr _ejdbqryexecute([In] IntPtr jcoll, [In] IntPtr q, out int count, [In] int qflags, [In] IntPtr logxstr); IntPtr qresptr = _ejdbqryexecute(cptr, _qptr, out count, qflags, logsptr); cur = new EJDBQCursor(qresptr, count); } finally { if (logsptr != IntPtr.Zero) { try { if (cur != null) { //static extern IntPtr _tcxstrptr([In] IntPtr strptr); IntPtr sbptr = _tcxstrptr(logsptr); cur.Log = Native.StringFromNativeUtf8(sbptr); //UnixMarshal.PtrToString(sbptr, Encoding.UTF8); } } finally { //static extern IntPtr _tcxstrdel([In] IntPtr strptr); _tcxstrdel(logsptr); } } } int ecode = _jb.LastDBErrorCode ?? 0; if (ecode != 0) { cur.Dispose(); throw new EJDBException(_jb); } return(cur); }