Page 1 of 1

How do I VACUUM a SQL database

Posted: Mon Jan 02, 2017 1:00 am
by Redlion
Hi,

I am playing with a very simple family tree program and wanted to clean up the database after all the updating.

I thought I could just use the SQL Vacuum command, but it does not work?

Here is the cut down code I am using, it is all that is needed to access the Database.

Code: Select all

function setup() ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    db = assert_userdata( sqlite3.open(Dir$.."FamilyData.sql") )
endfunction

function closedown() ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    assert_number( db:close() )
endfunction

function assert_number(f) ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    if gettype(f) <> #number then debugprint("Assertion failed")
    return(f)
endfunction

function assert_userdata(f) ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    if gettype(f) <> #userdata then debugprint("Assertion failed")
    return(f)
endfunction

function vacuum() ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    assert_number(db:exec("VACUUM"))
endfunction


setup()
vacuum()
closedown()
If anyone can suggest the correct syntax , that would move me on to the next challenge.

Thanks and Happy New Year to all.

Re: How do I VACUUM a SQL database

Posted: Tue Jan 03, 2017 12:08 pm
by sinisrus
Can be that ?
TRUNCATE TABLE `nom_de_la_table`

Re: How do I VACUUM a SQL database

Posted: Tue Jan 03, 2017 2:16 pm
by lazi
Try this:

db:exec("Vacuum")

As there is written https://sqlite.org/lang_vacuum.html it repacks the file to make it shorter. You can only see if it done anything, if there was e.g. deleted rows in the database.