SQLite deletes the last 25% of records in the database

I am using a SQLite database to store values ​​from a data logger. The data logger will eventually fill up all available space on the computer’s hard drive. I am looking for a way to remove the last 25% of the logs from the database when it reaches a certain limit.

Using the following code:

$ret = Query( 'SELECT id as last FROM data ORDER BY id desc LIMIT 1 ;' ); 
$last_id = $ret[0]['last'] ; 
$ret = Query( 'SELECT count( * ) as total FROM data' );
$start_id = $last_id - $ret[0]['total'] * 0.75 ; 
Query( 'DELETE FROM data WHERE id < '. round( $start_id, 0 ) );

A log file is created next to the database, which fills up the remaining disk space until the script runs.

How / Can I stop creating this log file? In any case, to combine all three SQL queries into one statement?

+5
source share
1 answer

, , SQLite .

:

PRAGMA journal_mode;
PRAGMA database.journal_mode;
PRAGMA journal_mode = DELETE | TRUNCATE | | | OFF
PRAGMA database.journal_mode = DELETE | TRUNCATE | | |

, .

. journal_mode. - , , ATTACH. .

. 4- . "" ( , sqlite3_open(), sqlite3_open16() sqlite3_open_v2()) "temp" , TEMP. , , ATTACH. . , .

DELETE - . DELETE . , - , . ( . Atomic Commit In SQLite).

TRUNCATE , , . , , .

PERSIST . . . PERSIST , , .

MEMORY . -, . , SQLite, , MEMORY, , , .

OFF . , , . OFF SQLite. ROLLBACK ; undefined. ROLLBACK, . , , , , .

, journal_mode MEMORY OFF . journal_mode , MEMORY OFF, . , journal_mode , .

+2

All Articles