Data module rely on schema for various tasks. One of them is the adopt functionality.
Briefly adopt invoke the "inspect" pseudo hook of the schema module to get information on the table to be adopted.
$schema = schema_invoke('inspect', $this->name);
Now, this hook is expecting to handle tables with db_prefix already applied; at least this seems looking how this is called from schema module itself:
function schema_compare_table($ref, $inspect = NULL) {
global $db_type;
$_db_type = $db_type;
if ($_db_type == 'mysqli') {
$_db_type = 'mysql';
}
if (! isset($inspect)) {
$ref_name = db_prefix_tables('{'. $ref['name'] .'}');
$inspect = schema_invoke('inspect', $ref_name);
$inspect = $inspect[$ref['name']];
}
Moreover on function schema_mysql_inspect the name is unprefixed on the return array:
$r['NEW_TABLE_NAME'] = schema_unprefix_table($r['TABLE_NAME']);
Now, with the current code (DataTable.inc,v 1.1.2.11 2010/07/28 20:21:19 alexb - 6.x-1.0-alpha12) the adopt method invoke the inspect without checking the prefix.
$schema = schema_invoke('inspect', $this->name);
A simple fix would be to change above line to:
$ref_name = db_prefix_tables('{'. $this->name .'}');
$schema = schema_invoke('inspect', $ref_name);
Patch will follow...
Comments
Comment #1
EmanueleQuinto commentedAnd here is the patch.
Comment #2
EmanueleQuinto commentedRevised patch.
Comment #3
datawench commentedCould you elaborate on what this is supposed to fix/enable? From the description, I was hoping that it solved the problem of requiring a $db_prefix statement in the settings file for every table you want to adopt, but that doesn't seem to be the case. Even with this patch applied, I still need the $db_prefix statements to view any data in the adopted tables (having adopted the tables from another local, but non-drupal database).
Comment #4
EmanueleQuinto commentedWell this patch addresses the adoption of tables in drupal DB when you are using $db_prefix.
A simple case could be using the feed module to import data in a table. If you are using prefix for your DB without this patch you'll not be able to adopt the data: no views for free.
Comment #5
3dloco commentedThanks EmanueleQuinto...your patch @ #2 worked for me!
Comment #6
ransomweaver commented#2 fixes failed adopt for prefixed tables in alpha14. Thanks!
Comment #7
kdhartstrom commentedIs there a d7 version of this patch?
Comment #8
batandwa commenteds
Comment #9
joachim commentedUpping version. Presumably, the patch needs work.
Comment #10
OkieRazorback commentedI'm by no means an expert on this, so if I'm completely off here let me know. It looks like if we changed the following two lines in the adopt function the problem would be corrected.
Change this:
to this:
Comment #11
joachim commentedLooks like that's on the right track.
Could you make that into a patch so people can test it?
Comment #12
OkieRazorback commentedTo be honest I have no idea how to do that. Would be willing to learn if someone pointed me in the right direction. :)
Comment #13
OkieRazorback commentedOkay, I think I got the patch done correctly. Let me know if it's not correct.
Comment #14
OkieRazorback commentedThe patch is for Drupal 7.
Comment #15
joachim commentedThanks! Setting to 'needs review'.
Can someone give this a try?
Comment #16
antoinetooley commentedthe drupal 7 patch doesnt work for me, but I have only implemented this patch and not any of the others in this thread.
Go to adopt the webform table and then nothing appears. Getting really confused and still new to drupal so I don't have agreat understanding of what is exactly is going on or what a database prefix is really.
Any help is greatly appreciated id love to one day be good enough to help others!
Cheers
Comment #17
joachim commentedWell it sounds like the patch at #13 is intended to be the sole one needed. If it's not working, then this issue needs work!
Comment #18
DriesP commentedPatch doesn't work for me. Could this issue please be fixed by anyone? It's been around for some time now...
Comment #19
Antoine_k commentedThe patch doesn't work for me either
Comment #20
jonlibrary commentedI came here from https://drupal.org/node/1040054. I was trying to get webform submission data into views using the Webform MySQL Views module.
But it turned out that prefixes weren't the problem for me.
For me the problem turned out to be that one of the field keys for my webform was too long. Although Webform MySQL Views told me it was creating the view, it actually wasn't anywhere to be found in my database. A data module error displayed on the screen, but the Webform MySQL VIews error was logged in the "Recent log entries" (drupal 6). I must have read somewhere else about column name length being a problem.
So if the patch isn't working, maybe it's something else for you, too.