Pejayuk wrote:
> I still can't get this to work.
> Can someone help please.
> 
> :working:
> 
> 
> Pejayuk wrote:
>> That is fantastic Igor.
>> Thankyou.
>> All I need to do now is work out how to get an update query to use a
>> select query to update the records from stats_memory to stats_static after
>> doing the link.
>> I think google may be able to help me with that.
>> Thankyou for your time.
>> =)
>>
>> EDIT:
>> I have just had a look around google. I think the following is what I need
>> to do but would like to know if someone can confirm I have this correct.
>>
>> I have the static_stats database and :memory: database open.
>> I then attach as follows.
>>
>> ATTACH ':memory:' as db1;
>> ATTACH 'stats_static' as db2;
>>
>> I then update the records in stats_static stats as follows from the
>> :memory: stats table.
>> INSERT OR REPLACE INTO db2.stats (rank, steamid, playername, zkills,
>> hkills, deaths, degrade, prounds, lastvisit, points) SELECT rank, steamid,
>> playername, zkills, hkills, deaths, degrade, prounds, lastvisit, points
>> from db1.stats
>>
>> I then detach the databases as follows.
>> DETACH 'stats_static'
>> DETACH ':memory:' 
>>
>> a) Would the insert or replace query as shown above, update the
>> stats_static database with the fields from :memory: ?.
>> b) After the detach command, would both the databases still be open as
>> they were before the attach command?.
>>
>> Many thanks in advance.
>>
>> EDIT2:
>> Another thought.
>> If I executed the following querys on the stats_static database.
>>
>> ATTACH ':memory:' as db1;
>>
>> INSERT OR REPLACE INTO stats SELECT rank, steamid, playername, zkills,
>> hkills, deaths, degrade, prounds, lastvisit, points from db1.stats
>>
>> DETACH ':memory:'
>>
>> Does that give me what I want.
>> Think this is more what I should be doing.
>> Can someone please confirm.
>>
>> Sorry for all the edits.
>>

You would be better served if you took a little more time to format your 
questions so they are clear to the reader. Rambling edits and pasting 
content as quotations doesn't help.

You need to open your permanent database as you normally would and then 
execute an SQL attach command to attach the memory database. I'm don't 
know the syntax for your eventscripts language, but if you can execute 
queries this would be much the same.

   es_xsql open stats_static |zmstats
   stats_static.execute "ATTACH ':memory:' as stats_temp"
   stats_static.execute "create table stats_temp.stats (...)"

Now copy data from the permanent database to the temp or vice versa. 
Note, "main" is the implicit name of the database that was opened as 
stats_static (i.e. by a call to sqlite3_open() by your eventscripts).

   stats_static.execute "INSERT into stats_temp.stats select * from 
main.stats"

Once the temp data is loaded it can be manipulated using normal SQL 
commands and the table name "stats_temp.stats".

When it is time to save the temp data simply copy it back.

   stats_static.execute "INSERT OR REPLACE into main.stats select * from 
stats_temp.stats"

Now you can detach the memory database and close the permanent database.

   stats_static.execute "DETACH stats_temp"
   es_xsql close stats_static

I'm doing a lot of reading between the lines, but I hope you get the 
gist of it.

HTH
Dennis Cote
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to