Accessing Database Information

<< Click to Display Table of Contents >>

Navigation:  Concordance Programming Fundamentals > Working with the Database >

Accessing Database Information

There will be times when you’ll need to access general database information such as the number of fields in the database, the names of the fields, how many records are currently in the database, and so on. For these situations, you use certain keywords in conjunction with the database handle. For more information about accessing fields in a database that are not part of the general database infrastructure, see Accessing Database Field Information.

To access database information

1.Create a handle to the database you wish to access.

i.For many applications, this will be the currently-open database. The following example creates a handle to the current database. For more information, see Understanding Database Handles.

int db;

2.Determine the keyword you wish to access.

i.For example, one such keyword is database, which holds the name of the handle's database. For more information on the keywords you can use, see the table below.

3.Concatenate the keyword at the end of the handle, using a period to separate the two.

i.The following example shows how to fill the text variable myDatabasename with the name of a database.

text myDatabaseName;

myDatabaseName = db.database; 

4.If the keyword has brackets [] listed after it, treat the keyword as an array, and use an integer to indicate which part of the array you wish to access.

i.Note that unlike normal arrays, database field arrays begin with 1, rather than 0. The following example checks to see if the 4th field is a paragraph field.

if (db.type[4] == ‘P’) 

{

     doSomethingHere();

}

 

For more information on arrays, see Creating and using an Array.

The following table contains a list of keywords to use when accessing a database.

Keyword

Type

Description

access[ ]

int array

This provides the user’s access rights to a field. This can be no-access, read access only, write access only, or read and write access.

activequery

int

Current active query.

database

text

Database name.

documents

int

Number of documents in the database.

edited

int

Non-zero if the database needs reindexing.

fields

int

True if the subscripted field is an image key.

image[ ]

int array

True if the subscripted field is a key field.

key[ ]

int array

True if the subscripted field is a key field.

length[ ]

int array

The defined length of the subscripted field. For date fields, this will return the format, i.e. ‘Y’, ‘M’ or ‘D’ for yyyy/mm/dd, mm/dd/yyyy, or dd/mm/yyyy respectively.

name[ ]

text

The name of the subscripted field.

order[ ]

int array

The order in which the subscripted field is used by load, unload, global, and other functions.

places[ ]

int array

Number of places in numeric fields.

query

int

The number of the last executed query.

type[ ]

text array

The field type of the subscripted field, either ‘T’ for text, ‘P’ for paragraph, ‘D’ for date, or ‘N’ for numeric fields.