Page 1 of 1
getCollectionFromDb($query, true) ?
Posted: 29 May 2022, 15:19
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.
Re: getCollectionFromDb($query, true) ?
Posted: 29 May 2022, 15:40
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.)
Re: getCollectionFromDb($query, true) ?
Posted: 29 May 2022, 15:59
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...
Re: getCollectionFromDb($query, true) ?
Posted: 29 May 2022, 17:13
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.
Re: getCollectionFromDb($query, true) ?
Posted: 29 May 2022, 20:15
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?
Re: getCollectionFromDb($query, true) ?
Posted: 29 May 2022, 21:16
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
Re: getCollectionFromDb($query, true) ?
Posted: 30 May 2022, 08:45
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...
