getCollectionFromDb($query, true) ?

Game development with Board Game Arena Studio
Post Reply
User avatar
Miwarre
Posts: 38
Joined: 07 January 2021, 19:19

getCollectionFromDb($query, true) ?

Post by Miwarre »

If in my game my.game.php' s getAllDatas() I put:

Code: Select all

$result['players'] = self::getCollectionFromDb($sqlquery);
everything is ok. However, if I put:

Code: Select all

$result['players'] = self::getCollectionFromDb($sqlquery, true);
with an optional true parameter at the end, reloading the page brings up a score of warnings of this kind:

Code: Select all

Warning: Illegal string offset 'color' in /var/tournoi/release/tournoi-220513-1000-gs/www/game/module/table/table.game.php on line 232
which is not a file under my control (my game is NOT named "table" nor "220513-1000" is its version!) and the UI is garbled.

Are there contexts where the optional true parameter can be used and contexts where it cannot? I found no mention of this in the documentation.
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: getCollectionFromDb($query, true) ?

Post by robinzig »

What's in your query?

That second parameter is documented as follows (from https://en.doc.boardgamearena.com/Main_ ... e.game.php):

"If you specified $bSingleValue=true and if your SQL query request 2 fields A and B, the method returns an associative array "A=>B", otherwise its A=>[A,B]"

so if you are requesting more than 2 fields (or only one), this is basically unsupported and could well behave strangely. (A more graceful and informative error message would certainly be nice in this case but, unfortunately, the framework isn't good at giving informative error messages.)
User avatar
Miwarre
Posts: 38
Joined: 07 January 2021, 19:19

Re: getCollectionFromDb($query, true) ?

Post by Miwarre »

Thanks for your quick reply.

Your point is correct in general, but I was aware of the documentation you quote and in fact the actual query involves only 2 columns:

Code: Select all

"SELECT player_id id, player_score score FROM player"
so it has to be something else, possibly the framework expecting a specific player info structure; which would be totally legitimate but, if this is the case, it would be useful to know this kind of requirements...
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: getCollectionFromDb($query, true) ?

Post by robinzig »

OK thanks.

I've set that parameter to `true` before with no issues. I suspect therefore that the error message is coming from somewhere later where you're using `$result["players"]`. After all, the purpose of that second parameter is to make the values of that associative array be simple values rather than associative arrays themselves, so if you're accessing values by key in that this would explain the behaviour you're seeing.
User avatar
Miwarre
Posts: 38
Joined: 07 January 2021, 19:19

Re: getCollectionFromDb($query, true) ?

Post by Miwarre »

so if you're accessing values by key in that this would explain the behaviour you're seeing.
Definitely yes, if the warnings were raised by some other point(s) of my own code, but they refer to /var/tournoi/release/tournoi-220513-1000-gs/www/game/module/table/table.game.php which does not belong to my game and it is presumably part of the framework.

This is why above I said it looks like the framework expects some data (player data?) in a specific structure. It also seems to happen only when that function is called in getAllDatas(); I have used that true parameter elsewhere without problems.

Agreed, the problem is rather small: I do without the parameter there and manage the resulting data according to the resulting structure. But the question remains:

Does the framework places undocumented restrictions on the data retrieved from the DB?
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: getCollectionFromDb($query, true) ?

Post by Victoria_La »

Framework does not place any restrictions on db queries. However there is restriction about $result['players'] returned by getAllDatas
This is used by framework itself, so it should contains fields from player table, and format is
player_id => [...]
If you want some other format don't use players field, use players_xx or something
User avatar
Miwarre
Posts: 38
Joined: 07 January 2021, 19:19

Re: getCollectionFromDb($query, true) ?

Post by Miwarre »

Many thanks to @Victoria for the valuable information provided.

It would then be quite useful if the doc page about <mygame>.game.php would detail these requirements, but it does not even mention the getAllDatas() function... :roll:
Post Reply

Return to “Developers”