@@ -431,6 +431,9 @@ def __init__(self, nomFichero):
431431
432432 self .rowidReader = Util .RowidReader (self .nomFichero , self .tabla )
433433
434+ def reset_cache (self ):
435+ self .cache = {}
436+
434437 def addcache (self , rowid , reg ):
435438 if len (self .cache ) > self .maxcache :
436439 keys = self .cache .keys ()
@@ -879,9 +882,18 @@ def leeAllRecno(self, recno):
879882 self ._cursor .execute ("SELECT %s FROM %s WHERE rowid =%d" % (select , self .tabla , rowid ))
880883 return self ._cursor .fetchone ()
881884
885+ def leeRegAllRecno (self , recno ):
886+ raw = self .leeAllRecno (recno )
887+ alm = Util .Almacen ()
888+ for campo in self .liCamposAll :
889+ setattr (alm , campo , raw [campo ])
890+ return alm , raw
891+
882892 def leePartidaRecno (self , recno ):
883893 raw = self .leeAllRecno (recno )
894+ return self .leePartidaRaw (raw )
884895
896+ def leePartidaRaw (self , raw ):
885897 p = Partida .PartidaCompleta ()
886898 xpgn = raw ["PGN" ]
887899 rtags = None
@@ -1005,6 +1017,8 @@ def modifica(self, recno, partidaCompleta):
10051017 self .dbSTAT .append (pvAnt , resAnt , - 1 )
10061018 self .dbSTAT .append (pvNue , resNue , + 1 )
10071019
1020+ del self .cache [rowid ]
1021+
10081022 return True
10091023
10101024 def inserta (self , partidaCompleta ):
@@ -1038,3 +1052,74 @@ def inserta(self, partidaCompleta):
10381052
10391053 def guardaPartidaRecno (self , recno , partidaCompleta ):
10401054 return self .inserta (partidaCompleta ) if recno is None else self .modifica (recno , partidaCompleta )
1055+
1056+ def massive_change_tags (self , li_tags_change , liRegistros , remove , overwrite ):
1057+ dtag = Util .SymbolDict ({tag :val for tag , val in li_tags_change })
1058+
1059+ def work_tag (tag , alm ):
1060+ if tag in dtag :
1061+ ant = getattr (alm , tag .upper ())
1062+ if (ant and overwrite ) or not ant :
1063+ setattr (alm , tag .upper (), dtag [tag ])
1064+
1065+ if remove :
1066+ remove = remove .upper ()
1067+
1068+ for recno in liRegistros :
1069+ alm , raw = self .leeRegAllRecno (recno )
1070+
1071+ work_tag ("Event" , alm )
1072+ work_tag ("Site" , alm )
1073+ work_tag ("Date" , alm )
1074+
1075+ p = self .leePartidaRaw (raw )
1076+ if remove :
1077+ for n , (tag , val ) in enumerate (p .liTags ):
1078+ if tag .upper () == remove :
1079+ del p .liTags [n ]
1080+ break
1081+ setattr (alm , remove , "" )
1082+
1083+ st_tag_ant_upper = set ()
1084+ for n , (tag , val ) in enumerate (p .liTags ):
1085+ if overwrite :
1086+ if tag in dtag :
1087+ p .liTags [n ] = [tag , dtag [tag ]]
1088+ st_tag_ant_upper .add (tag .upper ())
1089+ setattr (alm , tag .upper (), p .liTags [n ][1 ])
1090+
1091+ for tag_new in dtag :
1092+ if tag_new .upper () not in st_tag_ant_upper :
1093+ p .liTags .append ([tag_new , dtag [tag_new ]])
1094+ setattr (alm , tag_new .upper (), dtag [tag_new ])
1095+
1096+ rowid = self .liRowids [recno ]
1097+ pgn = {"FULLGAME" : p .save ()}
1098+ xpgn = Util .var2blob (pgn )
1099+ sql = "UPDATE GAMES SET EVENT=?, SITE=?, DATE=?, WHITE=?, BLACK=?, RESULT=?, " \
1100+ "ECO=?, WHITEELO=?, BLACKELO=?, PGN=? WHERE ROWID = %d" % rowid
1101+ self ._cursor .execute (sql , (alm .EVENT , alm .SITE , alm .DATE , alm .WHITE , alm .BLACK , alm .RESULT ,
1102+ alm .ECO , alm .WHITEELO , alm .BLACKELO , xpgn ))
1103+
1104+ self ._conexion .commit ()
1105+
1106+ self .reset_cache ()
1107+
1108+ def insert_pks (self , path_pks ):
1109+ f = open (path_pks , "rb" )
1110+ txt = f .read ()
1111+ f .close ()
1112+ dic = Util .txt2dic (txt )
1113+ fen = dic .get ("FEN" )
1114+ if fen :
1115+ return _ ("This pks file is not a complete game" )
1116+
1117+ liTags = dic .get ("liPGN" , [])
1118+
1119+ partidaCompleta = Partida .PartidaCompleta (liTags = liTags )
1120+ partidaCompleta .recuperaDeTexto (dic ["PARTIDA" ])
1121+
1122+ if not self .inserta (partidaCompleta ):
1123+ return _ ("This game already exists." )
1124+
1125+ return None
0 commit comments