Fires of Heaven Guild Message Board  

Go Back   Fires of Heaven Guild Message Board > General forums > Development
User Name
Password
ForumSpy Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 05-23-2008, 10:42 AM   #1 (permalink)
x1hundredregrets
Reactor Zero
 
x1hundredregrets's Avatar
 
Join Date: Dec 2002
Posts: 307
-5 Internets
SQL / SQLite trigger question

Hey all,

I'm writing a server app and client app in C# to handle some file caching.

I have these two tables:

mycommand.CommandText = "CREATE TABLE IF NOT EXISTS 'cache' (id INTEGER PRIMARY KEY, md5 VARCHAR(32), filename char(255), timeAdded TIMESTAMP, timeLastRef TIMESTAMP, fileize INTEGER, filedata BLOB)";
mycommand.ExecuteNonQuery();
mycommand.CommandText = "CREATE TABLE IF NOT EXISTS 'info' (totalFiles INTEGER, totalFileSize INTEGER)";
mycommand.ExecuteNonQuery();



I want to update the 'info' table's totalFiles and totalFileSize whenever a DELETE or INSERT is done on 'cache'. I need to use triggers since they are an atomic operation as far as SQLite is concerned.

Does anyone know the correct syntax for something like that? I googled it and came up with very very little info that applies to my specific case.

Thanks in advance!
x1hundredregrets is offline   Reply With Quote
Old 05-23-2008, 10:51 AM   #2 (permalink)
rangoth
collector of stuff
 
rangoth's Avatar
 
Join Date: Feb 2006
Location: constitution beach
Posts: 531
-1 Internets
Send a message via AIM to rangoth Send a message via MSN to rangoth
Code:
CREATE TRIGGER *trigger name* ON *table name* FOR INSERT AS *action to commit*

Last edited by rangoth : 05-23-2008 at 10:53 AM. Reason: used code blocks
rangoth is offline   Reply With Quote
Old 05-23-2008, 10:53 AM   #3 (permalink)
x1hundredregrets
Reactor Zero
 
x1hundredregrets's Avatar
 
Join Date: Dec 2002
Posts: 307
-5 Internets
I got that much done, lol. I'm wondering how I access the filesize column from the row being INSERTED or DELETED? Heres what I have so far, but it's throwing an exception because the syntax is wrong somehow:

mycommand.CommandText = "CREATE TRIGGER IF NOT EXISTS 'updateInfoOnDelete' DELETE ON 'cache' BEGIN UPDATE 'info' SET 'totalFiles'=totalFiles-1; UPDATE 'info' SET 'totalFileSize'=totalFileSize-old.filesize; END";
mycommand.ExecuteNonQuery();
mycommand.CommandText = "CREATE TRIGGER IF NOT EXISTS 'updateInfoOnInsert' INSERT ON 'cache' BEGIN UPDATE 'info' SET 'totalFiles'=totalFiles+1; UPDATE 'info' SET 'totalFileSize'=totalFileSize+old.filesize; END";
mycommand.ExecuteNonQuery();

Thanks again for the quick reply.
x1hundredregrets is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
uberguilds network



All times are GMT -7. The time now is 08:45 PM.


Powered by vBulletin® Version 3.6.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0 RC6