Magento upgrade 1.7 caused following error - sql

Admin panel works fine, but on front-end I get following error.
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous
Any idea what could this be?

Here is the solution i came up with, Many Thanks to Vern Burton.
Located table eav_attribute in phpmyadmin, which was related to catalog_eav_attribute.
Located column position in table eav_attribute and dropped it.
Cleared all cache and reindexed all data, visited front page and got a new error: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘main_table.include_in_menu’ in ‘where clause’
Located and opened file app/code/core/Mage/Catalog/Model/Resource/Category/Flat.php
Commented out following line:267 in my case ----
->where('main_table.is_active = ?', '1')
// ->where('main_table.include_in_menu = ?', '1')
->order('main_table.position');
I'm not really sure how esthetic this method is to fix this issue but, certainly works for me for now, If anyone has better way of fixing this I'd appreciate if you'll post your solution.
Hope this will help someone out, Cheers.
Next exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'position' in order clause is ambiguous' in /chroot/home/user/my_domain.com/magento_root/lib/Zend/Db/Statement/Pdo.php:234
Stack trace:
0 /chroot/home/user/my_domain.com/magento_root/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
1 /chroot/home/user/my_domain.com/magento_root/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
2 /chroot/home/user/my_domain.com/magento_root/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
3 /chroot/home/user/my_domain.com/magento_root/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT main_ta...', Array)
<br>4 /chroot/home/user/my_domain.com/magento_root/lib/Varien/Db/Adapter/Pdo/Mysql.php(419): Zend_Db_Adapter_Pdo_Abstract->query('SELECTmain_ta...', Array)
5 /chroot/home/user/my_domain.com/magento_root/lib/Zend/Db/Adapter/Abstract.php(734): Varien_Db_Adapter_Pdo_Mysql->query('SELECT main_ta...', Array)
<br>6 /chroot/home/user/my_domain.com/magento_root/lib/Varien/Data/Collection/Db.php(734): Zend_Db_Adapter_Abstract->fetchAll('SELECTmain_ta...', Array)
7 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php(521): Varien_Data_Collection_Db->_fetchAll('SELECT `main_ta...', Array)
8 /chroot/home/user/my_domain.com/magento_root/lib/Varien/Data/Collection/Db.php(566): Mage_Core_Model_Resource_Db_Collection_Abstract->getData()
9 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Catalog/Model/Layer.php(232): Varien_Data_Collection_Db->load()
10 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Catalog/Block/Layer/View.php(163): Mage_Catalog_Model_Layer->getFilterableAttributes()
11 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Catalog/Block/Layer/View.php(122): Mage_Catalog_Block_Layer_View->_getFilterableAttributes()
12 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Core/Block/Abstract.php(238): Mage_Catalog_Block_Layer_View->_prepareLayout()
13 /chroot/home/user/my_domain.com/magento_root/app/code/local/Mage/Core/Model/Layout.php(430): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout))
14 /chroot/home/user/my_domain.com/magento_root/app/code/local/Mage/Core/Model/Layout.php(446): Mage_Core_Model_Layout->createBlock('catalog/layer_v...', 'catalog.leftnav')
15 /chroot/home/user/my_domain.com/magento_root/app/code/local/Mage/Core/Model/Layout.php(238): Mage_Core_Model_Layout->addBlock('catalog/layer_v...', 'catalog.leftnav')
16 /chroot/home/user/my_domain.com/magento_root/app/code/local/Mage/Core/Model/Layout.php(204): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
17 /chroot/home/user/my_domain.com/magento_root/app/code/local/Mage/Core/Model/Layout.php(209): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
18 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
19 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Catalog/Helper/Product/View.php(73): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
20 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Catalog/Helper/Product/View.php(144): Mage_Catalog_Helper_Product_View->initProductLayout(Object(Mage_Catalog_Model_Product), Object(Mage_Catalog_ProductController))
21 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Catalog/controllers/ProductController.php(132): Mage_Catalog_Helper_Product_View->prepareAndRender(28491, Object(Mage_Catalog_ProductController), Object(Varien_Object))
22 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Core/Controller/Varien/Action.php(419): Mage_Catalog_ProductController->viewAction()
23 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('view')
24 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Core/Controller/Varien/Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
25 /chroot/home/user/my_domain.com/magento_root/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
26 /chroot/home/user/my_domain.com/magento_root/app/Mage.php(683): Mage_Core_Model_App->run(Array)
27 /chroot/home/user/my_domain.com/magento_root/index.php(87): Mage::run('', 'store')
28 {main}

Have you tried rebuilding your indexes? I had a similar problem, and that fixed it.

Related

Query with input parameter won't compile as a view

