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.

Share the Post:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as