Closed (won't fix)
Project:
Domain
Version:
5.x-1.9
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
5 Dec 2008 at 16:46 UTC
Updated:
30 Jan 2010 at 19:47 UTC
This one is something I really don't know nothing about. Table prefixing is very new for me.
When using Domain Prefix, in a code snippet that is supposed to be somewhere inside a node, if I use db_query("UPDATE {table} ...") in a table that has domain versions, all the versions will be updated? If not, is there a function where I can have all table prefixes to vary while updating, or where I can send the table, the field and the value to be updated?
Thanks!
Comments
Comment #1
agentrickardOK. In your query, the currently active database table will be used. That is, the {table} assigned to the domain that triggered the code snippet. All tables will not be updated by default.
If you need to update multiple domains at the same time, you would need to change the active prefix string, which should be possible.
A function to do this for you would be very cool. Something like:
A few warnings, though.
-- The code above will not work if you have a global prefix (such as 'drupal_{table}) on your database. Fixi9ng that would require a preg_replace().
-- The code above is only useful for insert, update, and delete statements.
You would then do this in code:
Testing and a patch would be great.
Comment #2
Vuds commentedI'll see that soon, I'm just too occupied with my new site released (and it needs that; but for the moment I'll update the needed table "manually").
Thanks for help!
Comment #3
Vuds commentedJust a question, you are speaking of patching, which archive/module should I consider as the API to patch?
Thanks!
Comment #4
agentrickardPatch Domain Prefix. The function would go in domain_prefix.module.
Comment #5
agentrickardComment #6
agentrickardComment #7
gunzip commentedThank you for the reply here #356579: Programmatically use drupal functions with domain-prefixed tables.
it's also useful to limit the function to just build the prefix (and not to execute the query too)
so one can use something like
global $db_prefix
$db_prefix = domain_get_prefix();
drupal_execute(...)
as i guess the drupal api use the global variable.
this may go into the module as an exported api.
Comment #8
agentrickardThe code above, however, will only work for the currently active site, which already changes the $db_prefix value as needed.
Comment #9
gunzip commentedwell, i had the need to modify content of other domains from another one
so i ended up using this:
so i can temporarly use the tables of the other domain then restore the prefix.
(ie. _domain_execute(24, 'menu_link_save', array('link_path' => 'node/37', 'link_title' => 'link'));
probably there are better ways to do this.
@agentrickard thank you again for the fast replies.
Comment #10
agentrickardThat's a nice-looking function. I would rename it
domain_prefix_execute, since it is meant to be called by external modules and because it belongs in Domain Prefix module.Comment #11
agentrickard5.x is closed to new features. There are ways to do this in 6.x now.