Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Simple question for any SQL ninjas
Old 02-28-2011, 06:14 AM Simple question for any SQL ninjas
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
I use Drupal to build development versions on my server
and show them to clients. When the client ponies up the money
I move the site out to it's own live server.

I have found that there are occasionally issues with images
where the path to the file doesnt get translated properly.

For example, if the path on my dev site is
www.mydev.com/client1/sites/all/themes/nicetheme/images/imagename.png

I want the path to be

www.clientlive.com/sites/all/themes/nicetheme/images/imagename.png

Trouble is that it sometimes picks up the first level directory so the url
trying to find the image borks out like this:

www.clientlive.com/client1/sites/all/themes/nicetheme/images/imagename.png



I figure that there must be an SQL query that I could run through myPHPadmin that would strip out the unwanted subdirectory from any links which contain it.

But being a bit of an SQL noob I defer to the powers that be here.
Any advice?
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE
TWD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-28-2011, 11:31 AM Re: Simple question for any SQL ninjas
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Is this any use?
http://drupal.org/node/199484
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 02-28-2011, 07:22 PM Re: Simple question for any SQL ninjas
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
Possibly. But if I am reading the thread correctly, the final advice is to use a preprocessor function in the themes layer.
It would probably work but I'd like to fix the problem upstream.
There is also the potential problem that if somebody switches presentation themes later on, everything breaks.

Maybe I am smoking crack here but would an SQL query like this, run through the phpMyAdmin tab work?

Code:
UPDATE * SET * = replace(*, 'clientlive.com/client1/', 'clientlive.com/
') WHERE * = 'clientlive.com/client1/';
';
Where * is a global wildcard.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE

Last edited by TWD; 02-28-2011 at 07:23 PM..
TWD is offline
Reply With Quote
View Public Profile
 
Old 03-01-2011, 07:29 AM Re: Simple question for any SQL ninjas
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A query like that would definitely not work.

UPDATE queries require a table name not a wildcard, so to update multiple rows in multiple tables based on a criteria would need to be done with a stored procedure, and to be honest, writing and testing a recursive procedure that was testing against every column, in every row, in every table in a database would not be my first choice of a fun thing to do.

Even if I was spending a wet weekend in Rhyl
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-01-2011, 10:30 AM Re: Simple question for any SQL ninjas
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
I've been to Wales. Thought it was quite nice actually.

Guess I need to brush up on my SQL.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE
TWD is offline
Reply With Quote
View Public Profile
 
Old 03-01-2011, 07:55 PM Re: Simple question for any SQL ninjas
TWD
TWD's Avatar
King Spam Talker

Posts: 1,190
Trades: 0
OK maybe this will make a bit more sense.
So far as I can tell there is only one table in Drupal that
contains data on links to uploaded images and files.
That is the "drp_node_revisions" table.

And the only fields that need updating are the "body" field and the "teaser" field.

So the following query will successfully select all the required
records:

Code:
SELECT * FROM drp_node_revisions WHERE body LIKE '%/sites/default/files/%' 
OR teaser LIKE '%/sites/default/files/%';
From that point, it is possible to go through each record and manually change the file reference.

However that's only a slight improvement on manually updating everything
from the Admin interface. I want to take it to the next level and run an SQL query that does that.

Would this work?:

Code:
UPDATE drp_node_revisions SET body, teaser
 = replace(*, '/client1/sites/default/files/', '/sites/default/files/')
 WHERE body LIKE '%/sites/default/files/%' 
OR teaser LIKE '%/sites/default/files/%';
I'm not sure if a % sign in the replace parameters is necessary or not, because it is affecting a part of a longer string,
but the MySQL docs suggest not.
__________________
RATE-MY-WEBSITE.com "Free website reviews by real web professionals"
Please login or register to view this content. Registration is FREE

Last edited by TWD; 03-01-2011 at 08:17 PM..
TWD is offline
Reply With Quote
View Public Profile
 
Old 03-18-2011, 02:22 PM Re: Simple question for any SQL ninjas
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
http://dev.mysql.com/doc/refman/5.0/...functions.html
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to Simple question for any SQL ninjas
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24276 seconds with 12 queries