You are here:  » Run SQL After Imports

Support Forum



Run SQL After Imports

Submitted by gregor on Sat, 2011-09-10 14:32 in

I have to clean up some products using SQL after my loads, so I would like to run a series of SQL commands after each import. So when I import a file, I want to run the SQLs against the products just imported. Would you help me understand where to do this?

Also, if I delete rows from the products table after it's been loaded, will it cause problems elsewhere? Seems to be working fine, but who knows?

Thank you!
Gregor

Submitted by support on Sat, 2011-09-10 17:27

Hi gregor,

Here's what to do; first create a .sql (text) file, for example post.sql (I would suggest saving this in the /scripts/ folder of your Price Tapestry installation) and in the file enter your required post import SQL statements, for example:

UPDATE pt_products SET brand = UPPER(brand);
DELETE FROM pt_products WHERE name LIKE 'Not Wanted Products%';

And with that in place, all you need to do is add the following to end of your CRON command (separated with a semi-colon from your existing command - that will make sure that it executes afterwards)

/usr/bin/mysql -u usernamne -p password -D databasename -p < /path/to/scripts/post.sql

Replace username, password and database name to match the equivalent values in your config.php, and /path/to/ is the installation path as displayed on the Support Info page of your Price Tapestry /admin/ area...

There's no problem deleting products in this way, it won't affect database consistency at all.

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by gregor on Sun, 2011-09-11 13:43

Thank you David. I'm not using CRON (that I know of) and I'm not sure where you suggested to put this. You gave me some ideas, so I looked at how you build the SQL in setup.php and decided to have a go at something like that. I added a new include to the bottom of feeds_import.php and in that file I build a string of SQL commands and then explode them and process each one. This is working well and I'm using the filename to limit the scope of the commands to the newly imported rows.

Thank you!
Gregor