[MySQL] How to send some info from MySQL to POL

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
Harley
Forum Regular
Posts: 350
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

[MySQL] How to send some info from MySQL to POL

Post by Harley » Thu Jan 31, 2019 5:44 pm

Hi guys!
For the reason that answers to my questions still remain, I want to know, how POL can get specific information from MySQL request?

Cause all that I got is only from this code:

Code: Select all

	query:="SELECT card FROM gamecards "+ card +"";
	print( " InMySQL() | query 1 : " + query ); // DEBUG

	query:= mysql_query(connection,query);
	print( " InMySQL() | query 2 : " + query ); // DEBUG
This one:
InMySQL() | query 1 : SELECT card FROM gamecards card_name
InMySQL() | query 2 : SQLResultSet
But I want to return this card_name and compare it. How can I make it with our POL functions?

p.s.
Maybe there is some reason to give more information, besides how MySQL works, how POL works with in this topic?
viewtopic.php?f=7&t=6222

With best regards!)

Skinny
Expert Poster
Posts: 72
Joined: Wed Dec 19, 2012 10:27 pm

Re: [MySQL] How to send some info from MySQL to POL

Post by Skinny » Fri Feb 01, 2019 10:49 am

Code: Select all

var value_name := "test";
var query := "SELECT card FROM gamecards WHERE card_name = " + value_name;
var result := mysql_query(connection, query);

if(!mysql_num_rows(result))
	Syslog("\nNo card found.");
	return 0;
endif

var line;
while(line := mysql_fetch_row(result))
	Syslog("\n " + line);
endwhile

Harley
Forum Regular
Posts: 350
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: [MySQL] How to send some info from MySQL to POL

Post by Harley » Sun Feb 03, 2019 4:28 pm

Skinny, thank you for an example! Will test very soon!

Harley
Forum Regular
Posts: 350
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: [MySQL] How to send some info from MySQL to POL

Post by Harley » Mon Mar 04, 2019 3:43 pm

Hello guys!
I tested this function

Code: Select all

mysql_fetch_row(result)
And like in docs said, that:
Return values
Array on success
This is my result:

Code: Select all

syslog [pkg/player/login/checkPT/mysql/MySQL_CNC.ecl]: [MySQL] Connection Successful!
 MySQL_CNC() | connection : SQLConnection
syslog [pkg/player/login/checkPT/mysql/MySQL_CNC.ecl]: [MySQL] Database Selected!
 MySQL_CNC() | selectdb : 1
syslog [pkg/player/login/checkPT/mysql/MySQL_CNC.ecl]: [MySQL] Query Result Sent!
 MySQL_CNC() | result : SQLResultSet
syslog [pkg/player/login/checkPT/mysql/MySQL_CNC.ecl]: [MySQL] Array Selected! : SQLRow
 MySQL_CNC() | getArray : SQLRow
syslog [pkg/player/login/checkPT/mysql/MySQL_CNC.ecl]: [MySQL] Connection Closed!
I think that there is something wrong or I don't know something.
By the way, I'll be very grateful to know some new info for it)

With best regards!

Turley
POL Developer
Posts: 654
Joined: Sun Feb 05, 2006 4:45 am

Re: [MySQL] How to send some info from MySQL to POL

Post by Turley » Wed Mar 06, 2019 9:25 am

I hope that you don't expect any detailed answer for your problem when you just publish random script outputs without the code.
mysql_fetch_row returns an array like object to get the content simply use res[1], res[2],.. up until the number of rows you have in your query

Harley
Forum Regular
Posts: 350
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: [MySQL] How to send some info from MySQL to POL

Post by Harley » Sun Mar 10, 2019 3:25 pm

Turley, thank you for your answer.
Of course, my request wasn't full and informative.
After some days, I guessed that POL can't display full array of MySQL result, and its a pity!

But I found some bugs with this functions and want to share them!

This is how my code works:
1st step
I connect to DB

Code: Select all

	var connection := mysql_connect( DB_HOST, DB_USERNAME, DB_PASSWORD );
	if( connection.errortext )
		SysLog("\n	[MySQL GameCards] Connection Failed: " + connection.errortext );
	else
		syslog("\n	[MySQL GameCards] Connection Successful!");
	endif
syslog [pkg/player/login/gameCards/mysql/MySQL_CreateNewCard.ecl]:
[MySQL GameCards] Connection Successful!

Code: Select all

	print( " MySQL_CreateNewCard() | connection : " + connection ); // DEBUG
MySQL_CreateNewCard() | connection : SQLConnection

2nd step
I select DB name

