@@ -2601,30 +2601,34 @@ private static void init() {
2601
2601
public void testQuerySyntaxAll () throws CouchbaseLiteException {
2602
2602
2603
2603
// tag::query-syntax-all[]
2604
- Query listQuery = QueryBuilder .select (SelectResult .all ())
2605
- .from (DataSource .database (this_Db )); // <.>
2604
+ try {
2605
+ this_Db = new Database ("hotels" );
2606
+ } catch (CouchbaseLiteException e ) {
2607
+ e .printStackTrace ();
2608
+ }
2606
2609
2610
+ Query listQuery = QueryBuilder .select (SelectResult .all ())
2611
+ .from (DataSource .database (this_Db ));
2607
2612
// end::query-syntax-all[]
2608
2613
2609
2614
// tag::query-access-all[]
2610
2615
try {
2611
2616
for (Result result : listQuery .execute ().allResults ()) {
2612
- int x = result .count ();
2613
- // get the k-v pairs from the 'hotel' key's value into a dictionary
2614
- thisDocsProps = result .getDictionary (dbName ); // <.>
2617
+ // get the k-v pairs from the 'hotel' key's value into a dictionary
2618
+ thisDocsProps = result .getDictionary (0 )); // <.>
2615
2619
thisDocsId = thisDocsProps .getString ("id" );
2616
2620
thisDocsName = thisDocsProps .getString ("Name" );
2617
2621
thisDocsType = thisDocsProps .getString ("Type" );
2618
2622
thisDocsCity = thisDocsProps .getString ("City" );
2619
2623
2620
2624
// Alternatively, access results value dictionary directly
2621
2625
final Hotel hotel = new Hotel ();
2622
- hotel .Id = result .getDictionary (dbName ).getString ("id" ); // <.>
2623
- hotel .Type = result .getDictionary (dbName ).getString ("Type" );
2624
- hotel .Name = result .getDictionary (dbName ).getString ("Name" );
2625
- hotel .City = result .getDictionary (dbName ).getString ("City" );
2626
- hotel .Country = result .getDictionary (dbName ).getString ("Country" );
2627
- hotel .Description = result .getDictionary (dbName ).getString ("Description" );
2626
+ hotel .Id = result .getDictionary (0 ).getString ("id" ); // <.>
2627
+ hotel .Type = result .getDictionary (0 ).getString ("Type" );
2628
+ hotel .Name = result .getDictionary (0 ).getString ("Name" );
2629
+ hotel .City = result .getDictionary (0 ).getString ("City" );
2630
+ hotel .Country = result .getDictionary (0 ).getString ("Country" );
2631
+ hotel .Description = result .getDictionary (0 ).getString ("Description" );
2628
2632
hotels .put (hotel .Id , hotel );
2629
2633
2630
2634
}
@@ -2638,6 +2642,12 @@ public void testQuerySyntaxAll() throws CouchbaseLiteException {
2638
2642
public void testQuerySyntaxProps () throws CouchbaseLiteException {
2639
2643
2640
2644
// tag::query-syntax-props[]
2645
+ try {
2646
+ this_Db = new Database ("hotels" );
2647
+ } catch (CouchbaseLiteException e ) {
2648
+ e .printStackTrace ();
2649
+ }
2650
+
2641
2651
Query listQuery =
2642
2652
QueryBuilder .select (SelectResult .expression (Meta .id ),
2643
2653
SelectResult .property ("name" ),
@@ -2684,13 +2694,18 @@ public void testQuerySyntaxProps() throws CouchbaseLiteException {
2684
2694
2685
2695
2686
2696
public void testQuerySyntaxCount () throws CouchbaseLiteException {
2697
+ try {
2698
+ this_Db = new Database ("hotels" );
2699
+ } catch (CouchbaseLiteException e ) {
2700
+ e .printStackTrace ();
2701
+ }
2687
2702
2688
- // tag::query-syntax-count-only[]
2689
- Query listQuery = QueryBuilder .select (
2690
- SelectResult .expression (Function .count (Expression .string ("*" ))).as ("mycount" )) // <.>
2691
- .from (DataSource .database (this_Db ));
2703
+ // tag::query-syntax-count-only[]
2704
+ Query listQuery = QueryBuilder .select (
2705
+ SelectResult .expression (Function .count (Expression .string ("*" ))).as ("mycount" )) // <.>
2706
+ .from (DataSource .database (this_Db ));
2692
2707
2693
- // end::query-syntax-count-only[]
2708
+ // end::query-syntax-count-only[]
2694
2709
2695
2710
2696
2711
// tag::query-access-count-only[]
@@ -2703,7 +2718,7 @@ public void testQuerySyntaxCount() throws CouchbaseLiteException {
2703
2718
// Alternatively, use the index
2704
2719
Integer orDocId = result .getInt (0 );
2705
2720
}
2706
- // Or even
2721
+ // Or even miss out the for-loop altogether
2707
2722
Integer resultCount = listQuery .execute ().next ().getInt ("mycount" );
2708
2723
2709
2724
} catch (CouchbaseLiteException e ) {
@@ -2714,12 +2729,18 @@ public void testQuerySyntaxCount() throws CouchbaseLiteException {
2714
2729
2715
2730
2716
2731
public void testQuerySyntaxId () throws CouchbaseLiteException {
2717
- // tag::query-syntax-id[]
2718
- Query listQuery =
2719
- QueryBuilder .select (SelectResult .expression (Meta .id ).as ("metaID" ))
2720
- .from (DataSource .database (this_Db ));
2732
+ // tag::query-syntax-id[]
2733
+ try {
2734
+ this_Db = new Database ("hotels" );
2735
+ } catch (CouchbaseLiteException e ) {
2736
+ e .printStackTrace ();
2737
+ }
2738
+
2739
+ Query listQuery =
2740
+ QueryBuilder .select (SelectResult .expression (Meta .id ).as ("metaID" ))
2741
+ .from (DataSource .database (this_Db ));
2721
2742
2722
- // end::query-syntax-id[]
2743
+ // end::query-syntax-id[]
2723
2744
2724
2745
2725
2746
// tag::query-access-id[]
@@ -2751,14 +2772,21 @@ public void testQueryPagination() throws CouchbaseLiteException {
2751
2772
2752
2773
2753
2774
// tag::query-syntax-pagination[]
2775
+ try {
2776
+ this_Db = new Database ("hotels" );
2777
+ } catch (CouchbaseLiteException e ) {
2778
+ e .printStackTrace ();
2779
+ }
2780
+
2754
2781
int thisOffset = 0 ;
2755
2782
int thisLimit = 20 ;
2756
2783
2757
2784
Query listQuery =
2758
2785
QueryBuilder
2759
2786
.select (SelectResult .all ())
2760
2787
.from (DataSource .database (this_Db ))
2761
- .limit (Expression .intValue (thisLimit ), Expression .intValue (thisOffset )); // <.>
2788
+ .limit (Expression .intValue (thisLimit ),
2789
+ Expression .intValue (thisOffset )); // <.>
2762
2790
2763
2791
// end::query-syntax-pagination[]
2764
2792
0 commit comments