24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/libcouchbase/query_n1ql.rb', line 24
def perform(limit: nil, **options, &blk)
raise 'not connected' unless @connection.handle
raise 'query already in progress' if @query_text
raise 'callback required' unless block_given?
orig_limit = @n1ql.limit
begin
if orig_limit && limit
@n1ql.limit = limit if orig_limit > limit
end
@query_text = @n1ql.to_s
rescue
@query_text = nil
raise
ensure
@n1ql.limit = orig_limit
end
@reactor.schedule {
@error = nil
@callback = blk
@cmd = Ext::CMDN1QL.new
@params = Ext.n1p_new
err = Ext.n1p_setquery(@params, @query_text, @query_text.bytesize, N1P_QUERY_STATEMENT)
if err == :success
err = Ext.n1p_mkcmd(@params, @cmd)
if err == :success
pointer = @cmd.to_ptr
@connection.requests[pointer.address] = self
@cmd[:callback] = @connection.get_callback(:n1ql_callback)
@cmd[:handle] = @request_handle
err = Ext.n1ql_query(@connection.handle, pointer, @cmd)
if err != :success
error(Error.lookup(err).new('full text search not scheduled'))
end
else
error(Error.lookup(err).new('failed to build full text search command'))
end
else
error(Error.lookup(err).new('failed to build full text search query structure'))
end
}
end
|