This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Adding info into a database via tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Adding info into a database via tcl

Post by COBRa »

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: Select all

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: Select all

!addid3c Marduk-World_Funeral-Remastered-2014-BERC Black Metal 2014 44100
and here is the database table

Code: Select all

-- 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
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

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: Select all

#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
C
COBRa
Halfop
Posts: 49
Joined: Fri Jan 04, 2013 8:23 am

Post by COBRa »

took your advice and all is working superbly well many thanks to all
Post Reply