AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Problems with mysql table column (https://forums.alliedmods.net/showthread.php?t=325842)

l00ka 07-08-2020 12:58

Problems with mysql table column
 
2 Attachment(s)
Hello,

i got a small issue with a plugin.
The plugin works fine but it throws the following error all the time in the server console:

Quote:

07/08/2020 - 16:29:47: [deathrun_stats.amxx] SQL error: Incorrect datetime value: '' for column 'recorddate' at row 1
when I look into the specific table there is indeed in some rows a NULL value in the 'recorddate' column.

And when I look into the sql statements I see the following insert statment that made me suspicious:
HTML Code:

formatex(gszQuery, charsmax(gszQuery), "INSERT INTO `results` VALUES (%d, %d, 0, 1, 0, 0, NULL)", giPid[id], gMid);
as you might see the last parameter in the insert is the column with the datetime value NULL.

My question is, how do I get the current time in the datetime format and insert it here instead of NULL.

Hope someone can help me out. Thx.

UPDATE:
TLTR; I compiled with the old Init.inl file.
So the solution is to update the following line in the Init.inl insert statement and recompile with the updated Init.inl file.
Code:

formatex(gszQuery, charsmax(gszQuery), "INSERT INTO `results` VALUES (%d, %d, 0, 1, 0, 0, now())", giPid[id], gMid);

Natsheh 07-08-2020 13:47

Re: Problems with mysql table column
 
Show the SQL. Query of creating the table.

l00ka 07-08-2020 13:58

Re: Problems with mysql table column
 
Quote:

Originally Posted by Natsheh (Post 2709282)
Show the SQL. Query of creating the table.

HTML Code:

query = SQL_PrepareQuery(link,
                "CREATE TABLE IF NOT EXISTS `results`( \
                        id                INT(11)                UNSIGNED, \
                        mid                INT(11)        UNSIGNED, \
                        besttime        INT(11)        NOT NULL, \
                        games                INT(11)        NOT NULL, \
                        playedtime        INT(11)                NOT NULL,        \
                        deaths                INT(11)                NOT NULL,        \
                        FOREIGN KEY(id) REFERENCES `runners`(id) ON DELETE CASCADE, \
                        FOREIGN KEY(mid) REFERENCES `maps`(mid) ON DELETE CASCADE, \
                        PRIMARY KEY(id, mid) \
                )");
        SQL_Execute(query);
        SQL_FreeHandle(query);
       
        query = SQL_PrepareQuery(link,
                "ALTER TABLE `results` \
                ADD        recorddate        DATETIME        NULL");
               
        SQL_Execute(query);
        SQL_FreeHandle(query);


JocAnis 07-08-2020 18:53

Re: Problems with mysql table column
 
Try with 'now()' on the exact place where is 'null' inserted

l00ka 07-09-2020 12:53

Re: Problems with mysql table column
 
Quote:

Originally Posted by JocAnis (Post 2709325)
Try with 'now()' on the exact place where is 'null' inserted

This is not working.

I also tried setting directly the value with a timestring.

HTML Code:

formatex(gszQuery, charsmax(gszQuery), "INSERT INTO `results` VALUES (%d, %d, 0, 1, 0, 0,'2029-01-01 23:59:59')", giPid[id], gMid);
SQL_ThreadQuery(gTuple, "handleStandard", gszQuery);

but this also doesn't work...


All times are GMT -4. The time now is 17:12.

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