Hello fellows,
I am trying to create a mod which requires database connection. Reading the documentation (http://www.simplemachines.org/community/index.php?topic=299669.0), for this purpose in SMF 2 and higher, I am supposed to use <database>. Still no problem, my install script is working; I am successfully creating a table in the database, but if I am to uninstall my mod, the table remains in the database. On the other hand, if I use <code> instead of <database> - everything works perfectly.
Is this a bug or am I doing anything incorrectly? Here is my uninstall.php file:
<?php
if(file_exists(dirname(__FILE__) . '/SSI.php') && !defined('SMF'))
require_once(dirname(__FILE__) . '/SSI.php');
else if(!defined('SMF'))
die('<b>Error:</b> Cannot install - please verify you put this in the same place as SMF\'s index.php and SSI.php files.');
$smcFunc['db_query']('', 'DROP TABLE IF EXISTS {db_prefix}myPrettyTableName');
if(SMF == 'SSI') {
echo 'Database changes are complete!';
}
Hello Avalanche91,
you are not supposed to use "normal" queries to create/delete tables, but the functions provided by SMF to do that (http://wiki.simplemachines.org/smf/$smcFunc#Database_Package_Functions). ;)
ETA: in particular if you want to create a table you should use:
http://wiki.simplemachines.org/smf/Db_create_table
On top of that, if you create a table with db_create_table fired from a script in <database>, SMF will 1) log this fact and 2) offer the user the choice of whether to remove it on uninstall.
In fact a database tag on uninstall will not be run UNLESS the tick box for "remove this mod's data" is ticked.
This is important because you might not actually want to remove a mod's data on uninstall, e.g. If you are about to install a new version... You can use <code> to fire changes that *must* be made (removing scheduled tasks, removing hooks) and database if you need it for other cleanup, but if set up properly SMF will take care of a lot of it for you.
Thanks for replying guys,
I see what you are trying to achieve there. I now tried to use $smcFunc['db_drop_table'], but I received an error - function name must be a string which I previously fought with when I had forgotten to set $smcFunc as global. In order to solve this issue I had to "extend" the database functionality by adding the following line of code before the query:db_extend('packages');
Now everything works as expected. Thank you very much!
I still have some other questions to ask regarding the proccess of creating modifications, but that would be tomorrow :)
And you STILL should NOT BE DOING IT.
Lainaus käyttäjältä: Arantor - marraskuu 17, 2013, 12:03:05 IP
And you STILL should NOT BE DOING IT.
Oh snap! You didn't make yourself clear enough. It was never written that I do NOT really need to specifically tell SMF to drop the table. Oh well, at least I know how to do it now. O:)