Console

The DynamicSelect console sample demonstrates retrieving a table from an instance of Relativity Server where only certain fields are retrieved, using the getDataTable:select:where: and beginGetDataTable:select:where:withBlock: methods of DARemoteDataAdapter. This is useful when you are only interested in a subset of the data.

Getting Started

The Console sample is typically located in /Developer/RemObjects Software/Samples/Data Abstract/Console/DynamicSelect, though you may have installed the Data Abstract for Cocoa and it's samples in another location.

To build it, you will of course need Xcode, and like all the samples provided with Data Abstract for Cocoa you will need to be running the Relativity Server with the DASamples Domain and the Simple Schema available.

Lastly this sample makes use of a convenience method (DALogTable) provided by a class extension to NSArray that we ship with Data Abstract for Cocoa. It is actually a #define method that uses one of three new log methods added to NSArray to print the contents of a DADataTable in a pretty fashion to the console using NSLog. To use this in your own code you must add the following to your import statements #import <DataAbstract/NSArray+DADataTableLog.h>. Please note that this class extension is intended for test purposes only.

Running the Sample

The sample when run sets up a connection to an instance of Relativity Server (Step 1). It then uses the synchronous method getDataTable:select:where: to request a copy of the Clients table from the server where only the ClientId and ClientName fields are selected (Step 2). This request is again repeated, though this time the ClientName and ClientPhone fields are selected (Step 3). Finally the sample uses the asynchronous method, beginGetDataTable:select:where:withBlock:, to retrieve the Clients table with only ClientName and ClientPhone fields selected (Step 4).

Examining the Code

The code for creating the connection to the server and handling logging in is covered by other samples. In this section we shall focus solely on Steps 2, 3 and 4 that request the Clients table with only the selected rows. All of the code can be found in the main.m source file.

Using getDataTable:select:where: (Steps 2 & 3)

To retrieve only selected fields when you request a table you need to pass an array of field names to the select: argument of getDataTable:select:where:. The array should contain strings which match the field names in the table, otherwise an ROException will be throw. Here we are requesting the Clients table and that each returned row only contains the ClientId and ClientName fields.

The where: argument is for an optional Dynamic Where clause, we simply pass nil here. To see an example of using Dynamic Where see the Dynamic Where sample.

DADataTable *table = [dataAdapter getDataTable:@"Clients"
                                        select:@[@"ClientId", @"ClientName"]
                                         where:nil];

Using beginGetDataTable:select:where:withBlock: (Step 4)

This is similar to the previous request, except that it uses an asynchronous form of the method to spin the table request into a background thread and return control to the main thread. The beginGetDataTable:select:where:withBlock: has one additional argument that is the block to execute when the request is complete. Here it simply prints the table to the console and sets the bool flag done to YES which will allow the sample to end.

The where: argument is for an optional Dynamic Where clause, we simply pass nil here. To see an example of using Dynamic Where see the Dynamic Where sample.

[dataAdapter beginGetDataTable:@"Clients"
                                   select:@[@"ClientName", @"ClientPhone"]
                                    where:nil withBlock:^(DADataTable *t) {
                                        NSLog(@"Data has been retrieved");
                                        DALogTable(t);
                                        done = YES;
                                    }];
