Cool to see activity on Gnoga!
Coincidentally I was working on the Pasta! game.
An idea for a very useful addition to Gnoga.Server.Database would be a
Simple_Query function for getting just a single information from a database.
The function would take care of connection, recordset and work much like
when you type some SQL statement for getting a number or name in your
preferred SQL interface.
Concretely, instead of:
function Rank_to_score (level, score : String) return String is
DB : aliased Gnoga.Server.Database.SQLite.Connection;
begin
DB.Connect (Database => phyrama_db_name);
declare
-- Count all better scores and put target score as first
ex-aequo.
RS : Gnoga.Server.Database.Recordset'Class :=
DB.Query (
"select 1 + count(Best_score) as Rank from
Pasta_best_score" &
" where Level = " & level & " and Best_score > " & score &
" order by Best_score desc"
);
begin
if RS.Next then
declare
result : constant String := RS.Field_Value ("Rank");
begin
RS.Close;
DB.Disconnect;
return result;
end;
end if;
RS.Close;
DB.Disconnect;
end;
return "";
end Rank_to_score;
you would have only:
function Rank_to_score (level, score : String) return String is
begin
return Simple_Query (Database => phyrama_db_name, Query =>
"select 1 + count(Best_score) as Rank from
Pasta_best_score" &
" where Level = " & level & " and Best_score > " & score &
" order by Best_score desc");
end;
the function Simple_Query would of course look much like the 1st version
of Rank_to_score.
Just need to abstract the kind of database (here it is SQLite). How to
do it best? Perhaps by using 'Class for reaching all of MySQL, SQLite etc. ?
If you want to seean example "in production", I've added Simple_Query to
the cousin of Gnoga.Server.Database, GWindows.Databases
https://sourceforge.net/p/gnavi/code/HEAD/tree/gwindows/framework/gwindows-databases.ads#l365
https://sourceforge.net/p/gnavi/code/HEAD/tree/gwindows/framework/gwindows-databases.adb#l1119
Cheers
Gautier
__
PS: now Pasta! shows your rank when your high score is not in the top 6 :-)
_______________________________________________
Gnoga-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gnoga-list