persistent.cql

// Download persistent.cql
// PGN output when run on sample.pgn

/**********
Print certain summary statistics about the database

Output to the console the number of games,
positions, underpromotions, wins, draws, mates and stalemates
in the database.

No games are matched in running this CQL code.
**********/

cql(input heijden.pgn)
if initial then
 persistent NumberGames += 1
if stalemate then
  persistent NumberStalemates += 1
if move previous promote [RBNrbn] then
  persistent NumberUnderpromotions += 1
if move previous promote R then
  persistent NumberRookPromotions += 1
if move previous promote B then
  persistent NumberBishopPromotions += 1
if move previous promote N then
  persistent NumberKnightPromotions += 1
if move previous promote Q then
  persistent NumberQueenPromotions += 1
if move previous promote [Aa] then
  persistent NumberPromotions += 1
if move enpassant then
   persistent NumberEnpassants += 1
if move castle then
   persistent NumberCastles += 1
if mate then
  persistent NumberMates+= 1
if {initial result 1-0} then{
    persistent NumberWins += 1
    persistent NumberWhiteWins+=1}
if {initial result 1/2-1/2} then
   persistent NumberDraws += 1
if {initial result 0-1} then{
    NumberWins+=1
    persistent NumberBlackWins+=1
    }
persistent NumberPositions +=1
false //we don't want any large pgn files output