| View previous topic :: View next topic |
| Author |
Message |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Thu Jul 31, 2014 1:04 pm Post subject: Adding info into a database via tcl |
|
|
i want to want to store the info into a database ive come up with this code so far it kinda works unless the genre is double worded then it seems to add the first word of the genre at the end of the rlsname
| Code: | proc addmy:id3c { bot com arg } {
global chann_ db_handle
set pattern { ([^>]+) ([^>]+) ([0-9]+) ([0-9]+) }
if { [regexp $pattern $arg match rlsname genre year sampling] }
{
set result [mysqlsel $db_handle "SELECT `rlsname` FROM `id3c` WHERE `rlsname` = '$rlsname'"]
}
if { $result == "0" } {
mysqlexec $db_handle "INSERT INTO `id3c` ( `rlsname` , `genre` , `year` , `sampling` ) VALUES ( '$rlsname' , '$genre' , '$year' , '$sampling' )"
putquick "PRIVMSG $chann_(addid3c) :!addid3c $rlsname $genre $year $sampling"
}
} |
the output from the previous script is this
| Code: | | !addid3c Marduk-World_Funeral-Remastered-2014-BERC Black Metal 2014 44100 |
and here is the database table
| Code: | -- Table structure for table `id3c`
--
CREATE TABLE IF NOT EXISTS `id3c` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`rlsname` varchar(240) CHARACTER SET utf8 NOT NULL,
`genre` text CHARACTER SET utf8,
`year` year(4) NOT NULL,
`sampling` int(10) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `rlsname` (`rlsname`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=602 ;
|
so basically it adds Marduk-World_Funeral-Remastered-2014-BERC Black into the rlsname field instead of Marduk-World_Funeral-Remastered-2014-BERC without the word Black which is part of the genre field |
|
| Back to top |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Jul 31, 2014 2:07 pm Post subject: |
|
|
This seems obviously related to your other thread.
What you need to understand, is that the regular expression (pattern) I tailored in that thread, was specific to the format of the data - as posted in that thread. Here you have a different format, and thus need a different pattern.
From what I can tell though, it would seem you have two eggdrops, one which receives the messages from a third party, which you then relay to the second eggdrop which is then responsible for storing the data in the database. In this case, I'd suggest you use the already built-in encapsulation methods in tcl in this bot-to-bot transfer. And that would be tcl-lists.
Your first eggdrop has managed to split the data into four different variables (rlsname genre year sampling), so just create a list containing these four elements, and be done with it...
| Code: | #bot 1
...
putbot bot2 "addid3c [list $rlsname $genre $year $sampling]"
...
#bot 2
bind bot - addid3c
proc addmy:idc {bot command items} {
lassign $items rlsname genre year sampling
... |
lassign is only available from tcl8.5 and forwards, for older versions you could use lindex to access each item by it's list offset instead. _________________ NML_375, idling at #eggdrop@IrcNET |
|
| Back to top |
|
 |
COBRa Halfop
Joined: 04 Jan 2013 Posts: 49
|
Posted: Mon Aug 18, 2014 5:16 am Post subject: |
|
|
| took your advice and all is working superbly well many thanks to all |
|
| Back to top |
|
 |
|
|
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 vote in polls in this forum
|
|