<< Click to Display Table of Contents >> Navigation: Concordance Programming Fundamentals > Using Common CPL Functions > Searching Databases |
You can utilize Concordance’s powerful searching capabilities within CPL, using the search and query functions. It helps if you are proficient in constructing Concordance queries.
The search function allows you to search through a database for a specified string. The syntax for the search function is as follows:
int search(int db; text searchString; int options); |
The following table describes the parameter values.
Parameter |
Description |
db |
The database handle. |
searchString |
The search string to execute. Search strings are the same as the queries you would use in the standard search screen in Concordance. |
options |
Optional. For more information, see the CPL Language reference. |
The results of the search become the current query. The return value contains an error code, if any.
The advanced features of CPL allow you to automate the creation of complex queries. For example, you can search for data in one database and use the results to populate the fields of another database. You can automate the searching in multiple databases to search and replace a misspelled word.
You are a paralegal and are preparing a database for trial. You suddenly get a call from your vendor telling you that the database they sent you two months ago was coded incorrectly. You hadn’t realized it, but an important field was never coded, the DOCTYPE field. They send you an update to the database, but you are faced with a dilemma. For the past two months, the attorneys have been using the database and entering comments into the COMMENTS field. You obviously do not want to overwrite this database. You need to quickly whip up a short CPL to do the job for you.
Let’s assume for this example that you have a field called BEG_BATES and END_BATES which together uniquely identify the same document in both databases. We’ll also assume your database is currently open and the database from your vendor is in the following directory:
C:\temp\vendor.dcb
Here’s what the CPL would look like:
main() { int db, db2; db2 = opendb("c:\temp\vendor.dcb");
cycle(db) { search(db2, "BEG_BATES = " + db->BEG_BATES + " and END_BATES = " + db->END_BATES); db->DOCTYPE = db2->DOCTYPE; }
closedb(db2); } |
The query function switches the current query to a new query. The syntax for the query function is as follows:
int query(int db, number; text string); |
The following table describes the parameter values.
Parameter |
Description |
db |
the database handle of the database to search. |
query |
The query number to switch to. Note that Concordance sequentially numbers the searches you execute. Query number 0 represents your entire database (with no query). In order for you to keep track of the queries you perform in CPL, you may wish to store the value of db.query or |
If successful, the current query becomes the specified query. The return value contains an error code, if applicable.