Code: Select all

	var selectdb := mysql_select_db( connection, DB_NAME );
	if( selectdb.errortext )
		SysLog("\n	[MySQL GameCards] Database Selection Failed: " + selectdb.errortext );
	else
		SysLog("\n	[MySQL GameCards] Database Selected!");
	endif
syslog [pkg/player/login/gameCards/mysql/MySQL_CreateNewCard.ecl]:
[MySQL GameCards] Database Selected!

Code: Select all

	print( " MySQL_CreateNewCard() | selectdb : " + selectdb ); // DEBUG
MySQL_CreateNewCard() | selectdb : 1

3rd step
I INSERT INTO 'gcards' table some info

Code: Select all

	query := "INSERT INTO gcards (
		card, card_days, card_time
		)
	VALUES ('"+ card +"', '"+ card_days +"', '"+ card_time +"'
		)";
	result := mysql_query( connection, query );
	if( result.errortext )
		SysLog("\n	[MySQL GameCards] Query Result 1 Failed: " + result.errortext );
	else
		SysLog("\n	[MySQL GameCards] Query Result 1 Sent!");
	endif
syslog [pkg/player/login/gameCards/mysql/MySQL_CreateNewCard.ecl]:
[MySQL GameCards] Query Result 1 Sent!

Code: Select all

	print( " MySQL_CreateNewCard() | result : " + result ); // DEBUG
MySQL_CreateNewCard() | result 1 : SQLResultSet

4th step
I SELECT last added card with ORDER BY id DESC colomn (id is AUTO_INCREMENT)

Code: Select all

	query := "SELECT * FROM gcards ORDER BY id DESC";
	result := mysql_query( connection, query );

	var getArray := mysql_fetch_row( result );
	if( getArray.errortext )
		SysLog("\n	[MySQL GameCards] mysql_fetch_row() Failed: " + getArray.errortext );
	else
		SysLog("\n	[MySQL GameCards] Array Selected! : " + getArray[1] );
	endif
syslog [pkg/player/login/gameCards/mysql/MySQL_CreateNewCard.ecl]:
[MySQL GameCards] Array Selected! : 3

Code: Select all

	print( " MySQL_CreateNewCard() | getArray : " + getArray[1] ); // DEBUG
MySQL_CreateNewCard() | getArray : 3



5th step
I INSERT INTO 'gcards_created_by' table some else info with Third Normal Form (3NF) order

Code: Select all

	query:="INSERT INTO gcards_created_by (
		id_card,
		created_by_account, created_by_name, created_by_ip,
		created_by_serial, created_by_serial_hex
		)
	VALUES ('"+ getArray[1] +"',
		'"+ card_created_by_acc +"', '"+ card_created_by_name +"',
		'"+ card_created_by_ip +"', '"+ card_created_by_serial +"', '"+ card_created_by_serial_hex +"'
		)";

	result := mysql_query( connection, query );
	if( result.errortext )
		SysLog("\n	[MySQL GameCards] Query Result 2 Failed: " + result.errortext );
	else
		SysLog("\n	[MySQL GameCards] Query Result 2 Sent!");
	endif
syslog [pkg/player/login/gameCards/mysql/MySQL_CreateNewCard.ecl]:
[MySQL GameCards] Query Result 2 Sent!

Code: Select all

	print( " MySQL_CreateNewCard() | result 2 : " + result ); // DEBUG
MySQL_CreateNewCard() | result 2 : SQLResultSet

6th step
I INSERT INTO 'gcards_created_time' table some else info with Third Normal Form (3NF) order

Code: Select all

	query:="INSERT INTO gcards_created_time (
		id_card,
		created_time, created_time_data
		)
	VALUES ('"+ getArray[1] +"',
		'"+ card_created_time +"', '"+ card_created_time_data +"'
		)";

	result := mysql_query( connection, query );
	if( result.errortext )
		SysLog("\n	[MySQL GameCards] Query Result 3 Failed: " + result.errortext );
	else
		SysLog("\n	[MySQL GameCards] Query Result 3 Sent!");
	endif
syslog [pkg/player/login/gameCards/mysql/MySQL_CreateNewCard.ecl]:
[MySQL GameCards] Query Result 3 Sent!

Code: Select all

	print( " MySQL_CreateNewCard() | result 3 : " + result ); // DEBUG
MySQL_CreateNewCard() | result 3 : SQLResultSet

7th step
And the final step!
If I find some nonexistent card in my DB, pol make MINIDUMP!

Code: Select all

	query := "SELECT * FROM gcards WHERE card IN('xxxxxxxxxxx') ";
	result := mysql_query( connection, query );

	getArray := mysql_fetch_row( result );
	if( getArray.errortext )
		SysLog("\n	[MySQL GameCards] mysql_fetch_row() Failed: " + getArray.errortext );
	else
		SysLog("\n	[MySQL GameCards] Array Selected! : " + getArray[1] );
	endif

