Uutiset:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu
Advertisement:

Database Tag Does Not Work

Aloittaja Avalanche91, marraskuu 17, 2013, 10:19:22 AP

« edellinen - seuraava »

Avalanche91

Hello fellows,

I am trying to create a mod which requires database connection. Reading the documentation, 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:
Koodi (php) [Valitse]
<?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!';
}

emanuele

Hello Avalanche91,

you are not supposed to use "normal" queries to create/delete tables, but the functions provided by SMF to do that. ;)

ETA: in particular if you want to create a table you should use:
http://wiki.simplemachines.org/smf/Db_create_table


Take a peek at what I'm doing! ;D




Hai bisogno di supporto in Italiano?

Aiutateci ad aiutarvi: spiegate bene il vostro problema: no, "non funziona" non è una spiegazione!!
1) Cosa fai,
2) cosa ti aspetti,
3) cosa ottieni.

Arantor

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.
Holder of controversial views, all of which my own.


Avalanche91

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:
Koodi (php) [Valitse]
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 :)

Arantor

And you STILL should NOT BE DOING IT.
Holder of controversial views, all of which my own.


Avalanche91

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:)

Advertisement: