Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: The Wizard - helmikuu 24, 2014, 08:05:40 AP

Otsikko: database code uninstall advice
Kirjoitti: The Wizard - helmikuu 24, 2014, 08:05:40 AP
Hello:

The following code below I add to the database during install on my mod and I was wondering whats the best way to remove it when I uninstall?


$smcFunc['db_insert']('insert', '{db_prefix}shop_categories',
array('name' => 'string', 'id' => 'int', 'count' => 'int'),
array('name' => 'Companions', 'id' => '502', 'count' => '12'),
array('name' => 'id', 'type' => 'primary', 'columns' => array('id') ));


I was thinking of writing a uninstall page and using the DELETE function like this -


$smcFunc['db_insert']('delete', '{db_prefix}shop_categories',
array('name' => 'string', 'id' => 'int', 'count' => 'int'),
array('name' => 'Companions', 'id' => '502', 'count' => '12'),
array('name' => 'id', 'type' => 'primary', 'columns' => array('id') ));


Thanks

Wiz
Otsikko: Re: database code uninstall advice
Kirjoitti: margarett - helmikuu 24, 2014, 08:53:35 AP
At uninstall the table should be dropped, so there's no need to remove content inside it ;)

And the table drop is automatically managed by SMF.
Otsikko: Re: database code uninstall advice
Kirjoitti: emanuele - helmikuu 24, 2014, 02:47:58 IP
And if you want to delete something you have to use a "DELETE" query, that is not implemented as a function within $smcFunc, so you'd have to write something like:
$smcFunc['db_query']('', '
DELETE FROM {db_prefix}shop_categories
WHERE id = {int:value}',
array(
'value' => 502
)
);

Though... I think also your insert query is wrong, I wonder how it can work.