If this is your first visit, check our documentation. To post, register or login.

Store Database Queries

Started by hubert on 3 Jun 2013, 1:38 AM · Views: 1,752

Results 1 to 11 of 11
3 Jun 2013, 1:38 AM
#1
hubert avatar

hubert

Zen Follower

Join Date:
Mar 2005
Posts:
229
Plugin Contributions:
0

Store Database Queries

Hello,

I'm in the process of upgrading and modifying my site and just discovered this setting.
As I want to reduce to the max the downtime of the site I was planning to make a bunch of modifications by using SQL queries directly on the database.

I found the syntaxe of some of the queries I need (by myself) but I would like to see what's happening behind the curtain, to be sure to not make any mistake and to take some queries as examples.

Unfortunately, by setting Store Database Queries to true I only get SELECTs.

That would be wonderful if I could get UPDATEs and INSERTs.

Is there a setting that I'm missing ?
Any modification to do on query_factory.php to get this ?

Thanks for your help.

Regards

Hubert

3 Jun 2013, 5:08 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: Store Database Queries

As I want to reduce to the max the downtime of the site I was planning to make a bunch of modifications by using SQL queries directly on the database
If you are following the recommended method for upgrading - there should be no need for what you are describing - which is dangerous at best

PLEASE Back up your database before doing any of this

Zen-Venom Get Bitten

3 Jun 2013, 1:32 PM
#3
hubert avatar

hubert

Zen Follower

Join Date:
Mar 2005
Posts:
229
Plugin Contributions:
0

Re: Store Database Queries

You're right Kobra, it is dangerous and I know that.
That's why I want to see Insert and Upgrade queries made by ZC so that I'm sure the ones I build are not wrong.

More, my modifications are, for example, mass moving products from one category to another, or mass changing price to zero (because the product is becoming priced by attributes).

Making that from admin takes a long time, making it using a query is very fast.

I'm planning to queue all these modificcations using queries.
That's why I need to see, not only SELECTs but also UPDATEs and INSERTs.

Hubert

3 Jun 2013, 3:51 PM
#4
dbltoe avatar

dbltoe

Totally Zenned

Join Date:
Jan 2004
Location:
N of San Antonio TX
Posts:
9,904
Plugin Contributions:
23

Re: Store Database Queries

Why are you insisting on such a radical process? What is it you expect to gain from avoiding the tried and true method of upgrade?

Have you looked at http://www.zen-cart.com/entry.php?3-How-do-I-rebuild-my-site-on-the-new-version-instead-of-upgrading?

Need a hand with Zen Cart? Hire the team at myZenCartZone.com for upgrades, repairs, and custom plugins.
Zen Cart Certified hosting at myZenCartHost.com

3 Jun 2013, 3:59 PM
#5
hubert avatar

hubert

Zen Follower

Join Date:
Mar 2005
Posts:
229
Plugin Contributions:
0

Re: Store Database Queries

I've already done that guys, but while upgrading I'm also updating, changing look and feel, adding some new modules, two of theme are custom modules. This simplify the structure of my categories and products.

My only question was how to get sql INSERT and UPDATE queries in the logs.

3 Jun 2013, 4:24 PM
#6
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Store Database Queries

you will have to rewrite the query-factory code

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

3 Jun 2013, 7:47 PM
#7
hubert avatar

hubert

Zen Follower

Join Date:
Mar 2005
Posts:
229
Plugin Contributions:
0

Re: Store Database Queries

So sad, seems too complicated for me.
I took a look into query_factory but I don't see where it is said to only log SELECTs.

I also was wondering if all and every queries are going thru query_factory.
Perhaps it's the case for everything done from admin ?
If not, this is not my solution.

That's really sad, it would have been a good debugging tool.

3 Jun 2013, 8:32 PM
#8
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Store Database Queries

I don't mean to sound uncooperative. However it's important to note that there's a lot more business logic going on in the PHP code beyond just mere SQL queries, including safeties and keeping relational records intact and ensuring related dependencies exist. This logic will not be evident in mere SQL queries alone. The logic is all there in the PHP files for you to review.

And, yes, query_factory is used for all queries executed by original Zen Cart files.
That said, addons/contributions may have taken shortcuts and thus there are no guarantees that they've embraced the ZC framework methods for doing db queries, and therefore can't be certain that they're using query_factory as it was intended.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

3 Jun 2013, 9:37 PM
#9
hubert avatar

hubert

Zen Follower

Join Date:
Mar 2005
Posts:
229
Plugin Contributions:
0

Re: Store Database Queries

Thanks for your reply DrByte.

Are you meaning that there's No safe SQL queries if they are made directly on the database ?
Even if it's only a simple price update, or a category id change ?

3 Jun 2013, 11:33 PM
#10
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Re: Store Database Queries

hubert:

Thanks for your reply DrByte.

Are you meaning that there's No safe SQL queries if they are made directly on the database ?
Even if it's only a simple price update, or a category id change ?

I didn't say that. I was responding to your post where your question implied that reverse-reviewing logged queries would be suitable for relying upon for general updates.
My post was intended to convey the fact that taking information out of context can result in problems. That includes looking at queries independent of business logic.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

4 Jun 2013, 12:35 AM
#11
hubert avatar

hubert

Zen Follower

Join Date:
Mar 2005
Posts:
229
Plugin Contributions:
0

Re: Store Database Queries

I understand.
If you take the example of disabling a category, ZC warns you about the fact he will also disable all products in this category. So it's queuing too kind of queries.

1-UPDATE db.categories SET categories_status = '0' WHERE categories.categories_id =X;
and
2-UPDATE db.products SET products_status = '0' WHERE products.master_categories_id =X;

In this case ZC tells you it's doing so but I'm quite sure many times it's doing the same kind of queuing without telling you anything.

I would like to see what's happening behind the scene to be sure to not forget anything.