So I am trying to create a view that allows the user (from the front-end) query on it by specifying a specific date (in the form of a varchar/string). The view/query will then return data for the month of the specified date and also data for 13 months prior to it. When I run the following query and enter a valid 'string'/date , I am able to return results successfully. However, when I try to create a view with the same query, i am receiving the following error:
SQL Error: ORA-01027: bind variables not allowed for data definition operations
Below is the query:
SELECT person_name
, person_age
, person_dob
FROM person p
WHERE p.person_dob >= add_months(to_date(:par_date, 'yyyy-mm-dd'), -13);
Here is some sample data:
Person_Name Person_Age Person_DOB
Jon 18 01-01-1990
Jacob 21 09-04-1994
Heidi 28 04-02-2010
mark 30 05-02-2011
Helga 18 03-02-2015
Mike 18 01-02-1992
Larry 18 01-04-1993
I want to return the following result after specify :par_date as '2020-03-02'.
Person_Name Person_Age Person_DOB
Heidi 28 04-02-2010
mark 30 05-02-2011
Helga 18 03-02-2015
You unfortunately cannot do this. The closest you could come would be to create a table function, but that will be much less efficient than just selecting from the table with a 'WHERE' clause.
Ask Tom has a work around, but it is complex, much more work, and potentially very inneficient. Just use a 'WHERE' clause on the view or table
https://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:9536277800346269502

Returning the distinct records from a table with counts of instances

I have a database that logs requests made, and I'm trying to find the unique exceptions thrown for each request and the FK that each instance of that exception was thrown by. I've tried a number of different iterations but can't quite seem to find a workable solution so I figured I'd ask here since I'm sure I'm over-thinking this.
Sample data
Unauthorized User 42
Internal Server Error 57
Unauthorized Employee 88
Bad Request 57
Bad Request 42
Bad Request 42
Bad Request 42
Bad Request 42
Bad Request 42
Unauthorized User 57
Sample desired results
Unauthorized 42, 88, 57
Internal Server Error 57
Bad Request 42, 57
EDIT: The version is Sql server 2014 and I changed the data from images to inline text as requested. I'm happy with the answer but for bonus I'm adding in the following condition of the source data having similar exceptions but wanting them to be grouped together like the unauthorized exceptions being grouped.
What I have so far:
Select r.Exception, stuff(
(select distinct FK + ','
from [Table] wr
where r.Exception = wr.Exception
for XML PATH('')),1,0,''
) as [FKs]
From [Table] r
Group by r.Exception
SQL Server (starting with 2017)
SELECT Exception, STRING_AGG (FK, ',') AS FK
FROM YourTable
GROUP BY Exception;
OR
Optimal way to concatenate/aggregate strings

Second highest column

