AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   mathematical and SQL question (https://forums.alliedmods.net/showthread.php?t=62808)

lomax 11-05-2007 04:10

mathematical and SQL question
 
I need to make a var which is a SUM between 2 integers current time and ban lenght - showld give me ban expire time right ? how do i do that ...

and how to port this line into amxx language ?
INSERT INTO `%s_bans` (`ip`, `authid`, `name`, `created`, `ends`, `length`, `reason`, `aid`, `adminIp`, `sid`) VALUES ('%s', '%s', \"%s\", UNIX_TIMESTAMP(), UNIX_TIMESTAMP() + %d, '%d', '%s', (SELECT `aid` FROM `%s_admins` WHERE `authid` = '%s'), '%s', (SELECT `sid` FROM `%s_servers` WHERE `ip` = '%s' AND `port` = '%s' LIMIT 0,1))", DatabasePrefix, Ip, Authid, Name, (time*60), (time*60), Reason, DatabasePrefix, AdminAuthid, AdminIp, DatabasePrefix, ServerIp, ServerPort);

purple_pixie 11-05-2007 10:52

Re: mathematical and SQL question
 
The maths looks like it should be right ..

The SQLX snippet for that select is basically:
PHP Code:

query_handle SQL_PrepareQuery(connection_handle,"INSERT INTO '%s_bans' 
('ip', 'authid', 'name', 'created', 'ends', 'length', 'reason', 'aid', 'adminIp', 'sid')
VALUES (
'%s',
'%s',
\"%s\",
UNIX_TIMESTAMP(),
UNIX_TIMESTAMP() + %d,
'%d', '%s', 
(SELECT 'aid' FROM '%s_admins' WHERE 'authid' = '%s'),
'%s',
(SELECT 'sid' FROM '%s_servers' WHERE 'ip' = '%s' AND 'port' = '%s' LIMIT 0,1))"
DatabasePrefixIpAuthidName, (time*60), (time*60), ReasonDatabasePrefixAdminAuthidAdminIpDatabasePrefixServerIpServerPort) ; 

(The linebreaks are to add a tiny bit of readability ... but should be fine left in)

lomax 11-05-2007 15:06

Re: mathematical and SQL question
 
that means that i won't have any problems having SELECTS in VALUES section ?

purple_pixie 11-06-2007 06:44

Re: mathematical and SQL question
 
You shouldn't do ...

If you do then you'd have to run the sub-select queries first and save their output, and then pass that back into the INSERT query.

But it should be alright ... that's handled within SQL which should be fine with it.


All times are GMT -4. The time now is 01:16.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.