logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
No respose from "SELECT datetime('now');"

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related
View previous topic :: View next topic  
Author Message
JustVoodoo



Joined: 17 Jan 2012
Posts: 4

PostPosted: Wed Jan 18, 2012 12:12    Post subject: No respose from "SELECT datetime('now');" Reply with quote

I tried it with SQLiteBrowser an it works.

The logile says "o Got request: SELECT datetime('now','localtime');" but I do not get a response...

A work around is to make an entry for the Date and then "select * FROM x WHERE Id=1" or s.t. like that, but isn't there a way to get that response?

BTW: Does anyone knows a solution for that strftime('%s', 'now') problem? The % will be replaced with ~ and thats pretty bad. Especially because I need the current Day of the Week ( strftime('%W', 'now') ) ...

Any other ways to get the Day of the Week will be fine as well Wink

Thx for Help
Back to top
View user's profile Send private message
Lokey



Joined: 02 Jan 2005
Posts: 158

PostPosted: Fri Jan 20, 2012 0:38    Post subject: Reply with quote

SELECT NOW(); is date + time
SELECT TIME();
SELECT DATE();

Unix time functions can be useful too.

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html
_________________
Neversummer PW NWNx powered mayhem Wink
Back to top
View user's profile Send private message
JustVoodoo



Joined: 17 Jan 2012
Posts: 4

PostPosted: Fri Jan 20, 2012 17:42    Post subject: Reply with quote

Hi Lokey,

thx for your answer but I guess that that functons are for MySQL not for SQLite. Even in QueryBrowser it says "no such function".

Or is that a function from NWNX (that translate this into SELECT datetime('now') ?).


BTW:
I did the workaround just a few minutes ago. Since I needed some other timefunctions like strftime('%s','now') and strftime('%W','now') and you can't use "%" in a string in NWScript (because some mechanics I dont know translate every "%" in "~", there is another topic about that issue).

So I am using a TRIGGER like this:

Code:

CREATE TRIGGER update_timestamp AFTER UPDATE OF value ON module
BEGIN
   UPDATE module SET value = strftime('%s',(SELECT value FROM module WHERE variable='ActualTime'),'localtime') WHERE variable='ActualTimestamp';
   UPDATE module SET value = strftime('%w',(SELECT value FROM module WHERE variable='ActualTime'),'localtime') WHERE variable='ActualTimeWeekOfYear';
END;


I am using a table "module" with 2 columns "variable" and "value", to store some stuff for my module. Three rows are used for my time thing.

ID,variable,value
1, ActualTime, 2012-01-01 00:00:00
2, ActualTimestamp, 1325376000
3, ActualTimeWeekOfYear, 0

Everytime I update ActualTime, the other 2 Rows will be updated by the trigger and then I can read that values with the normal DBReadString command from NWNX.
Back to top
View user's profile Send private message
Lokey



Joined: 02 Jan 2005
Posts: 158

PostPosted: Sat Jan 21, 2012 1:00    Post subject: Reply with quote

Sorry reading fail. There's certainly sqlite manuals around, spitting out time shouldn't be too hard (failing that there's other modules that give access to environment).
_________________
Neversummer PW NWNx powered mayhem Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Database related All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group