PDA

View Full Version : Large SQL statements in a quest?


Trackye
09-26-2015, 01:12 AM
Is it possible to do something like this


use DBI;
#database configuration information
$db="DATABASECORRECT";
$host="localhost";
$user="USERCORRECT";
$password="PASSWORDCORRECT";

#connect to MySQL database
my $dbh = DBI->connect ("DBI:mysql:database=$db:host=$host", $user, $password);



sub EVENT_SAY
{
my $wares = quest::saylink("wares", 1);
if($text=~/Hail/i)
{
plugin::Whisper("Would you like me to reset my $wares ?") ;
}
if($text=~/wares/i)
{
plugin::Whisper("Restocking now!") ;
my $Sql1 = $dbh->prepare("Delete from Merchantlist_temp where npcid =999260;");
$Sql1->execute( );
plugin::Whisper("Restock complete!") ;
}
}


But I need it to run approximately 60 Sql statements?
Eventually on a timer like every 2 hours? I only set it up as a manual Hail so i could test it.

Everything works up until clicking Wares. The NPC says restocking now and then nothing

Questerrors command shows the Npc then a number of Boxes or something after that...

Any help with this would be greatly appreciated.

demonstar55
09-26-2015, 01:25 AM
PEQ had some quests at some point in time that did SQL stuff, it was HORRIBLE for performance and would lock the zone for a bit.

N0ctrnl
09-28-2015, 11:38 AM
The MySQL plugin allows for direct DB access, if that's the way you wanna go.

Akkadius
09-28-2015, 11:42 AM
PEQ had some quests at some point in time that did SQL stuff, it was HORRIBLE for performance and would lock the zone for a bit.

DBI can be just fine if its used right.

Trackye
09-28-2015, 01:22 PM
Could you possibly give me some more information as to how I would do that correctly please? lol

I do not seem to be able to get the above code to work although it gives no errors in a Pearl check for Syntax.

N0ctrnl
09-28-2015, 03:10 PM
I looked at Akkadius' leaderboard plugin. It makes plenty of database calls to use as a reference.

http://www.eqemulator.org/forums/showthread.php?t=37650

Kingly_Krab
09-28-2015, 03:36 PM
Do you have Perl DBI and Perl DBD-MySQL installed?

http://www.eqemulator.org/forums/showthread.php?t=37955

Trackye
09-28-2015, 04:26 PM
Thank you I will read up and look into both of those.


-------EDIT----------

So having looked into both of those.

Im still stuck.

The download links for DBD-MYSQL are not working I found a copy of DBD-mysql.4.0.32 but cannot seem to get it to install correctly.

If i try to install DBI using PPM install DBI it says no packages missing So it seems I have that installed.
But the code still returns #questerrors with a number of squares as the subject.

I do also have the mysql plugin and the DB is configured correctly there.

What im currently working with...

sub EVENT_SAY
{
my $wares = quest::saylink("wares", 1);
if($text=~/Hail/i)
{
plugin::Whisper("Would you like me to reset my $wares ?") ;
}
if($text=~/wares/i)
{
plugin::Whisper("Restocking now!") ;
$connect = plugin::LoadMysql();
$query = "Delete from Merchantlist_temp where npcid =999260;";
$query_handle->execute;
plugin::Whisper("Restock complete!") ;
}
quest::debug("$DBI::errstr") if $DBI::errstr;
}


For this type of code would DBD-mysql be required or is DBI enough?
Or am I doing something foolish incorrectly?