Esempio n. 1
0
            public ulong Visitor(ref EJDB_EXEC ctx, ref EJDB_DOC doc, out long step)
            {
                ulong  rc   = 0;
                IntPtr xstr = IntPtr.Zero;

                step = 0;

                try
                {
                    uint sz = _helper.jbl_size(doc.raw).ToUInt32() * 2;
                    xstr = _helper.iwxstr_new2((UIntPtr)sz);

                    if (xstr == IntPtr.Zero)
                    {
                        throw new InvalidOperationException("iwxstr_new2 failed.");
                    }

                    rc = doc.node != IntPtr.Zero
                        ? _helper.jbn_as_json(doc.node, _helper.jbl_xstr_json_printer,
                                              xstr, jbl_print_flags_t.JBL_PRINT_NONE)
                        : _helper.jbl_as_json(doc.raw, _helper.jbl_xstr_json_printer,
                                              xstr, jbl_print_flags_t.JBL_PRINT_NONE);

                    if (rc != 0)
                    {
                        throw _e.CreateException(rc);
                    }

                    string json = Utf8String.FromIntPtr(_helper.iwxstr_ptr(xstr));
                    long   llv  = _callback(doc.id, json);
                    step = llv < -2 ? 0 : llv;
                }
                finally
                {
                    if (xstr != IntPtr.Zero)
                    {
                        _helper.iwxstr_destroy(xstr);
                    }
                }

                return(rc);
            }
Esempio n. 2
0
        public long ExecuteScalarInt64(EJDB2Handle db, EJDB2Handle jql,
                                       long skip, long limit, 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,
                };

                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);
                }

                return(ux.cnt);
            }
            finally
            {
                if (log != IntPtr.Zero)
                {
                    _helper.iwxstr_destroy(log);
                }
            }
        }