コード例 #1
0
ファイル: QueryHandle.cs プロジェクト: solyutor/ejdb-csharp
        internal CursorHandle Execute(QueryMode flags, out int count)
        {
            QueryLogBuffer logsptr = null;

            //TODO: check it more elegant way?
            if ((flags & QueryMode.Explain) != 0)
            {
                //static extern IntPtr _tcxstrnew();
                logsptr = new QueryLogBuffer(Collection.Database.Library.Functions.Query); //Create dynamic query execution log buffer
            }

            CursorHandle cursorHandle = null;

            try
            {
                int resultCount = 0;
                //static extern IntPtr _ejdbqryexecute([In] IntPtr jcoll, [In] IntPtr q, out int count, [In] int qflags, [In] IntPtr logxstr);
                IntPtr bufferPointer = logsptr == null ? IntPtr.Zero : logsptr.DangerousGetHandle();
                cursorHandle = new CursorHandle(() => _functions.Execute(Collection.CollectionHandle, this, out resultCount, flags, bufferPointer), pointer => _functions.DeleteCursor(pointer));
                count        = resultCount;
            }
            finally
            {
                if (logsptr != null)
                {
                    try
                    {
                        if (cursorHandle != null && !cursorHandle.IsInvalid)
                        {
                            unsafe
                            {
                                //static extern IntPtr _tcxstrptr([In] IntPtr strptr);
                                var sbptr = logsptr.AsString();
                                cursorHandle.Log = new string(sbptr);
                            }
                        }
                    }
                    finally
                    {
                        //static extern IntPtr _tcxstrdel([In] IntPtr strptr);
                        logsptr.Dispose();
                    }
                }
            }
            Collection.Database.ThrowOnError();

            return(cursorHandle);
        }
コード例 #2
0
ファイル: QueryHandle.cs プロジェクト: hendryten/ejdb-csharp
        internal CursorHandle Execute(QueryMode flags, out int count)
        {
            QueryLogBuffer logsptr = null;
            //TODO: check it more elegant way?
            if ((flags & QueryMode.Explain) != 0)
            {
                //static extern IntPtr _tcxstrnew();
                logsptr = new QueryLogBuffer(Collection.Database.Library.LibraryHandle); //Create dynamic query execution log buffer
            }

            CursorHandle cursorHandle = null;
            try
            {
                int resultCount = 0;
                //static extern IntPtr _ejdbqryexecute([In] IntPtr jcoll, [In] IntPtr q, out int count, [In] int qflags, [In] IntPtr logxstr);
                IntPtr bufferPointer = logsptr == null ? IntPtr.Zero : logsptr.DangerousGetHandle();
                cursorHandle = new CursorHandle(() => _execute(Collection.CollectionHandle, this, out resultCount, flags, bufferPointer), pointer => _deleteCursor(pointer));
                count = resultCount;
            }
            finally
            {
                if (logsptr != null)
                {
                    try
                    {
                        if (cursorHandle != null && !cursorHandle.IsInvalid)
                        {
                            //static extern IntPtr _tcxstrptr([In] IntPtr strptr);
                            IntPtr sbptr = logsptr.AsString();

                            cursorHandle.Log = Native.StringFromNativeUtf8(sbptr); //UnixMarshal.PtrToString(sbptr, Encoding.UTF8);
                        }
                    }
                    finally
                    {
                        //static extern IntPtr _tcxstrdel([In] IntPtr strptr);
                        logsptr.Dispose();
                    }
                }
            }
            Collection.Database.ThrowOnError();

            return cursorHandle;
        }