Closed (fixed)
Project:
Drupal core
Version:
6.x-dev
Component:
database system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 Nov 2007 at 21:54 UTC
Updated:
13 Dec 2007 at 06:57 UTC
Jump to comment: Most recent file
Comments
Comment #1
bjaspan commentedI think you meant $ret = update_sql($query) not $ret = db_query($query). db_query never returned the 'success' or 'failed' thing.
All Schema API functions generate the update_sql() output array and, in fact, drupal_install_schema() and drupal_uninstall_schema() actually collect them (they have to since the API functions require the argument). They do not yet return anything, so it is easy enough to return them.
Patch attached.
Comment #2
bjaspan commentedComment #3
hunmonk commentedcouple of corrections:
FYI, here's how i'm using this:
this allows me to give the user a bit of intelligent output about the module installation.
actually, in the old days, i would just do $q1 = db_query('blah'), as i indicated above, which would at least give me a TRUE/FALSE on the query. AFAICT, we always used db_query(), not update_sql(), for initial install queries, even in core.
Comment #4
bjaspan commentedYou say "We really should be testing for the existence of a table before we drop it on uninstall" but I'm not convinced. We don't check if a table exists before creating it, and we don't check if the schema matches our expectations before we alter it. Our entire schema maintenance system is built on assuming things are the way we left them. I don't see much harm in checking if a table exists, and I'm not concerned about the extra query. On the other hand, avoiding a "DROP TABLE failed because table does not exist" error is also not that important and, I'd even say, getting such an error when it should not occur provides useful information to the administrator. So, I'd vote for not checking before db_drop_table().
Note that "assuming things are the way we left them" is absolutely on the table for discussion for D7. Schema.module already knows how to inspect the database and compare it to hook_schema results. This can lead us towards automatic schema updates instead of hand-written hook_update_n() functions, at least for many common cases. However, I'd still say that we can/should assume that any table in hook_schema() exists and if it doesn't report an error.
Incidentally, making hook_install() unnecessary for modules that do nothing but drupal_install_schema() is also on the table for D7. The central hook_install replacement should probably report on failed table creation as you are doing in asterisk.module; there is no reason for that code to be duplicated among many modules.
Comment #5
hunmonk commentedgood points all the way around. given the larger current system we've got, it's probabaly smart to wait on the db_table_exists() change.
attached removes that, and simply corrects the code comments from your original patch.
Comment #6
hunmonk commentedback to original title :)
Comment #7
hunmonk commentedi've tested this patch -- it works, and it's a simple fix that provides install/uninstall hooks with useful information.
Comment #8
gábor hojtsyGreat, thanks, committed.
Comment #9
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #10
panchoJust a notice: a similar patch by Rob Loach has been declined in October 2007 (see #187121)