How to add new fields to the existing table in piwit db


i want to add some new fields in the log_visit table to store some value. wen i use the install method i don get any errors or any updation in the table. plz let me know wat am i doing wrong! is it enough if i overwride this method in my class that extends Piwik_plugin or shd i call this metho some wer explicitly?

public function install()
$query = "ALTER TABLE ".Piwik::prefixTable('log_visit')." " .
"ADD newfield VARCHAR( 100 ) NULL " ;

	try {
	catch(Exception $e){

First: your catch block is empty – which explains why you’re not seeing any errors; if query() throws an exception, your catch block has to handle it

Second: you should use Piwik_Exec() for DDL statements like CREATE, ALTER, DROP, …

it works fine except with an exception…

i get a duplicate field error…

exception: exception ‘Zend_Db_Statement_Exception’ with message ‘SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name ‘newfield’’ in C:\xampp\htdocs\piwik\libs\Zend\Db\Statement\Pdo.php:234 Stack trace: #0 C:\xampp\htdocs\piwik\libs\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array) #1 C:\xampp\htdocs\piwik\libs\Zend\Db\Adapter\Abstract.php(468): Zend_Db_Statement->execute(Array) #2 C:\xampp\htdocs\piwik\libs\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query(‘ALTER TABLE p...', Array) #3 C:\xampp\htdocs\piwik\core\PluginsFunctions\Sql.php(37): Zend_Db_Adapter_Pdo_Abstract->query('ALTER TABLEp…’, Array) #4 C:\xampp\htdocs\piwik\plugins\dbnow\dbnow.php(47): Piwik_Query(‘ALTER TABLE `p…’) #5 C:\xampp\htdocs\piwik\core\PluginsManager.php(347): Piwik_dbnow->install() #6 C:\xampp\htdocs\piwik\core\PluginsManager.php(453): Piwik_PluginsManager->installPlugin(Object(Piwik_dbnow)) #7 C:\xampp\htdocs\piwik\core\PluginsManager.php(148): Piwik_PluginsManager->installPluginIfNecessary(Object(Piwik_dbnow)) #8 C:\xampp\htdocs\piwik\plugins\CorePluginsAdmin\Controller.php(54): Piwik_PluginsManager->activatePlugin(‘dbnow’) #9 [internal function]: Piwik_CorePluginsAdmin_Controller->activate() #10 C:\xampp\htdocs\piwik\core\FrontController.php(129): call_user_func_array(Array, Array) #11 C:\xampp\htdocs\piwik\index.php(104): Piwik_FrontController->dispatch() #12 {main}

That means your SQL statement worked, i.e., you already added the new column (newfield) to the table. Under normal circumstances, this shouldn’t happen, but you can a check in the catch block to ignore the duplicate column error.

thank u!!! it solves my problem… style_emoticons/<#EMO_DIR#>/smile.gif

i hav another doubt… wen wud d uninstall method wud b triggered

  • wen we deactivate the plugin in settings page (or)

  • wen we remove the plugin from the plugin folder

We have a ticket open to add an “uninstall” action for plugins; at which point, the uninstall method would be called.