I have seen a similar question asked How to get second highest value among multiple columns in SQL ... however the solution won't work for Microsoft Access (Row_Number/Over Partition isn't valid in Access).
My Access query includes dozens of fields. I would like to create a new field/column that would return the second highest value of 10 specific columns that are included in the query, I will call this field "Cover". Something like this:
Product Bid1 Bid2 Bid3 Bid4 Cover
Watch 104 120 115 108 115
Shoe 65 78 79 76 18
Hat 20 22 19 20 20
I can do a really long SWITCH formula such as the following equivalent Excel formula:
IF( AND(Bid1> Bid2, Bid1 > Bid3, Bid1 > Bid4), Bid1,
AND(Bid2> Bid1, Bid2 > Bid3, Bid2 > Bid4), Bid2,
.....
But there must be a more efficient solution. A MAXIF equivalent would work perfectly if MS-Access Query had such a function.
Any ideas? Thank you in advance.
This would be easier if the data were laid out in a more normalized way. The clue is the numbered field names.
Your data is currently organized as a Pivot (known in Access as crosstab), but can easily be Unpivoted.
This data is much easier to work with if laid in a more normalized fashion which is this case would be:
Product Bid Amount
--------- ----- --------
Watch 1 104
Watch 2 120
Watch 3 115
Watch 4 108
Shoe 1 65
Shoe 2 78
Shoe 3 79
Shoe 4 76
Hat 1 20
Hat 2 22
Hat 3 19
Hat 4 20
This way querying becomes simpler.
It looks like you want the maximum of the bids, grouped by Product, so:
select Product, max(amount) as maxAmount
from myTable
group by product
Really, we shouldn't be storing text fields at all, so Product should be an ID number, with associated Product Names stored once in a separate table, instead of several times in the this one, like:
ProdID ProdName
-------- ----------
1 Watch
2 Shoe
3 Hat
... but that's another lesson.
Generally speaking repeating of anything should be avoided... that's pretty much the purpose of a database... but the links below will explain than I. :)
Quackit : Microsoft Access Tutorial
YouTube : DB Planning
Microsoft : Database Design Basics
Microsoft : Database Normalization Basics
Wikipedia : Database Normalization

Too many results - SQL join issues

I've never posted here, so hoping this goes well :). I am using SQL Server 2008 R2 and I am trying to extract Student/Course information from a database. Here is what I am dealing with:
Table dbo.StudentsSchedule
StudentsSchedule table contains the following fields:
CRS_CODE
CRS_SECT
ID_NUMBER
Table dbo.StaffSchedule:
COURSE
SECTION
Teacher_ID
Here is what I am trying to accomplish:
I would like to combine the COURSE+SECTION CODE+Teacher_ID to use that as a Unique "New Course ID" and then attach a Student to it.
I've attempted this but I am getting way too many results. I am expecting around 300 but receiving over 10K+
SELECT dbo.StaffSchedule.COURSE+'-'+ dbo.StaffSchedule.SECTION+'-'+dbo.StaffSchedule.Teacher_ID) as [NewCourseID],
dbo.StudentSchedule.ID_NUMBER AS [StudentID],
from dbo.StaffSchedule INNER JOIN dbo.StudentSchedule ON
dbo.StaffSchedule.COURSE=dbo.StudentSchedule.CRS_CODE and
dbo.StaffSchedule.SECTION=dbo.StudentSchedule.CRS_SECT
Note that Teacher_ID can only exist once per COURSE+SECTION.
Any ideas? Am I doing this wrong?
Lets try to see it
Table dbo.StaffSchedule:
COURSE SECTION Teacher_ID
1 1 23
1 1 24
1 3 55
1 3 24
Table dbo.StudentsSchedule:
CRS_CODE CRS_SECT ID_NUMBER
1 1 44
1 1 45
1 3 89
1 3 44
This code:
SELECT dbo.StaffSchedule.COURSE+'-'+ dbo.StaffSchedule.SECTION+'-'+dbo.StaffSchedule.Teacher_ID) as [NewCourseID], dbo.StudentSchedule.ID_NUMBER AS [StudentID]
from dbo.StaffSchedule INNER JOIN dbo.StudentSchedule ON
dbo.StaffSchedule.COURSE=dbo.StudentSchedule.CRS_CODE and
dbo.StaffSchedule.SECTION=dbo.StudentSchedule.CRS_SECT
will return:
NewCourseID StudentID
1-1-23 44
1-1-23 45
1-1-24 44
1-1-24 45
1-3-55 89
1-3-24 89
1-3-55 44
1-3-24 44
May be the only problem I see is that for the same StudentID you have more than one value. I don't know what are you specting, so this is hoy much I can help you.
Sorry for my bad english! I hope this can help!
EDITE FOR NEW COMMENT
Is really simple to not use de Section in the NewCourseId
SELECT dbo.StaffSchedule.COURSE+'-'+dbo.StaffSchedule.Teacher_ID) as [NewCourseID], dbo.StudentSchedule.ID_NUMBER AS [StudentID]
from dbo.StaffSchedule INNER JOIN dbo.StudentSchedule ON
dbo.StaffSchedule.COURSE=dbo.StudentSchedule.CRS_CODE and
dbo.StaffSchedule.SECTION=dbo.StudentSchedule.CRS_SECT
But... what will happen?
The result will be:
NewCourseID StudentID
1-23 44
1-23 45
1-24 44
1-24 45
1-55 89
1-24 89
1-55 44
1-24 44
Look what happened whit the ID 1-24, it's look to has duplicated values, do you understand why? Look at the original tables again.
Sorry for my bad english!

Database design for a step by step wizard

I am designing a system containing logical steps with some actions associated (but the actions are not part of the question, but they are crucial for each step in the list)!
The ting is that I need to create a way to define all the logical steps in an ordered way, so that I can get the list by query, and also make modifications later on!
Anyone with some experience in this kind of database design?
I have been thinking of having a column named wizard_steps (or something similar), and then use priority to make the order, but for some reason i feel that this design at some point will fail (due to items with same priority, adding new items would then have to rearrange the rest of the items, and so forth)!
Another design I have been thinking about is the use of "next item" as a column in the wizard_step column, but I don't feel this is the correct step eighter!
So to summarize; I am trying to make a list (and the design should be open enought to support multiple lists) of elements where the order is crucial!
Any ideas on how the database should look like?
Thanks!
EDIT: I found this yii component I will check out: http://www.yiiframework.com/extension/simpleworkflow/
Might be a good solution!
If I get you well, your main concern is to create a schema that supports ordered lists and can provide easy insert/reordering of items.
The following table design:
id_list item_priority foreign_itemdef_id
1 1 245
1 2 32
1 3 45
2 1 156
2 2 248
2 3 127
coupled to a table with item definition will be easily queried but will be difficult to maintain, especially for insertions
That one:
id_list first_item_id
1 45
2 38
coupled to the linked list:
item_id next_item foreign_itemdef_id
45 381 56
381 NULL 59
38 39 89
39 42 78
42 NULL 45
Will be both difficult to query and update (you should update the linked list inside a transaction, otherwise your linked list can get corrupted).
I would prefer the first solution for simplicity.
Depending on your update frequency, you may consider using large increments between item_priority to help insertion:
id_list item_priority foreign_itemdef_id
1 1000 245
1 2000 32
1 3000 45
2 1000 156
2 2000 248
2 3000 127
1 2500 46 -- late insertion
1 2750 47 -- late insertion
EDIT:
Here's a query that will hopefully make room for an insertion: it increments priority of all rows above the argument
$query_make_room_for_new_item = "UPDATE item_priority_table SET item_priority = item_priority + 1 WHERE item_priority > ". $new_item_position_priority ." AND id_list = ".$id_list;
Then insert your item with priority $new_item_position_priority