NSLog(@"Waiting for completion asynchronous GetData call...");
while(!done && [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);

Example Output

This is an example of the output you will see when the sample is run.

Dynamic Select sample has been started.
Target URL is http://localhost:7099/bin.
RO SDK layer is configured.
Trying to login with login string User=simple;Password=simple;Domain=DASamples;Schema=Simple...
Login successfull

STEP 2. Select ClientId and ClientName fields only ...
TABLE: Clients (24 rows from 24)
-----------------------------------
| ClientId| ClientName            |
-----------------------------------
| 1       | Mollie Bennett (edited|
| 2       | Gale Dalton           |
| 3       | Matthew Decker        |
| 4       | Joseph Henson234      |
| 5       | Jennifer Kent         |
| 6       | Sandy Manning         |
| 7       | Glenn Cunningham      |
| 8       | Marcy Collins         |
| 9       | Kirsten Rosario       |
| 10      | Merle Frank           |
| 11      | Will Smith            |
| 12      | John Doe              |
| 13      | Ian G. Kim            |
| 14      | Jermaine M. Miller    |
| 15      | Jean C. Gates         |
| 16      | David M. Lee          |
| 17      | Jennifer K. Jones     |
| 18      | Brian L. Rowles       |
| 19      | Angela W. Vanover     |
| 20      | Anna H. Kugler        |
| 21      | Randy R. Howard       |
| 22      | Kenny S. Lay          |
| 23      | Maryann C. Bachmann   |
| 24      | Lillie R. Schroeder   |
-----------------------------------

STEP 3. Select ClientName and ClientPhone fields only ...
TABLE: Clients (24 rows from 24)
-------------------------------------------------
| ClientName            | ClientPhone           |
-------------------------------------------------
| Mollie Bennett (edited| (171) 555-1212        |
| Gale Dalton           | 0221-0644327          |
| Matthew Decker        | (503) 555-3612        |
| Joseph Henson234      | (939)399-99-99        |
| Jennifer Kent         | (11) 555-7647         |
| Sandy Manning         | (1) 354-2534          |
| Glenn Cunningham      | 0522-556721           |
| Marcy Collins         | (14) 555-8122         |
| Kirsten Rosario       | (930)930-30-93        |
| Merle Frank           | (415) 555-5938        |
| Will Smith            | (714) 256-0552        |
| John Doe              | (612) 276-0136        |
| Ian G. Kim            | (612) 276-0136        |
| Jermaine M. Miller    | (814) 343-0945        |
| Jean C. Gates         | (757) 382-4391        |
| David M. Lee          | (704) 718-1664        |
| Jennifer K. Jones     | (859) 491-4222        |
| Brian L. Rowles       | (908) 385-7809        |
| Angela W. Vanover     | (610) 463-9999        |
| Anna H. Kugler        | (817) 249-9525        |
| Randy R. Howard       | (234) 567-8909        |
| Kenny S. Lay          | (817) 249-9525        |
| Maryann C. Bachmann   | (907) 722-6777        |
| Lillie R. Schroeder   | (312) 476-1404        |
-------------------------------------------------

STEP 4. The same as previous step but Asynchronous ...
Begin to select ClientName, ClientPhone from Clients ...
Waiting for completion asynchronous GetData call...
Data has been retrieved
TABLE: Clients (24 rows from 24)
-------------------------------------------------
| ClientName            | ClientPhone           |
-------------------------------------------------
| Mollie Bennett (edited| (171) 555-1212        |
| Gale Dalton           | 0221-0644327          |
| Matthew Decker        | (503) 555-3612        |
| Joseph Henson234      | (939)399-99-99        |
| Jennifer Kent         | (11) 555-7647         |
| Sandy Manning         | (1) 354-2534          |
| Glenn Cunningham      | 0522-556721           |
| Marcy Collins         | (14) 555-8122         |
| Kirsten Rosario       | (930)930-30-93        |
| Merle Frank           | (415) 555-5938        |
| Will Smith            | (714) 256-0552        |
| John Doe              | (612) 276-0136        |
| Ian G. Kim            | (612) 276-0136        |
| Jermaine M. Miller    | (814) 343-0945        |
| Jean C. Gates         | (757) 382-4391        |
| David M. Lee          | (704) 718-1664        |
| Jennifer K. Jones     | (859) 491-4222        |
| Brian L. Rowles       | (908) 385-7809        |
| Angela W. Vanover     | (610) 463-9999        |
| Anna H. Kugler        | (817) 249-9525        |
| Randy R. Howard       | (234) 567-8909        |
| Kenny S. Lay          | (817) 249-9525        |
| Maryann C. Bachmann   | (907) 722-6777        |
| Lillie R. Schroeder   | (312) 476-1404        |
-------------------------------------------------
Done!
Program ended with exit code: 0

NOTE: For clarity the date and process name and ID have been removed from the sample text above