Code: Select all
Procedure PragmaSet( updates.i = 512, setcommit = 0 )
Protected temp.s
sql = "PRAGMA temp_store = MEMORY"
DatabaseUpdate( gLocaldb, sql )
sql = "PRAGMA page_size = 8192"
DatabaseUpdate( gLocaldb, sql )
If setcommit
;sql = "PRAGMA journal_mode = TRUNCATE" ;MEMORY is faster but unsafe if crash occurs
sql = "PRAGMA journal_mode = MEMORY"
DatabaseQuery( gLocaldb, sql )
FinishDatabaseQuery( gLocaldb )
EndIf
sql = "PRAGMA synchronous = OFF"
DatabaseUpdate( gLocaldb, sql )
sql = "cache_size=" + Str( updates )
DatabaseUpdate( gLocaldb, sql )
sql = "pragma default_cache_size=" + Str( updates )
DatabaseUpdate( gLocaldb, sql )
EndProcedure
Code: Select all
Macro dbUpdate( runsql )
If Not DatabaseUpdate( gLocaldb, runsql )
Debug "[" + #PB_Compiler_Procedure + "] sql=" + runsql + Chr(13) + DatabaseError()
EndIf
EndMacro
Now lets say you have a table which you use often, and which you only add to (no deletes or modifies), and this table is called testdata
then you do the following
Code: Select all
sql = "create temp table tmptestdata( id INTEGER PRIMARY KEY AUTOINCREMENT,text TEXT, time time NOT NULL DEFAULT CURRENT_TIMESTAMP)"
dbUpdate( sql )
sql = "insert into temp.tmptestdata select * from testdata"
dbUpdate( sql )
select * from mytable
INNER JOIN temp.tmptestdata id = mytable.link_id;
You want to add to the meory table for speed? No problem, do so and then at timely intervals
Code: Select all
Procedure SyncronizeTable( table.s )
Protected sql.s
Protected id.i
sql = "select id from " + table + " order by id desc limit 1"
If DatabaseQuery( gLocaldb, sql )
If NextDatabaseRow( gLocaldb )
id = GetDatabaseLong( gLocaldb, 0 )
EndIf
FinishDatabaseQuery( gLocaldb )
Else
WriteLog( "[" + #PB_Compiler_Procedure + "] sql=" + sql + LF + DatabaseError() )
EndIf
sql = "insert into " + table + " select * from temp.tmp" + table + " where temp.tmp" + table + ".id > " + Str( id )
dbUpdate( sql )
EndProcedure