본문 바로가기
프로그래밍 놀이터/iOS

[ios] NSCocoaErrorDomain Code=522 ( SQLite )

by 돼지왕 왕돼지 2018. 2. 12.
반응형

[ios] NSCocoaErrorDomain Code=522 ( SQLite )


출처 : http://stackoverflow.com/questions/18277092/persistentstorecoordinator-sqlite-error-code522-not-an-error

266, coredatadb.sqlite, coredatadb.sqlite-shm, coredatadb.sqlite-wal, corrupted, db file, error code 522, INTERRUPT, IOS, NSCocoaErrorDomain, Read, SQLite, SQLITE_IOERR, SQLITE_IOERR_READ, SQLITE_IOERR_SHORT_READ, VFS layer, [ios] NSCocoaErrorDomain Code=522 ( SQLite )


-

SQLite 의 Error code 522 는 SQLITE_IOERR_SHORT_READ 를 의미한다.



-

SQLITE_IOERR_SHORT_READ 는 SQLITE_IOERR 중 하나로 VFS layer 를 통해 read 를 할 때,

요청한 byte 만큼 읽지 못했을 경우 발생한다.

이 현상이 발생한 이유는 db file 이 망가졌을 때(corrupted) 주로 발생한다.

혹은 간헐적으로 read 도중 interrupt 가 발생했을 때 발생한다.


The SQLITE_IOERR_SHORT_READ error code is an extended error code for SQLITE_IOERR indicating that a read attempt in the VFS layer was unable to obtain as many bytes as was requested. This might be due to a truncated file.



-

해당 에러가 발생하는 코드는 아래 소스 코드에서 찾을 수 있다.

http://www.sqlite.org/src/artifact/07acbb3e074e?ln=3012

266, coredatadb.sqlite, coredatadb.sqlite-shm, coredatadb.sqlite-wal, corrupted, db file, error code 522, INTERRUPT, IOS, NSCocoaErrorDomain, Read, SQLite, SQLITE_IOERR, SQLITE_IOERR_READ, SQLITE_IOERR_SHORT_READ, VFS layer, [ios] NSCocoaErrorDomain Code=522 ( SQLite )



-

아예 바이트를 읽지 못할 경우에는 SQLITE_IOERR_READ (266) 가 발생함도 확인해 볼 수 있다.



-

iOS 에서의 에러 문구는 "SQLite error code:522, 'not an error’” 와 같이 나타난다.

이는 DB 파일(coredatadb.sqlite) 생성시에 함께 생성되는 coredatadb.sqlite-shm 과 coredatadb.sqlite-wal 파일들이 있는데,

DB 삭제시 coredatadb.sqlite 만 삭제하고 부차적인 파일들은 삭제되지 않기 때문에,

새로운 DB 생성시 오래된 파일들을 참조하면서 발생할 수 있다고 한다.




반응형

댓글