using macro to connect to DB

All about the macro plugin can be found in this forum. This forum is intended for the macro plugin only.

Moderator: Moderators

m1334
Noob
Noob
Posts: 18
Joined: 16 Oct 2010, 12:02
Noob?: Yes

using macro to connect to DB

#1 Post by m1334 »

Is it possible to use macro to send data to my DB? I have a macro I created that logs guild breaks but I don't know how to send the data to my DB. I can't even create a simple command to show the result on the bot using subroutine. Can anyone give me some hints or guidance?

Code: Select all

automacro Garden {
	console /\[GM\] s+\[(.+)\] guild occupied the \[(Garden of Heaven)\] Agit./
	call {
		$Garden = $.lastMatch1
                write($Garden)
	}
}

sub write {
    print ""   //no idea how to do this
    echo ""  //no idea how to do this
}
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: using macro to connect to DB

#2 Post by EternalHarvest »

"print" always prints to STDOUT in kore, you may try message() or Log::message() instead.

Database access, as you're already using Perl subs and not just macros: http://search.cpan.org/perldoc?DBI#SYNOPSIS
m1334
Noob
Noob
Posts: 18
Joined: 16 Oct 2010, 12:02
Noob?: Yes

Re: using macro to connect to DB

#3 Post by m1334 »

Thanks message() work perfectly. I'm having a bit of a problem connecting to the DB though, probably because I don't know where should I put "use DBI;"?

Right now I'm just printing my output to a text file that looks like this

Code: Select all

~~~~~~~~~~~~~~~~~~~~~~~~
Sun Feb 12 21:00:06 2012
~~~~~~~~~~~~~~~~~~~~~~~~


##########
###Juno###
##########

Heemin = Guild
Andlerangh = Guild
Bidblind = Guild
Hueluid = Guild
Schatirnil = Guild 


############
###Rachel###
############

Mardol = Guild
Scheit = Guild
Horn = Guild
Gepun = Guild
Banadis = 
AnotherBotterOnFro
Noob
Noob
Posts: 2
Joined: 12 Feb 2012, 16:24
Noob?: Yes

Re: using macro to connect to DB

#4 Post by AnotherBotterOnFro »

I used eval to execute a script. Goes like

Code: Select all

do eval system ("./database.sh $param1 $param2");
Ofc i get the params from other macros. I use this to debug loads of them. Though I can t use Linux (see my post on the fro-forum :-/) anymore, this works in Windows as well.

Script goes like

Code: Select all

#!/bin/bash
mysql -h localhost -u $dbusername -p$dbpassword -D $dbname -e "insert into $dbtable values ('$1','$2');"
exit 0
einrel
Noob
Noob
Posts: 9
Joined: 04 Jan 2011, 10:06
Noob?: No

Re: using macro to connect to DB

#5 Post by einrel »

any update on this one? this was useful though