Couchbase C Client  2.5.6
n1ql.h
1 /*
2  * Copyright 2015 Couchbase, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  **/
16 
17 #ifndef LCB_N1QL_API_H
18 #define LCB_N1QL_API_H
19 #include <libcouchbase/couchbase.h>
20 #include <libcouchbase/api3.h>
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
36 typedef struct lcb_RESPN1QL lcb_RESPN1QL;
37 typedef struct lcb_CMDN1QL lcb_CMDN1QL;
38 typedef struct lcb_N1QLREQ* lcb_N1QLHANDLE;
39 
46 typedef void (*lcb_N1QLCALLBACK)(lcb_t, int, const lcb_RESPN1QL*);
47 
66 typedef struct lcb_N1QLPARAMS_st lcb_N1QLPARAMS;
67 
74 LIBCOUCHBASE_API
76 lcb_n1p_new(void);
77 
84 LIBCOUCHBASE_API
85 void
87 
93 LIBCOUCHBASE_API
94 void
96 
98 #define LCB_N1P_QUERY_STATEMENT 1
99 
101 #define LCB_N1P_QUERY_PREPARED 2
102 
111 LIBCOUCHBASE_API
113 lcb_n1p_setquery(lcb_N1QLPARAMS *params, const char *qstr, size_t nqstr, int type);
114 
115 #define lcb_n1p_setstmtz(params, qstr) \
116  lcb_n1p_setquery(params, qstr, -1, LCB_N1P_QUERY_STATEMENT)
117 
126 LIBCOUCHBASE_API
128 lcb_n1p_namedparam(lcb_N1QLPARAMS *params, const char *name, size_t n_name,
129  const char *value, size_t n_value);
130 
131 #define lcb_n1p_namedparamz(params, name, value) \
132  lcb_n1p_namedparam(params, name, -1, value, -1)
133 
140 LIBCOUCHBASE_API
142 lcb_n1p_posparam(lcb_N1QLPARAMS *params, const char *value, size_t n_value);
143 
152 LIBCOUCHBASE_API
154 lcb_n1p_setopt(lcb_N1QLPARAMS *params, const char *name, size_t n_name,
155  const char *value, size_t n_value);
156 
163 #define lcb_n1p_setoptz(params, key, value) \
164  lcb_n1p_setopt(params, key, -1, value, -1)
165 
166 
168 #define LCB_N1P_CONSISTENCY_NONE 0
169 
175 #define LCB_N1P_CONSISTENCY_RYOW 1
176 
178 #define LCB_N1P_CONSISTENCY_REQUEST 2
179 
181 #define LCB_N1P_CONSISTENCY_STATEMENT 3
182 
191 LIBCOUCHBASE_API
193 lcb_n1p_setconsistency(lcb_N1QLPARAMS *params, int mode);
194 
203 LIBCOUCHBASE_API
206  const char *keyspace, const lcb_MUTATION_TOKEN *st);
207 
215 LIBCOUCHBASE_API
217 lcb_n1p_setconsistent_handle(lcb_N1QLPARAMS *params, lcb_t instance);
218 
229 LIBCOUCHBASE_API
230 const char *
232 
244 LIBCOUCHBASE_API
247 
259 #define LCB_CMDN1QL_F_PREPCACHE 1<<16
260 
262 #define LCB_CMDN1QL_F_JSONQUERY 1<<17
263 
271 struct lcb_CMDN1QL {
272  lcb_U32 cmdflags;
285  const char *query;
286 
288  size_t nquery;
289 
291  const char *host;
292 
294  const char *content_type;
295 
298 
301  lcb_N1QLHANDLE *handle;
302 };
303 
309 struct lcb_RESPN1QL {
310  #ifndef __LCB_DOXYGEN__
312  #else
313  lcb_U16 rflags;
314  #endif
315 
321  const char *row;
323  size_t nrow;
326 };
327 
341 LIBCOUCHBASE_API
343 lcb_n1ql_query(lcb_t instance, const void *cookie, const lcb_CMDN1QL *cmd);
344 
345 
354 LIBCOUCHBASE_API
355 void
356 lcb_n1ql_cancel(lcb_t instance, lcb_N1QLHANDLE handle);
361 #ifdef __cplusplus
362 }
363 #endif
364 #endif
lcb_error_t lcb_n1p_posparam(lcb_N1QLPARAMS *params, const char *value, size_t n_value)
Adds a positional argument for the query.
const char * content_type
Ignored since version 2.5.3.
Definition: n1ql.h:294
Response for a N1QL query.
Definition: n1ql.h:309
const char * row
Current result row.
Definition: n1ql.h:321
lcb_N1QLHANDLE * handle
Request handle.
Definition: n1ql.h:301
lcb_N1QLCALLBACK callback
Callback to be invoked for each row.
Definition: n1ql.h:297
Main header file for Couchbase.
size_t nquery
Length of the query data.
Definition: n1ql.h:288
const lcb_RESPHTTP * htresp
Raw HTTP response, if applicable.
Definition: n1ql.h:325
void lcb_n1p_reset(lcb_N1QLPARAMS *params)
Reset the parameters structure so that it may be reused for a subsequent query.
lcb_N1QLPARAMS * lcb_n1p_new(void)
Create a new N1QL Parameters object.
void lcb_n1ql_cancel(lcb_t instance, lcb_N1QLHANDLE handle)
Cancels an in-progress request.
lcb_error_t lcb_n1p_setconsistency(lcb_N1QLPARAMS *params, int mode)
Sets the consistency mode for the request.
Structure representing a synchronization token.
Definition: couchbase.h:577
Command structure for N1QL queries.
Definition: n1ql.h:271
lcb_error_t lcb_n1p_namedparam(lcb_N1QLPARAMS *params, const char *name, size_t n_name, const char *value, size_t n_value)
Sets a named argument for the query.
Structure for HTTP responses.
Definition: couchbase.h:2439
lcb_error_t lcb_n1p_setquery(lcb_N1QLPARAMS *params, const char *qstr, size_t nqstr, int type)
Sets the actual statement to be executed.
const char * host
Ignored since version 2.5.3.
Definition: n1ql.h:291
struct lcb_st * lcb_t
Library handle representing a connection to a data bucket.
Definition: couchbase.h:41
lcb_error_t lcb_n1p_setopt(lcb_N1QLPARAMS *params, const char *name, size_t n_name, const char *value, size_t n_value)
Set a query option.
lcb_error_t
Error codes returned by the library.
Definition: error.h:506
#define LCB_RESP_BASE
Response specific flags.
Definition: couchbase.h:539
void(* lcb_N1QLCALLBACK)(lcb_t, int, const lcb_RESPN1QL *)
Callback to be invoked for each row.
Definition: n1ql.h:46
struct lcb_N1QLPARAMS_st lcb_N1QLPARAMS
Opaque object representing N1QL parameters.
Definition: n1ql.h:66
const char * lcb_n1p_encode(lcb_N1QLPARAMS *params, lcb_error_t *rc)
Encodes the request and returns it as a string.
lcb_error_t lcb_n1p_setconsistent_handle(lcb_N1QLPARAMS *params, lcb_t instance)
Indicate that the query should synchronize its internal snapshot to reflect any past changes made by ...
size_t nrow
Length of the row.
Definition: n1ql.h:323
lcb_error_t lcb_n1p_setconsistent_token(lcb_N1QLPARAMS *params, const char *keyspace, const lcb_MUTATION_TOKEN *st)
Indicate that the query should synchronize its internal snapshot to reflect the changes indicated by ...
const char * query
Query to be placed in the POST request.
Definition: n1ql.h:285
lcb_U16 rflags
Flags for response structure.
Definition: n1ql.h:313
void lcb_n1p_free(lcb_N1QLPARAMS *params)
Free the parameters structure.
lcb_error_t lcb_n1p_mkcmd(lcb_N1QLPARAMS *params, lcb_CMDN1QL *cmd)
Populates the given low-level lcb_CMDN1QL structure with the relevant fields from the params structur...
lcb_error_t lcb_n1ql_query(lcb_t instance, const void *cookie, const lcb_CMDN1QL *cmd)