Skip to content

Conversation

@Pavan-Nambi
Copy link
Contributor

@Pavan-Nambi Pavan-Nambi commented Oct 25, 2025

closes #3833

turso> create table t(x);
turso> select * from sqlite_dbpage;
┌──────┬───────────────────────────────────────────────────────────────────────┐
│ pgno │ data                                                                  │
├──────┼───────────────────────────────────────────────────────────────────────┤
│    1 │ SQLite format 3@  ���0… │
├──────┼───────────────────────────────────────────────────────────────────────┤
… │  2 │
└──────┴───────────────────────────────────────────────────────────────────────┘
turso> .dbtotxt
| size 8192 pagesize 4096 filename 1qazq
| page 1 offset 0
|      0: 53 51 4c 69 74 65 20 66 6f 72 6d 61 74 20 33 00   SQLite format 3.
|     16: 10 00 02 02 00 40 20 20 00 00 00 01 00 00 00 02   .....@  ........
|     32: 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 04   ................
|     48: ff ff f8 30 00 00 00 00 00 00 00 01 00 00 00 00   ...0............
|     80: 00 00 00 00 00 00 00 00 00 00 00 00 00 2e 7e 58   ..............~X
|     96: 00 2e 7e 58 0d 00 00 00 01 0f de 00 0f de 00 00   ..~X............
|   4048: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 01   .............. .
|   4064: 06 17 0f 0f 01 31 74 61 62 6c 65 74 74 02 43 52   .....1tablett.CR
|   4080: 45 41 54 45 20 54 41 42 4c 45 20 74 20 28 78 29   EATE TABLE t (x)
| page 2 offset 4096
|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
| end 1qazq
turso>

sqlite dont support this but i think this is nice to have a --page flag

turso> .dbtotxt --page 2
| size 8192 pagesize 4096 filename :memory:
| page 2 offset 4096
|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
| end :memory:
turso>

Note:

sqlite allows to write into sqlite_db_page , we do not yet, - issue #3836 - i'm not really sure why this is needed, so i didn't bothered with it.

❯ sqlite3 --unsafe-testing /tmp/1qaz
SQLite version 3.50.4 2025-07-30 19:33:53
Enter ".help" for usage hints.
sqlite> INSERT INTO sqlite_dbpage(pgno, data) VALUES(1000, NULL);
sqlite> SELECT pgno FROM sqlite_dbpage WHERE schema='main';
1
2
sqlite> INSERT INTO sqlite_dbpage(pgno, data) VALUES(1, NULL);
Runtime error: bad page value
sqlite> INSERT INTO sqlite_dbpage(pgno, data) VALUES(2, NULL);
sqlite> SELECT pgno FROM sqlite_dbpage WHERE schema='main';
Runtime error: database disk image is malformed (11)
sqlite>

@Pavan-Nambi Pavan-Nambi marked this pull request as draft October 25, 2025 05:45
@Pavan-Nambi Pavan-Nambi force-pushed the need_it_need_it_dbtotx branch 2 times, most recently from 72a4fef to 6b1ee7c Compare October 25, 2025 05:49
@Pavan-Nambi Pavan-Nambi force-pushed the need_it_need_it_dbtotx branch from 6b1ee7c to 56df015 Compare October 25, 2025 05:50
@Pavan-Nambi Pavan-Nambi force-pushed the need_it_need_it_dbtotx branch from 0284241 to d110d1d Compare October 25, 2025 15:17
@Pavan-Nambi
Copy link
Contributor Author

If used on empty db, we currently get this error but it is due to #3441

turso> .dbtotxt
| size 0 pagesize 4096 filename wed
/****** ERROR: Database is empty, header does not exist - page 1 should've been allocated before this ******/
turso>

@Pavan-Nambi Pavan-Nambi marked this pull request as ready for review October 25, 2025 15:31
@Pavan-Nambi
Copy link
Contributor Author

Pavan-Nambi commented Oct 26, 2025

I m thinking maybe it would be nice if we could do smthng like

.dbtotxt --page-no 2

and we only display page 2 , sqlite dont have this, but i had this issue in large dbs i have to scroll forever or pipe it into a file and read from file

@Pavan-Nambi
Copy link
Contributor Author

turso> .dbtotxt --page 2
| size 8192 pagesize 4096 filename :memory:
| page 2 offset 4096
|      0: 0d 00 00 00 00 10 00 00 00 00 00 00 00 00 00 00   ................
| end :memory:
turso>

@Pavan-Nambi
Copy link
Contributor Author

Pavan-Nambi commented Oct 26, 2025

Maybe i am getting ahead of myself but why cant we just use a seperate screen for this? for eg: similar to how .manual command shows it in a seperate screen? - would also be nice cus terminal be clean.

if anyone think this is a good idea, please let me know and i will do that. for now i am not doing it as i am not really sure if its good or bad thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement .dbtotxt and dbpage vtab

1 participant