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
api_plugin_db_table_create() method in cacti plugins
Moderators: Developers, Moderators
- rony
- Developer/Forum Admin
- Posts: 6022
- Joined: Mon Nov 17, 2003 6:35 pm
- Location: Michigan, USA
- Contact:
Re: api_plugin_db_table_create() method in cacti plugins
Well....
Mostly it doesn't support foreign keys because the default database engine in mysql does not.
Mostly it doesn't support foreign keys because the default database engine in mysql does not.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
- TheWitness
- Developer
- Posts: 17007
- Joined: Tue May 14, 2002 5:08 pm
- Location: MI, USA
- Contact:
Re: api_plugin_db_table_create() method in cacti plugins
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:
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
Code: Select all
db_execute("CREATE TABLE IF NOT EXISTS...");
TheWitness
True understanding begins only when we realize how little we truly understand...
Life is an adventure, let yours begin with Cacti!
Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages
For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Life is an adventure, let yours begin with Cacti!
Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages
For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
Who is online
Users browsing this forum: No registered users and 0 guests