Programmatically corrupting a database

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Programmatically corrupting a database

Deon Brewis
I am trying to write unit tests for some error detection & recovery scenarios and would like to simulate the following type of corruptions:

1) Header corruption (easy)
2) Corrupting a specific SQL Table/Index so that it can be read, but inserts/updates will fail
3) Corrupting a specific SQL Table/Index so that it can neither be read nor written to

Any ideas on how to do the last 2?

- Deon

_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically corrupting a database

Richard Hipp-3
On 3/16/18, Deon Brewis <[hidden email]> wrote:

> I am trying to write unit tests for some error detection & recovery
> scenarios and would like to simulate the following type of corruptions:
>
> 1) Header corruption (easy)
> 2) Corrupting a specific SQL Table/Index so that it can be read, but
> inserts/updates will fail
> 3) Corrupting a specific SQL Table/Index so that it can neither be read nor
> written to
>
> Any ideas on how to do the last 2?

First run the deadly "PRAGMA writable_schema=ON;" statement.  Then
make UPDATEs to the sqlite_master table to do things like change the
root page number of the table or one of its indexes.


--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users
Reply | Threaded
Open this post in threaded view
|

Re: Programmatically corrupting a database

Deon Brewis
Works like a charm. Thanks!

- Deon

-----Original Message-----
From: sqlite-users <[hidden email]> On Behalf Of Richard Hipp
Sent: Friday, March 16, 2018 10:39 AM
To: SQLite mailing list <[hidden email]>
Subject: Re: [sqlite] Programmatically corrupting a database

On 3/16/18, Deon Brewis <[hidden email]> wrote:

> I am trying to write unit tests for some error detection & recovery
> scenarios and would like to simulate the following type of corruptions:
>
> 1) Header corruption (easy)
> 2) Corrupting a specific SQL Table/Index so that it can be read, but
> inserts/updates will fail
> 3) Corrupting a specific SQL Table/Index so that it can neither be
> read nor written to
>
> Any ideas on how to do the last 2?

First run the deadly "PRAGMA writable_schema=ON;" statement.  Then make UPDATEs to the sqlite_master table to do things like change the root page number of the table or one of its indexes.


--
D. Richard Hipp
[hidden email]
_______________________________________________
sqlite-users mailing list
[hidden email]
https://nam04.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmailinglists.sqlite.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fsqlite-users&data=02%7C01%7C%7Cb52a75ab16a34c1f984b08d58b64d9bb%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636568187614528868&sdata=zKOCIZ7IfDLxHIR6WG98ZfFVtvkuvnG4%2Bqp5HiTCBYc%3D&reserved=0
_______________________________________________
sqlite-users mailing list
[hidden email]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users