@@ -89,7 +89,7 @@ static void getting_started() {
89
89
CBLDocument_Release (docAgain );
90
90
FLSliceResult_Release (id );
91
91
92
- // tag::query-syntax-n1ql-params []
92
+ // tag::query-syntax-n1ql[]
93
93
// Create a query to fetch documents of type SDK
94
94
int errorPos ;
95
95
CBLQuery * query = CBLDatabase_CreateQuery (database , kCBLN1QLLanguage , FLSTR ("SELECT * FROM _ WHERE type = \"SDK\"" ), & errorPos , & err );
@@ -105,7 +105,7 @@ static void getting_started() {
105
105
// Failed to run query, do error handling as above
106
106
return ;
107
107
}
108
- // end::query-syntax-n1ql-params []
108
+ // end::query-syntax-n1ql[]
109
109
110
110
// TODO: Result set count?
111
111
CBLResultSet_Release (result );
@@ -827,7 +827,7 @@ static void order_by() {
827
827
// NOTE: No error handling, for brevity (see getting started)
828
828
829
829
CBLError err ;
830
- CBLQuery * query = CBLDatabase_CreateQuery (db , kCBLN1QLLanguage ,
830
+ CBLQuery * query = CBLDatabase_CreateQuery (db , kCBLN1QLLanguage ,
831
831
FLSTR ("SELECT meta().id, title FROM _ WHERE type = \"hotel\" ORDER BY title ASC LIMIT 10" ),
832
832
NULL , & err );
833
833
@@ -850,7 +850,7 @@ static void test_explain_statement() {
850
850
// NOTE: No error handling, for brevity (see getting started)
851
851
852
852
CBLError err ;
853
- CBLQuery * query = CBLDatabase_CreateQuery (db , kCBLN1QLLanguage ,
853
+ CBLQuery * query = CBLDatabase_CreateQuery (db , kCBLN1QLLanguage ,
854
854
FLSTR ("SELECT * FROM _ WHERE type = \"hotel\" GROUP BY country ORDER BY title ASC LIMIT 10" ),
855
855
NULL , & err );
856
856
@@ -865,15 +865,15 @@ static void test_explain_statement() {
865
865
866
866
static void query_result_json () {
867
867
CBLDatabase * db = kDatabase ;
868
-
868
+
869
869
CBLError err ;
870
870
CBLQuery * query = CBLDatabase_CreateQuery (db , kCBLN1QLLanguage ,
871
871
FLSTR ("SELECT meta().id as id, name, city, type FROM _ LIMIT 10" ),
872
872
NULL , & err );
873
873
874
874
// tag::query-access-json[]
875
875
// NOTE: No error handling, for brevity (see getting started)
876
-
876
+
877
877
CBLResultSet * results = CBLQuery_Execute (query , & err );
878
878
while (CBLResultSet_Next (results )) {
879
879
FLDict result = CBLResultSet_ResultDict (results );
@@ -882,9 +882,9 @@ static void query_result_json() {
882
882
FLSliceResult_Release (json );
883
883
}
884
884
CBLResultSet_Release (results );
885
-
885
+
886
886
// end::query-access-json[]
887
-
887
+
888
888
CBLQuery_Release (query );
889
889
}
890
890
@@ -931,7 +931,7 @@ static void full_text_search() {
931
931
// NOTE: No error handling, for brevity (see getting started)
932
932
933
933
CBLError err ;
934
- CBLQuery * query = CBLDatabase_CreateQuery (db , kCBLN1QLLanguage ,
934
+ CBLQuery * query = CBLDatabase_CreateQuery (db , kCBLN1QLLanguage ,
935
935
FLSTR ("SELECT meta().id FROM _ WHERE MATCH(nameFTSIndex, \"'buy'\")" ),
936
936
NULL , & err );
937
937
@@ -1046,6 +1046,43 @@ static void enable_basic_auth() {
1046
1046
// end::basic-authentication[]
1047
1047
}
1048
1048
1049
+ static void docsonly_N1QL_Params () {
1050
+ CBLDatabase * database = kDatabase ;
1051
+
1052
+ // tag::query-syntax-n1ql-params[]
1053
+ int errorPos ;
1054
+
1055
+ CBLError err ;
1056
+
1057
+ FLString n1qlstr = FLSTR ("SELECT * FROM _ WHERE type = $type" );
1058
+
1059
+ FLMutableDict n1qlparams = FLMutableDict_New ();
1060
+ FLMutableDict_SetString (n1qlparams , FLSTR ("type" ), FLSTR ("hotel" ));
1061
+
1062
+ CBLQuery * query = CBLDatabase_CreateQuery (database ,
1063
+ kCBLN1QLLanguage ,
1064
+ n1qlstr ,
1065
+ & errorPos ,
1066
+ & err );
1067
+
1068
+ CBLQuery_SetParameters (query , n1qlparams );
1069
+
1070
+ if (!query ) {
1071
+ /* Do appropriate error handling ...
1072
+ Note that (where applicable) errorPos contains the position
1073
+ in the N1QL string that the parse failed
1074
+ */
1075
+ return ;
1076
+ }
1077
+
1078
+ CBLResultSet * result = CBLQuery_Execute (query , & err );
1079
+ if (!result ) {
1080
+ // Failed to run query, do error handling ...
1081
+ return ;
1082
+ }
1083
+ // end::query-syntax-n1ql-params[]
1084
+ }
1085
+
1049
1086
int main (int argc , char * * argv ) {
1050
1087
create_new_database ();
1051
1088
create_document ();
0 commit comments