Unhandled Exception! Minidump started...

##########################################################
Current StackBackTrace
(function-name not available) - 0x140261b47
(filename not available)
(function-name not available) - 0x14025694f
(filename not available)
(function-name not available) - 0x140256530
(filename not available)
UnhandledExceptionFilter - 0x7ffba610bdd0
(filename not available)
memset - 0x7ffba8ed3167
(filename not available)
_C_specific_handler - 0x7ffba8ebb5e6
(filename not available)
_chkstk - 0x7ffba8ecf7dd
(filename not available)
RtlWalkFrameChain - 0x7ffba8e3d856
(filename not available)
KiUserExceptionDispatcher - 0x7ffba8ece70e
(filename not available)
(function-name not available) - 0x1400dbddf
(filename not available)
(function-name not available) - 0x140219801
(filename not available)
(function-name not available) - 0x1402141c6
(filename not available)
(function-name not available) - 0x1400caecd
(filename not available)
(function-name not available) - 0x1400cd025
(filename not available)
(function-name not available) - 0x1400900bb
(filename not available)
(function-name not available) - 0x140255452
(filename not available)
(function-name not available) - 0x140255688
(filename not available)
(function-name not available) - 0x1402a2f99
(filename not available)
BaseThreadInitThunk - 0x7ffba6463dc4
(filename not available)
RtlUserThreadStart - 0x7ffba8ea3691
(filename not available)
##########################################################
##########################################################
Unhandled Exception! Writing Minidump file.
Post this file with explanation and last lines from log files on http://forums.polserver.com/tracker.php for the development team.
Saved dump file to '20190311011640-0.dmp'

Last Script: pkg/player/login/gameCards/mysql/MySQL_CreateNewCard.ecl PC: 512
##########################################################

Code: Select all

	print( " MySQL_CreateNewCard() | getArray : " + getArray[1] ); // DEBUG
...

I have a several questions!
Is it real to make that from DB we will get a full array of result SELECT * FROM ....?
Can we change so that in case of failure, will shown an error is instead a minidump?
Can we make that POL displays full array of result?
And what do you think about implementing associative arrays in mysql functions?)

p.s. I still use 99.0.1 Break Everything Even Rudder ;-)
20190311011640-0.dmp
(99.79 KiB) Downloaded 11 times
With best regards!
Last edited by Harley on Fri Mar 15, 2019 4:48 pm, edited 1 time in total.

Harley
Forum Regular
Posts: 350
Joined: Sat Mar 18, 2006 1:41 am
Location: Germany

Re: [MySQL] How to send some info from MySQL to POL

Post by Harley » Fri Mar 15, 2019 4:28 pm

Okay, guys! I see that you don't want to make some changes for us in MySQL functions, but there is a SOS situation!
Why POL writes me Minidumps? I don't know, but I hope that you will find some desicion.
Here is some new)
20190316022330-0.dmp
(101.95 KiB) Downloaded 13 times
With best regards and hope for a bright future)

Skinny
Expert Poster
Posts: 72
Joined: Wed Dec 19, 2012 10:27 pm

Re: [MySQL] How to send some info from MySQL to POL

Post by Skinny » Fri May 10, 2019 6:51 pm

Harley wrote:
Sun Mar 10, 2019 3:25 pm

7th step
And the final step!
If I find some nonexistent card in my DB, pol make MINIDUMP!

Code: Select all

	query := "SELECT * FROM gcards WHERE card IN('xxxxxxxxxxx') ";
	result := mysql_query( connection, query );

	getArray := mysql_fetch_row( result );
	if( getArray.errortext )
		SysLog("\n	[MySQL GameCards] mysql_fetch_row() Failed: " + getArray.errortext );
	else
		SysLog("\n	[MySQL GameCards] Array Selected! : " + getArray[1] );
	endif

try this:

Code: Select all

	query := "SELECT * FROM gcards WHERE card = 'xxxxxxxxxxx'";
	result := mysql_query( connection, query );

	if(result.errortext)
		SysLog("\n	[MySQL GameCards] mysql_query() Failed: " + result.errortext );
		return 0;
	endif
	
	var numfound := mysql_num_rows(result);
	if(!numfound)
		SysLog("\n	[MySQL GameCards] mysql_num_rows(): no rows found.");
		return 0;
	endif

	//Columns: card, card_days, card_time
	var line;
	var cards_result := array{};
	while(line := mysql_fetch_row(result))
		var card := struct;
		card['card'] := line[1];
		card['card_days'] := line[2];
		card['card_time'] := line[3];
		cards_result.append(card);
	endwhile
	
	print(cards_result);


Post Reply