Cacti (home)ForumsDocumentation
Cacti: offical forums and support
It is currently Mon May 29, 2017 5:49 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: api_plugin_db_table_create() method in cacti plugins
PostPosted: Wed Dec 21, 2011 4:27 am 
Offline

Joined: Fri Dec 09, 2011 1:21 am
Posts: 8
Hi All,

I am trying to create a table in cacti database from my plugin.

The query is below

CREATE TABLE `kpi_param` (
`kpi_id` int(3) NOT NULL,
`param_id` int(3) NOT NULL,
PRIMARY KEY (`kpi_id`,`param_id`),
KEY `fk_kpi_param_param1` (`param_id`),
KEY `fk_kpi_param_kpi1` (`kpi_id`),
CONSTRAINT `fk_kpi_param_kpi1` FOREIGN KEY (`kpi_id`) REFERENCES `kpi` (`kpi_id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT `fk_kpi_param_param1` FOREIGN KEY (`param_id`) REFERENCES `param` (`param_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


As per the api_plugin_db_table_create() there are no references of foreign keys.
How do we get the above query in a api_plugin_db_table_create() format?
especially foreign key , References information.

My implementation:
function kpi_param_table(){

global $config,$database_default;
include_once($config["library_path"]."/database.php");
$data=array();
$data['columns'][]=array('name' => 'kpi_id',
'type' => 'bigint(25)',
'unsigned' => 'unsigned',
'NULL' => false,
'auto_increment' => true
);
$data['columns'][]=array('name' => 'param_id',
'type' => 'int(3)',
'unsigned' => 'unsigned',
'NULL' => false
);
$data['primary']='kpi_id';
$data['type']='MyISAM';
$data['comment']='kpi param Data Table';
api_plugin_db_table_create ('param kpi','kpi_param',$data);

}

Aprreciate your help.

Thanks.

Regards,
Das


Top
 Profile  
 
 Post subject: Re: api_plugin_db_table_create() method in cacti plugins
PostPosted: Wed Dec 21, 2011 4:22 pm 
Offline
Developer/Forum Admin
User avatar

Joined: Mon Nov 17, 2003 6:35 pm
Posts: 5945
Location: Michigan, USA
Well....

Mostly it doesn't support foreign keys because the default database engine in mysql does not.

_________________
Tony Roman
Experience is what causes a person to make new mistakes instead of old ones.
There are only 3 way to complete a project: Good, Fast or Cheap, pick two.
With age comes wisdom, what you choose to do with it determines whether or not you are wise.


Top
 Profile  
 
 Post subject: Re: api_plugin_db_table_create() method in cacti plugins
PostPosted: Wed Dec 21, 2011 5:48 pm 
Offline
Developer
User avatar

Joined: Tue May 14, 2002 5:08 pm
Posts: 14863
Location: MI, USA
I suggest that you don't use the API function for setting up Fk's. You should instead use the 'create' syntax and wrap it into a function called "db_execute". So, it would go something like this:

Code:
db_execute("CREATE TABLE IF NOT EXISTS...");


Then, please log an enhancement request at http://bugs.cacti.net under the plugins section to allow the specification of Fk's in the API.

TheWitness

_________________
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of MacTrack, Boost, CLog, SpikeKill, Platform RTM, DSStats, maintainer of Spine, lot's of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
Gandalfs Official Debugging Help
Central Plugin Repository
Central Templates Repository


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Protected by Anti-Spam ACP Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group