@@ -38,7 +38,6 @@ def __getitem__(self, i): # i is 0-based
3838 ), f"page index is out of range: { i } is not in (0, { header .num_pages - 1 } )"
3939 # todo: maybe cache page
4040 # equality test: page_a.page_number == page_b.page_number
41- # FIXME handle root page: i == 0
4241 _pos = root ._io .pos ()
4342 if i == 0 :
4443 # The first 100 bytes of the database file comprise the database file header
@@ -176,15 +175,15 @@ def get_local_key(key, global_names):
176175root = kaitaistruct_sqlite3 .Sqlite3 .from_bytes (good_database_header_bytes )
177176
178177# patch the internal cache attribute of root.pages
179- # root._m_pages = PagesList(root)
178+ root ._m_pages = PagesList (root )
180179
181180root ._read ()
182181
183182# print("root.header.magic", root.header.magic)
184183# now, this will parse **only** the first page
185184# fix: 'BtreePage' object has no attribute 'cell_pointers'
186185
187- if 1 :
186+ if 0 :
188187 # print("root.pages[0] keys:", get_keys(root.pages[0]))
189188 # print("root.pages[0] seq:", get_seq(root.pages[0]))
190189 # FIXME kaitaistruct.ValidationNotEqualError: /types/database_header/seq/0: at pos 116: validation failed: not equal,
@@ -198,7 +197,7 @@ def get_local_key(key, global_names):
198197 print_value ("root.pages[0].num_cells" )
199198 print_value ("root.pages[0].cell_pointers[0]" )
200199 print_value ("root.pages[0].cell_pointers[0].ofs_content" )
201- if 1 :
200+ if 0 :
202201 # print("root.pages[1] keys:", get_keys(root.pages[1]))
203202 # print("root.pages[1] seq:", get_seq(root.pages[1]))
204203 print ("root.pages[1]._read()" ); root .pages [1 ]._read ()
@@ -309,6 +308,10 @@ def codegen(
309308 print (f"{ ind } { ids } if not _io:" , file = out )
310309 print (f"{ ind } { ids } { ids } _io = kaitaistruct.KaitaiStream(io.BytesIO(bytearray(root_size)))" , file = out )
311310 print (f"{ ind } { ids } { on } = { mod } .{ member } (_io)" , file = out )
311+ # TODO remove. this works only for sqlite3.ksy
312+ print (f"{ ind } { ids } # try to fix root._write" , file = out )
313+ print (f"{ ind } { ids } # https://github.com/kaitai-io/kaitai_struct/issues/1245" , file = out )
314+ print (f"{ ind } { ids } { on } .pages__to_write = False" , file = out )
312315 # else:
313316 # print(f"{ind}{ids}# non-root init", file=out)
314317 # print(f"{ind}{ids}{on} = {mod}.{member}(_io, {on_parent}, {on_parent}._root)", file=out)
@@ -423,11 +426,13 @@ def codegen(
423426 print (f"{ ind } { ids } root = get_root()" , file = out )
424427 print (f"{ ind } { ids } _io = root._io" , file = out )
425428 # print(f"{ind}{ids}_io.seek(0)", file=out)
426- print (f"{ ind } { ids } # no. _write calls _fetch_instances which throws" , file = out )
427- print (f"{ ind } { ids } # root._write(_io)" , file = out )
428- print (f"{ ind } { ids } root._write__seq(_io)" , file = out )
429- print (f"{ ind } { ids } # root._fetch_instances() # this would throw" , file = out )
430- print (f"{ ind } { ids } root._io.write_back_child_streams()" , file = out )
429+ print (f"{ ind } { ids } if 1:" , file = out )
430+ print (f"{ ind } { ids } { ids } # no. _write calls _fetch_instances which throws" , file = out )
431+ print (f"{ ind } { ids } { ids } root._write(_io)" , file = out )
432+ print (f"{ ind } { ids } else:" , file = out )
433+ print (f"{ ind } { ids } { ids } root._write__seq(_io)" , file = out )
434+ print (f"{ ind } { ids } { ids } # root._fetch_instances() # this would throw" , file = out )
435+ print (f"{ ind } { ids } { ids } root._io.write_back_child_streams()" , file = out )
431436 print (f"{ ind } { ids } return _io" , file = out )
432437 print ("" , file = out )
433438 print (f"{ ind } def get_bytes():" , file = out )
0 commit comments