Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Beginner
Mar 24, 1997

Compound key

Question:
I want to use a unique compound key, with a string columns and a numeric column, in my table. Since Blaze does not support compound keys, I will have to check for uniqueness in my application. What's the best way to accomplish this?

Answer:
Although Blaze is being replaced by Oracle Lite in version 2.0, you may still have situations when you want to execute procedural code based on the value of more than one field in your application. You can use the technique described in this tip for any of these type of situations.

One of the issues you will have to wrestle with in a client/server environment is when to implement logic. In the case you describe, I will assume that you need a unique compound key for the row. Power Objects gives you a method that can be used to implement logic whenever the user tries to either commit a new or changed row or move from a new or changed row to a different row. This method is called ValidateRow(). The ValidateRow() method returns either True or False. If the method returns False, the action that triggered the method is not executed and OPO pops a message box with the message that is specified in the ValidateRowMsg property of the container.

Assuming that your table name was ORDERS, the two columns are called CUSTOMER and ORDER_ID and the data field objects that are bound to the columns are fldCUSTOMER and fldORDER_ID, the code for the ValidateRow() method would look like:

DIM nCount AS Integer
EXEC SQL SELECT COUNT(*) FROM ORDERS INTO :nCount  WHERE & 
        CUSTOMER = :fldCUSTOMER AND ORDER_ID = :fldORDER_ID
IF nCount = 0 THEN
ValidateRow = TRUE
ELSE
        ValidateRow = FALSE
END IF

You return the appropriate boolean value based on the value of the nCount variable. If the method returns False, the string specified in the ValidateRowMsg property is shown in a message box and the user action is not executed.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date