contents   index   previous   next



SimpleDataset find() with template

syntax:

simpledataset.find(template1[, template2[, ...])

where:

templateN - Item template to search for. When more than one template is present, the templates are OR'd together.

 

Templates contain properties to match. Only those records which have properties that match those values will be included in the result set.

 

return:

boolean - value indicating success. In the case that the operation failed, use the getLastErrorCode() and getLastError() methods to determine the reason for the failure.

 

description:

This method searches the database table of a SimpleDataset for all items that match the given templates. The contents of the SimpleDataset are changed to reflect the results of the search. The previous contents of the SimpleDataset are cleared and the complete database table is searched to create the new contents.

 

After the find has completed, the current record is set to the record "before" the first record. Fill out the properties in the template to indicate which items to find. For instance, to find all records whose 'city' field equals "Metropolis", set the value of the 'city' property to "Metropolis". If a template has more than one property, the properties will be combined with an AND to form the search term.

 

More than one template can be used. If multiple templates are used, the template values will be combined using an OR to form the search term.

 

see:

#include <smdtset.jsh>, SimpleDataset findAll(), SimpleDataset findDistinct(), SimpleDataset caseSensitive

 

example:

// the following function will print out the fields

// of each of the records that have either Boston,

// USA or Paris, France as

// their city, country values

function print_BostonParis(db, table, user, passwd)

{

   // create the SimpleDataset

   var ds = new SimpleDataset(db, table,  user, 

                              passwd);

 

   var template1, template2;

 

   template1.city = "Boston";

   template1.country = "USA";

 

   template2.city = "Paris";

   template2.country = "France";

 

   ds.find( template1, template2 );

 

   while( var rec = ds.nextRecord() )

      for( var prop in rec )

         Clib.printf(prop + " = " + rec[prop] +

                     "\n");

 

   ds.close();

}

 


SimpleDataset find() with clause