Any way to intercept an error message and make more user friendly? - oracle

I have looked for an answer here among other places but havent quite been able to find what I need to know.
I have 3 tables, Order_Details, Products_Ordered and Product_Details. The first two are being used in a master detail form to show the order and the items ordered together. The Products_Ordered table has a composite primary key made from two foreign keys, the first being the primary key from the Order_Details table, and the second being the primary key from the Product_Details table. Together they ensure that a type of product can only be added to an order once. If someone wants to order more than one product then the quantity field in the record can be altered to reflect this. All that seems fine so far.
My issue is that when adding products to the order in the master detail form i have used a drop down list of values to select the product to add to the order. the display value for this is the product name and the return value for it is the primary key for the product from the Product_Details table.
I like this because its easier for the user to simply select the product and add a quantity of it to the table. And it works fine for both insert and update operations apart from one situation.
If the user selects the same product in to rows then submits the table the database then tries to add the product to the order twice, throwing a "ORA-00001: unique constraint violated." error. Obviously this is because of the product ID being used in the primary key of the table.
I don't want to allow the user to add two records to the table like that, rather id like to force them to alter the quantity field accordingly. The error message that comes up isn't very user friendly so my question is how can I detect this error and display a more user friendly one instead telling them to alter the quantity field instead?
*If this isn't possible then is there a way that I can hide any already selected products from the dropdown list of values in the following table rows? I haven't looked into this too much because surely it would get complicated when the user tries to add more rows than products available in the dropdown and there are no more products values to show?
I am quite new to this so please be nice. Any help is greatly appreciated :D

Here is a link where all is nicely described:
https://docs.oracle.com/cd/A97630_01/appdev.920/a96624/07_errs.htm
Section
Predefined PL/SQL Exceptions
in combination with:
Defining Your Own PL/SQL Exceptions
and
Defining Your Own Error Messages: Procedure RAISE_APPLICATION_ERROR
Hope it helps...

Related

preventing users to create duplicate primary keys

How would you prevent users to create duplicate primary keys?
My question is worded quite poorly so ill give an example to make it more clear (not sure how to put this in better words).
Let's say there are two users who are both trying to insert an item into our db. Now the ID (primary key) for this item is auto-incremented by 1 whenever a new item is inserted.
When two users try to insert an item into the db at the same time, the moment they insert the item, both items would be assigned with same ID but with different details and hence would cause a problem later when we look up that item b/c now there are two items with same ID.
How would you prevent this from Oracle?
Please comment if my question is not clear!

How to insert rows in phpMyAdmin

