@@ -1892,30 +1892,35 @@ private static void init() {
1892
1892
public void testQuerySyntaxAll () throws CouchbaseLiteException {
1893
1893
1894
1894
// tag::query-syntax-all[]
1895
- Query listQuery = QueryBuilder .select (SelectResult .all ())
1896
- .from (DataSource .database (this_Db )); // <.>
1895
+ try {
1896
+ this_Db = new Database ("hotels" );
1897
+ } catch (CouchbaseLiteException e ) {
1898
+ e .printStackTrace ();
1899
+ }
1900
+
1901
+ Query listQuery = QueryBuilder .select (SelectResult .all ())
1902
+ .from (DataSource .database (this_Db )); // <.>
1897
1903
1898
1904
// end::query-syntax-all[]
1899
1905
1900
1906
// tag::query-access-all[]
1901
1907
try {
1902
1908
for (Result result : listQuery .execute ().allResults ()) {
1903
- int x = result .count ();
1904
- // get the k-v pairs from the 'hotel' key's value into a dictionary
1905
- thisDocsProps = result .getDictionary (dbName ); // <.>
1909
+ // get the k-v pairs from the 'hotel' key's value into a dictionary
1910
+ thisDocsProps = result .getDictionary (0 )); // <.>
1906
1911
thisDocsId = thisDocsProps .getString ("id" );
1907
1912
thisDocsName = thisDocsProps .getString ("Name" );
1908
1913
thisDocsType = thisDocsProps .getString ("Type" );
1909
1914
thisDocsCity = thisDocsProps .getString ("City" );
1910
1915
1911
1916
// Alternatively, access results value dictionary directly
1912
1917
final Hotel hotel = new Hotel ();
1913
- hotel .Id = result .getDictionary (dbName ).getString ("id" ); // <.>
1914
- hotel .Type = result .getDictionary (dbName ).getString ("Type" );
1915
- hotel .Name = result .getDictionary (dbName ).getString ("Name" );
1916
- hotel .City = result .getDictionary (dbName ).getString ("City" );
1917
- hotel .Country = result .getDictionary (dbName ).getString ("Country" );
1918
- hotel .Description = result .getDictionary (dbName ).getString ("Description" );
1918
+ hotel .Id = result .getDictionary (0 ).getString ("id" ); // <.>
1919
+ hotel .Type = result .getDictionary (0 ).getString ("Type" );
1920
+ hotel .Name = result .getDictionary (0 ).getString ("Name" );
1921
+ hotel .City = result .getDictionary (0 ).getString ("City" );
1922
+ hotel .Country = result .getDictionary (0 ).getString ("Country" );
1923
+ hotel .Description = result .getDictionary (0 ).getString ("Description" );
1919
1924
hotels .put (hotel .Id , hotel );
1920
1925
1921
1926
}
@@ -1929,6 +1934,12 @@ public void testQuerySyntaxAll() throws CouchbaseLiteException {
1929
1934
public void testQuerySyntaxProps () throws CouchbaseLiteException {
1930
1935
1931
1936
// tag::query-syntax-props[]
1937
+ try {
1938
+ this_Db = new Database ("hotels" );
1939
+ } catch (CouchbaseLiteException e ) {
1940
+ e .printStackTrace ();
1941
+ }
1942
+
1932
1943
Query listQuery =
1933
1944
QueryBuilder .select (SelectResult .expression (Meta .id ),
1934
1945
SelectResult .property ("name" ),
@@ -1975,13 +1986,18 @@ public void testQuerySyntaxProps() throws CouchbaseLiteException {
1975
1986
1976
1987
1977
1988
public void testQuerySyntaxCount () throws CouchbaseLiteException {
1989
+ try {
1990
+ this_Db = new Database ("hotels" );
1991
+ } catch (CouchbaseLiteException e ) {
1992
+ e .printStackTrace ();
1993
+ }
1978
1994
1979
- // tag::query-syntax-count-only[]
1980
- Query listQuery = QueryBuilder .select (
1981
- SelectResult .expression (Function .count (Expression .string ("*" ))).as ("mycount" )) // <.>
1982
- .from (DataSource .database (this_Db ));
1995
+ // tag::query-syntax-count-only[]
1996
+ Query listQuery = QueryBuilder .select (
1997
+ SelectResult .expression (Function .count (Expression .string ("*" ))).as ("mycount" )) // <.>
1998
+ .from (DataSource .database (this_Db ));
1983
1999
1984
- // end::query-syntax-count-only[]
2000
+ // end::query-syntax-count-only[]
1985
2001
1986
2002
1987
2003
// tag::query-access-count-only[]
@@ -1994,7 +2010,7 @@ public void testQuerySyntaxCount() throws CouchbaseLiteException {
1994
2010
// Alternatively, use the index
1995
2011
Integer orDocId = result .getInt (0 );
1996
2012
}
1997
- // Or even
2013
+ // Or even miss out the for-loop altogether
1998
2014
Integer resultCount = listQuery .execute ().next ().getInt ("mycount" );
1999
2015
2000
2016
} catch (CouchbaseLiteException e ) {
@@ -2005,12 +2021,18 @@ public void testQuerySyntaxCount() throws CouchbaseLiteException {
2005
2021
2006
2022
2007
2023
public void testQuerySyntaxId () throws CouchbaseLiteException {
2008
- // tag::query-syntax-id[]
2009
- Query listQuery =
2010
- QueryBuilder .select (SelectResult .expression (Meta .id ).as ("metaID" ))
2011
- .from (DataSource .database (this_Db ));
2024
+ // tag::query-syntax-id[]
2025
+ try {
2026
+ this_Db = new Database ("hotels" );
2027
+ } catch (CouchbaseLiteException e ) {
2028
+ e .printStackTrace ();
2029
+ }
2030
+
2031
+ Query listQuery =
2032
+ QueryBuilder .select (SelectResult .expression (Meta .id ).as ("metaID" ))
2033
+ .from (DataSource .database (this_Db ));
2012
2034
2013
- // end::query-syntax-id[]
2035
+ // end::query-syntax-id[]
2014
2036
2015
2037
2016
2038
// tag::query-access-id[]
@@ -2042,14 +2064,21 @@ public void testQueryPagination() throws CouchbaseLiteException {
2042
2064
2043
2065
2044
2066
// tag::query-syntax-pagination[]
2067
+ try {
2068
+ this_Db = new Database ("hotels" );
2069
+ } catch (CouchbaseLiteException e ) {
2070
+ e .printStackTrace ();
2071
+ }
2072
+
2045
2073
int thisOffset = 0 ;
2046
2074
int thisLimit = 20 ;
2047
2075
2048
2076
Query listQuery =
2049
2077
QueryBuilder
2050
2078
.select (SelectResult .all ())
2051
2079
.from (DataSource .database (this_Db ))
2052
- .limit (Expression .intValue (thisLimit ), Expression .intValue (thisOffset )); // <.>
2080
+ .limit (Expression .intValue (thisLimit ),
2081
+ Expression .intValue (thisOffset )); // <.>
2053
2082
2054
2083
// end::query-syntax-pagination[]
2055
2084
0 commit comments