Created a node type with the Amazon Item field, I try adding some nodes. But if submit a new node I get an error:

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydatabase.amazon_book' doesn't exist: SELECT * FROM amazon_book WHERE asin = :asin; Array ( [asin] => 7802000947 )  in amazon_media_amazon_item_load() (line 111 of .../drupal/sites/mysite.com/modules/amazon/amazon_media/amazon_media.module).

I checked my database and can find the table amazon_book exists but the name is spn_amazon_book, because a table prifix spn_ had been added when Drupal installed.

Is this error from the table prefix or something else?

CommentFileSizeAuthor
#5 amazon.amazon_media_static_query.patch1.22 KBrfay

Comments

rfay’s picture

So it sounds like you're using a database prefix, which this hasn't been tested with. However, the code I see I think should work. In amazon_media_amazon_item_load():

    $additions = db_query("SELECT * FROM {$table} WHERE asin = :asin",
    array('asin' => $item['asin']))->fetchAssoc();

However, this doesn't look like the best code in the world to me. Probably this should be turned from a static query into a dynamic query, since that's what it is. I'm not sure it's going to fix your problem, though.

Here's what I recommend as debugging steps:

1. Completely uninstall amazon_media module. (Don't just disable it, but rather disable and then uninstall).
2. Check to see that all related tables (amazon_book, amazon_dvd, amazon_music) are *gone*. (In your case these will be prefixed, I imagine).
3. Reinstall amazon_media module and look to see what tables are there.

Thanks for the report!

astra’s picture

Thanks for replying! I have a test by your debugging steps but couldn't fix it.

After uninstalled amazon_media module, all related 4 tables are deleted from the database. And I can now post my nodes (ABIS Books) without displaying any error message. But you know it missed some data for book items without amazon_media.

Then reinstalled amazon_media module, all tables (spn_amazon_book, spn_amazon_dvd, spn_amazon_music, spn_amazon_software) were added again into the database. But now the same error message comes back again if post a new node, and no content of the node displays.

rfay’s picture

Thanks for taking a look at that. I'll take a look at this when I next spend a day with the module.

If anybody wants to work on this, I think the obvious thing is to turn that from a DBTNG static query to a dynamic one. Patches are welcome and appreciated.

-Randy

rfay’s picture

Title: Amazon Module: problem for database table amazon_book » amazon_book (D7) fails with database prefixing turned on
rfay’s picture

Status: Active » Needs review
StatusFileSize
new1.22 KB

Found the problem. Patch attached.

rfay’s picture

Status: Needs review » Fixed

Committed to HEAD: http://drupal.org/cvs?commit=417098

Thanks so much for the problem report.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.