devxlogo

Compound key

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 IntegerEXEC SQL SELECT COUNT(*) FROM ORDERS INTO :nCount  WHERE &         CUSTOMER = :fldCUSTOMER AND ORDER_ID = :fldORDER_IDIF nCount = 0 THENValidateRow = TRUEELSE        ValidateRow = FALSEEND 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.

See also  How IoT Tech Will Transform Logistics
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist