Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

ios - Do i need to Enable WAL mode to copy .SQLite from bundle to Document directory?

My current application only copying .sqlite file (WAL MODE = DELETE). Everything went smoothly , the new copied myfile.sqlite also contain data perfectly.

When I execute a fetch request , the execution has no error , and BOOL (success) is 1 . BUT the returned array always EMPTY.

https://www.appcoda.com/core-data-preload-sqlite-database/

This tutorial told me I neeed to copy 3 files (.sqlite , .sqlite-wal , .sqlite-shm) in to Document directory .

Does this mean I need to Enable WAL mode and re-do everything from the start? In Xcode 10 we still cannot copy just 1 .sqlite file? Can someone clarify this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Assuming that you mean journal mode, and not WAL MODE (and that you mean Xcode 8.x, since Xcode 10 doesn't exist yet), no you do not need to copy any additional files or change modes. With journal mode set to DELETE there's only the one file. You don't need to create extra files to make copying work.

But there are several other problems you might be having, which you should check on, and if necessary post additional questions about:

  • Maybe the copy phase isn't actually working as perfectly as you think.
  • Maybe you're not adding the SQLite file to the persistent store coordinator-- so it's not available when you do the fetch.
  • Maybe your fetch is misconfigured and is trying to fetch data that isn't present.

As for your question though, no you do not need to copy other files, or change the journal mode to force those other files to exist.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...