Ejemplo n.º 1
0
 public ExecuteVisitor(INativeHelper helper, JQLCallback callback)
 {
     _helper   = helper;
     _callback = callback;
     _e        = new ExceptionHelper(helper);
 }
Ejemplo n.º 2
0
        public void Execute(EJDB2Handle db, EJDB2Handle jql, long skip, long limit,
                            JQLCallback cb, StringWriter explain)
        {
            if (db.IsInvalid)
            {
                throw new ArgumentException("Invalid DB handle.");
            }

            if (db.IsClosed)
            {
                throw new ArgumentException("DB handle is closed.");
            }

            if (jql.IsInvalid)
            {
                throw new ArgumentException("Invalid JQL handle.");
            }

            if (jql.IsClosed)
            {
                throw new ArgumentException("JQL handle is closed.");
            }

            IntPtr log = IntPtr.Zero;

            try
            {
                if (explain != null)
                {
                    log = _helper.iwxstr_new();
                    if (log == IntPtr.Zero)
                    {
                        throw new InvalidOperationException("iwxstr_new failed.");
                    }
                }

                var ux = new EJDB_EXEC
                {
                    db      = db.DangerousGetHandle(),
                    q       = jql.DangerousGetHandle(),
                    skip    = skip > 0 ? skip : 0,
                    limit   = limit > 0 ? limit : 0,
                    opaque  = IntPtr.Zero,
                    visitor = null,
                    log     = log,
                };

                if (cb != null)
                {
                    var visitor = new ExecuteVisitor(_helper, cb);
                    ux.visitor = visitor.Visitor;
                }

                ulong rc = _helper.ejdb_exec(ref ux);
                if (rc != 0)
                {
                    throw _e.CreateException(rc);
                }

                if (log != IntPtr.Zero)
                {
                    string slog = Utf8String.FromIntPtr(_helper.iwxstr_ptr(log));
                    explain.Write(slog);
                }
            }
            finally
            {
                if (log != IntPtr.Zero)
                {
                    _helper.iwxstr_destroy(log);
                }
            }
        }