Retrieving Data with @DbColumn and @DbLookup

Table of contents:

All database languages have the capability to look up reference or other information, and nearly all applications use this capability at some point. Domino applications frequently use formulas for keyword fields that can look up information within the same database, other Domino databases, or even foreign databases. @DbColumn() and @DbLookup() are the most frequently used @Functions to retrieve data, although @DbCommand() can also be used against ODBC data sources.

NOTE

@DbColumn() , @DbLookup() , and @DbCommand() can return no more than 64KB of data. If you run into this barrier , use @PickList() .

 

The function @DbColumn() returns a list of values from the specified column of a view. The view can be in the current database or in another database. The function @DbLookup() also returns a list of values from a specified column in a view. Unlike @DbColumn() , which loads whatever is in the column into memory, @DbLookup() enables you to specify a key value. This value is compared against the first sorted column in the view, and only values from documents matching the key are retrieved. The following code, which is from an action button that looks up departments and enables the user to choose a supervisor from a list of supervisors for that department, illustrates the use of @DbColumn() and @DbLookup() :

REM "Look up the departments" ; 
jcHRLookupID := @GetProfileField("GP"; "cHRLookupID");

jcDeptList := @DbColumn( ""; jcHRLookupID ; "LUDEPT";1) ;

jcDept := @Prompt([OKCANCELLIST]; "Departments" ;
 "Choose a department" ; "" ; jcDeptList ) ;
@If(jcDept = ""; @Return(""); @Success) ;

REM "The Department code and description are concatenated";
REM "into a single view column" ;
jcDeptName := @Right(jcDept; " ") ;
REM "The Department code should be the first four characters";
REM "plus 00" ;
jcDeptCode := @Left(jcDept; 4) + "00";

@SetField("cDepartment"; jcDeptName) ;
@SetField("cCostCenter"; jcDeptCode);

REM "Present a list of supervisors from the Cost Center to the user";
jcSuperList := @DbLookup(""; jcHRLookupID; "SDN";
 cCostCenter; "cSuper");
jcSupervisor := @Prompt([OKCANCELLIST]; "Supervisors";
 "Choose a Supervisor"; ""; jcSuperList );
@SetField("cSupervisor";@If(@IsError(jcSupervisor); "";
 jcSupervisor)) ;

The syntax of @DbColumn() and @DbLookup() is quite similar, as you can see in the following:

@DbColumn(Class : NoCache ; server : database ; view name; column number) 
@DbLookup(Class : NoCache ; server : database ; view name; key value; column number or
graphics/ccc.gif
field name)

Class refers to the database type. You can refer to Notes databases as "Notes" or with double quotes. NoCache tells Notes not to store the results in memory (the default). Storing the results of the lookup can provide performance improvements for lookups against data that doesn't change very often. Server can be represented by the name of the server or with double quotes, indicating the current server. Database can be the current database, represented by double quotes, or it can be the replica ID of a database. It can also be the operating system filename. If you choose to use the filename, you must include the path relative to the data directory on the server. The view name can be either the name of a view or its alias. Note that for @DbColumn() , you must specify the column number, whereas with @DbLookup() , you can specify either the column number or the name of a document field. The document field does not have to be present in the view.

Using Hidden Views

It is often a good idea to use a hidden view to look up reference information. You can hide a view by enclosing its name in parentheses. You can also indicate the purpose of the view by placing the characters "LU," for "look up" at the beginning of the view name. This tells other developers about the purpose of the view. The code sample uses a hidden view with the name (LUDept) and an alias of LUDept.

The functions @DbColumn() and @DbLookup() can also be used to perform ODBC lookups. ODBC stands for Open Database Connectivity, a standard that supports connectivity among different database sources. For example, you can install an ODBC driver for SQL Server, Sybase, or any one of a number of different databases. When the ODBC source is configured, you can use it to look up information in the foreign database by passing a table name, a key column, and a key value for @DbLookup() , or by specifying a table name and column name for @DbColumn() . For example, if you were to look up the department information in a SQL Server table, you might use the following code:

@DbColumn("ODBC" : "NoCache"; "HR Lookup"; skern : nreks; Department; cDeptName;
graphics/ccc.gif
"Distinct" : "Ascending")

TIP

For those of you with SQL in your background, you can pass a SQL statement to an ODBC source using @DbCommand .

 

CAUTION

A risk is associated with using ODBC sources in your applications. The users must have appropriate access to the data source. If a user cannot read the ODBC source, the lookup will fail. To get around this problem, you can use DECS or a data-integration product such as the Lotus Enterprise Integrator.


Part I. Introduction to Release 6

Whats New in Release 6?

The Release 6 Object Store

The Integrated Development Environment

Part II. Foundations of Application Design

Forms Design

Advanced Form Design

Designing Views

Using Shared Resources in Domino Applications

Using the Page Designer

Creating Outlines

Adding Framesets to Domino Applications

Automating Your Application with Agents

Part III. Programming Domino Applications

Using the Formula Language

Real-World Examples Using the Formula Language

Writing LotusScript for Domino Applications

Real-World LotusScript Examples

Writing JavaScript for Domino Applications

Real-World JavaScript Examples

Writing Java for Domino Applications

Real-World Java Examples

Enhancing Domino Applications for the Web

Part IV. Advanced Design Topics

Accessing Data with XML

Accessing Data with DECS and DCRs

Security and Domino Applications

Creating Workflow Applications

Analyzing Domino Applications

Part V. Appendices

Appendix A. HTML Reference

Appendix B. Domino URL Reference



Lotus Notes and Domino 6 Development
Lotus Notes and Domino 6 Development (2nd Edition)
ISBN: 0672325020
EAN: 2147483647
Year: 2005
Pages: 288

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net