I have a database which I've opened in phpMyAdmin. I clicked the "Insert" button, which has an icon showing one row being inserted between two others.
When I actually try to insert a row, I get the following error:
1062 - Duplicate entry '294' for key 'PRIMARY'
How do I get phpMyAdmin to insert a row (presumably by increasing all the higher-numbered rows by 1) as the icon and the term "Insert" implies? It only seems to want to "Add" a row to the end, not "Insert" it.
As I said, the icon specifically shows one row being inserted between two others, and this is what I want to do. How do I get it to do what it claims it will do?
First, "INSERT" is standard SQL terminology for putting something in the database; it doesn't specifically mean "putting it between two existing values". I see how the icon can be a bit confusing, but when "insertting" data there is no difference between putting something at the end or in the middle of the database. For that matter, there's no real inherent order to data stored in a database; you can select many different ways to sort it when you display the data (and phpMyAdmin generally does a good job of guessing what's reasonable), but data just exists. You can select to sort it by the primary key or alphabetically by user name or any means you wish.
Second, your primary key shouldn't change. It's the key that holds your data together; if you start changing that your references from other tables will be messed up (see below). So don't change that.
Third, if you have your primary key set up with auto_increment (the A_I checkbox in phpMyAdmin), then you shouldn't ever need to set it or worry about it yourself. It's all managed by MySQL. If you aren't happy with the order and want to move 294 to 295 so you can insert something else at 294, then your database design needs tweaking because that's not how auto_incrementing primary keys are designed to work. As a simple solution, you may wish to create another field called "sort_value" or something that you can change.
Which all brings me to the root cause of your trouble: you're trying to create a new row while reusing an existing auto_increment value, and MySQL is smart enough to know this is a bad idea.
So as I said above, changing your primary key (whether or not it's auto generated) is a bad idea, but it may not be obvious why if you only have one table. But relational databases are designed so that you can reference tables from other tables, so for instance a customer database might have a table for "customers", "products", and "purchases" where the purchases table references the primary key ID from both customers and products...imagine the carnage your data would see if you then change the value of those keys in the customer table. You'd show customers associated with some other customer's purchases. So it might not make sense in your database, but overall that's the best way to handle things.
If you really, really don't want to change your database structure, don't reference that key from any other tables, and don't want to listen to my advice, you should be able to simply turn off the auto_increment function on your primary key and reorder them however you wish.

Oracle forms hybrid validation

This is my first post ever and haven't come across any other questions related to this. I am attempting to try and create a hybrid validation type and add it to an existing oracle form. We have a super/subset type of thing going on. When one chooses something from a dropdown, there are 5 options. If 4 of those options are chosen, the data is pulled from one validation table dataset, table A. If the other option is chosen, it comes from a different table's dataset, table B. These (along with others items) are saved in Table C. Table C has a FK constraint regarding these validations. I have added another column to table C to attempt to bypass the FK constraint, but the field still tries to save in the FK column. I can't seem to figure out if I need to add a database trigger, an item level trigger, or a form level trigger to reroute the data to correct columns in the database. Thanks in advance for any help!
If your items are select lists, you would use an item level trigger (when-validate-item) on the superset list item to populate/repopulate the list for the subset item.
Alternatively, you could use a popup LOV on the subset item which has a query which is filtered by the value of the superset item.

FileMaker Pro -- Filtering Relationship Not Working

I'm trying to build a FileMaker Pro 11 layout that excludes records containing a certain value. The relevant data is in table Invoice. I want to filter so that Invoice records whose "Invoice Check Grouping" field is blank are not displayed on the layout.
I've added a global field to the invoice table called "Blank Invoice Check Grouping" to use as my filter criteria. I've created a self-join relationship to the Invoice table, joining "Invoice ID" to "Invoice ID" and joining "Invoice Check Grouping" to "Blank Invoice Check Grouping". The resulting table is named "Invoice Check Groupings".
The layout which I build based on table "Invoice Check Groupings" shows all records in Invoice--it does not filter out those with blank values. What am I doing incorrectly?
Thanks,
Ben
Layouts show records in a table (or more accurately, a table occurrence) and don't directly deal with related data. As mentioned by #pft221, you can use relationships for filtering, but only when viewing data through a portal.
If you always want a particular layout to show data based on a particular find, you can do so with a script and a script trigger. First set up a script to do the following:
Enter Find Mode[]
Set Field["Invoice Check Grouping"; "*" // Find all records with any data in this field
Perform Find[]
Note that you can also embed the find request within the Perform Find script step, but I tend to script finds in the above manner as it's easier to see what the find request is in the script and variables can be used in the find request.
Now you need to set your layout to execute this script whenever it's loaded. Go to the layout and enter Layout Mode. Select Layouts>Layout Setup from the menu bar. Click the Script Triggers tab and check the box for OnLayoutEnter and select the script you wrote above. Now whenever the layout is entered, that script will run and exclude the records that have that particular field being empty.
There are many ways to filter records, depending on what you are trying to do and what you are trying to display for your users.
The most common and simple way you can filter records is through a simple Find in a list view. I'm unclear from your question, but my best guess is that you're already using a list view and misunderstanding how FileMaker's relationships and Table Occurrences (TO's) work.
To Filter with the "Find Records" method:
Create a new List View layout of any Table Occurrence of your Invoice Table -- most likely you will want to use the default Table Occurrence that FileMaker created for you when you created the table.
Place the fields that you would like to display on that layout, including the "Invoice Check Grouping" field.
Switch into Find Mode
Put a '*' character into the "Invoice Check Grouping" field
Perform the Find
You should now see a list of all Invoices where the "Invoice Check Grouping" field is not blank. (You can find additional interesting search criteria in the "Insert: Operators" drop down of the title bar.)
Now you may actually be looking to filter related records through a portal but, given that you've set up a self-join on the Invoice index on the Invoice table my guess is that, at best, this would show either 0 or 1 record for each Invoice record you display in your main layout.
To Filter Records with the "Portal Filter" method:
Let's assume, though, that you have a Client table where you'd like to see only the records with a non-blank "Invoice Check Grouping" value. The table set-up would be as follows:
Client
Client ID
[... other client info ...]
Invoice
Invoice ID
Client ID
Invoice Check Grouping
[... other invoice info ...]
With a relationship in the relationships graph:
Client::Client ID ------< Invoice::Client ID
From there you would set up a Form layout on the Client TO and create a portal showing records from the Invoice TO. From the options for the portal you would select "Filter Portal Records" and use a formula similar to:
not IsEmpty(Invoice::Invoice Check Grouping)
Finally, it's worth noting that a portal filter isn't appropriate for all display situations or calculations. You can set up a similar filter completely through your relationships graph (as I believe you have already tried to do.) This will work, once again, for viewing records through a portal but not for the records displayed by a layout itself.
The answers above don't actually help Ben with his question. They are workarounds.
I have the same problem as Ben, and I don't think there is a solution, even now in Filemaker 12. There is I think no way to define a relationship that will omit the related records where the match fields are empty.
Two options come to mind:
On a specific layout, you have more fine-grained control in the portal definition itself, and can use this to exclude the records
You can now use SQL queries to achieve this result within Filemkaer.

configurable product Issue

I am facing a problem while making product configurable i used this link http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-configurable-product/ but In associated tab the products doesnt show up
Thankds and regards
2 things you can check:
Are you sure that the simple products you want to associate to the configurable product actually have values for the attribute you made the configurable product configurable by? So if you made a configurable product based on 'color', do the simple products have values selected for 'color'?
When you are looking at the associated products tab, and seeing the blank grid there, have you tried resetting the filter, or selecting 'No' or 'Any' in the first column? If it is set to 'Yes', it is only looking for products that have already been associated.
How does configurables products linking works in magento ?
Getting rid of being trolled by the linking of configurables products with their simple counterparts ? Let's explain how does Magento link'em... and why it sometimes doesn't work as expected.
The first point to understand is how the data persistence is managed by the application. As expected, links are stored in database. Thought it was in catalog_product_relation ? You were wrong. It should be too simple to respect the Magento's spirit :)
catalog_product_relation vs catalog_product_super_* tables
I won't tell catalog_product_relation is useless – in fact, it's necessarily there for something. But from version 1.5+, this is not there that links are stored, and I can't explain what does its purpose is.
First step
The first step of the linking process is the definition of the configurable product's configurable attributes. Supposing we're creating a new configurable product from an attribute set having a few global-select attributes.
If you try to access to your configurable product, the application will ask you which of 'em should be used as configurable attributes, in a form using a list of checkboxes associated to each attribute. By selecting some and saving your product, you insert in catalog_product_super_attribute a row by attribute (an association between product's id and attribute's one).
Second step
The second step is the linking itself with the associated simple products. This step is a bit more complex, because it implies some checks of the database's content, which we'll detail further below. Some rules to keep in mind about that :
only products having the same attribute set as the current configurable product
options must be defined for the configurable attribute
only one simple can be linked for a given configurable attribute combination
simple can be linked to as many configurables as desired
Then, what happens when we go to our configurable's associated products tab ? Don't be scray to not see any of your simple-corresponding-product in the list that display – it's filter is configured by default to display only already linked products. Here is what happens behind the scene :
the application go check the catalog_product_super_attribute table, and bring back each corresponding attribute id defined there for the current product (our configurables attributes)
from them, it will go check eav_attribute to get some details about them – in which ones the backend_type, which is the more important part of this explanation
parallely, the catalog_product_super_link table is checked too. Any product linked to current_product is a potential linked product
for each attribute, the application check if a value exists in catalog_product_entity_{backend_type} for each potentially linked product. Note that if no value exists for a given product, it won't be validated nor as a potential link nor than an effective one, even if it has already been linked (we'll see below what it implies for attribute creation).
To resume, only products with a valid value are diplayable and effectively linked / linkable. Note that all of the combination must have valid values – if any of the configurable's attribute as none, game over, you'll not have any link between your simple product and its configurable counterpart.
We should think it's ok, and everything will go right now, since we know how everything works in database. That's true if you always create your attributes from the application's back-office. But since scripting attributes is a very common way to proceed, you're much like to be in this second case, which implies a potential HUGE problem.
Programatically created attributes and... What the hell !?! This attribute has change of backend type !
Edit note: this case happens effectively when using a eav/entity_attribute_source_table source model
This a trouble I personnally runned through. If you check attributes backend models in database (only for select attributes – we do not care about which ones are not usable as configurable's ones), you'll see some varchar, some int... In short, multiple ones, and we could rightfully expect any of them works.
And they do so. Since you do not decide to add an option to your attribute from the back-office, or anything else that require to click on the « save » button on the attribute page.
The point is that when you save your attribute, Magento, in it's great goodness, ask itself what is the type of the attribute you ask him to save. The point is that before anything else, it's a select. And a select has options. And options has id. Which are the values that will be put in catalog_product_entity_{backend_type}, in any case. The label is just properly ignored in that (it's stored in it's proper table and doesn't affect anything there). Only the id is used.
And what shall we expect from Magento :) ?
It just change the attribute backend type to int systematically.
So, if you have products that used to be linked and are no more, go check the catalog_product_entity_{backend_type} tables and the eav_attribute one – compare the backend type, look for values in each values table... If you find 'em in a table that does not correspond, you get your problem. You have a few ways to correct the problem, here are the both I find myself (and I really do not promote the first, which I put only for explanation purpose).
First way: get the backend type back (The Dirty Trick)
It has changed to int ? Don't care. Bring it back to what you want it to be.
Why it's dirty : because you want you user to be able to update it's attributes when he wants. If you update the backend type to varchar, for example, any label change in the back-office for an option will rollback to int as it will be saved.
Second way: let's correct everything ! (The Right Thing)
You can pass throught this... bad situation, with a bit of MySQL without harming your database. But please, first, dump it. Then you'll require 4 steps :
check that you don't already have the data in catalog_product_entity_int table
duplicate the rows of the current ...entity{attribute} table to the ..._entity_int one by using an INSERT / SELECT statement (this query can be a bit long)
update your configurable attributes (not all your attributes, ONLY the ones you know you have created and are use to set configurable products) to set their backend type to int (and never do something else again for configurable selects :) )
delete all entries corresponding to attribute in the ..._entity{attribute} table that you'll no more use (it can do pretty much entries since you can have a lot of products if you get a lot of options)
Here are some MySQL scripts, corresponding to these steps, supposing you have at start a list of the attributes codes concerned :
Check existing entries in entity int for a given list of attribute codes
-- Check existing entries to not duplicate
SELECT ea.attribute_code,
count(*)
FROM eav_attribute as ea
INNER JOIN catalog_product_entity_int as cpei
ON ea.attribute_id = cpei.attribute_id
WHERE ea.attribute_code IN(
{attributeCodesList}
)
GROUP BY ea.attribute_code
Duplicate entries from entity_varchar table (for example) to entity_int for a given list of attribute codes
-- Duplicating missed selects from varchat entity table to int
INSERT INTO catalog_product_entity_int (entity_type_id, attribute_id, store_id, entity_id, value)
SELECT cpev.entity_type_id,
cpev.attribute_id,
cpev.store_id,
cpev.entity_id,
cpev.value
FROM eav_attribute as ea
INNER JOIN catalog_product_entity_varchar as cpev
ON ea.attribute_id = cpev.attribute_id
WHERE ea.attribute_code IN(
{attributeCodesList}
)
Update attributes to never have the problem again!
-- Update missed select attributes from varchar backend type to int one
UPDATE eav_attribute as ea
SET ea.backend_type = 'int'
WHERE ea.attribute_code IN (
{attributeCodesList}
)
Remove the no more used entries from your database
-- Kill old varchar in varchar entity table
DELETE FROM catalog_product_entity_varchar
WHERE attribute_id IN (
SELECT ea.attribute_id
FROM eav_attribute as ea
WHERE ea.attribute_code IN (
{attributeCodesList}
)
)
Hope it will help all of the ones who can't make their associated products show up to get the trick!

Resources