Registered User Counts and String (SQLite)
#1

Hello again,
In my previous topic, i didn't check the code correctly that's why it's not working.
But now, I check it first before getting help in Scripting Help.

But it still don't save.

LastOn and LastTime in the database doesn't save. It always saves as null causing the server to crash everytime the server tries to display a dialog with the LastOn, LastTime (Causes the crash) and loads the GameTime (loads correctly).

Also i've question, How do i check how many registered users are in the server? For example a registered users register.
It will show something like this

"Jake_Hero(0) has registered the server making the server to have 2 registered players"

This is how i count the userid (automatically no var)

Код:
`userid` INTEGER PRIMARY KEY AUTOINCREMENT
And about the LastOn and LastTime null problem. Here's the code

pawn Код:
new y, m, d;
new hs, ms, ss;
gettime(hs, ms, ss);
getdate(y, m, d);
new str[35],
    str2[35]
;
format(str, sizeof str, "%d-%d-%d", m, d, y);
format(str2, sizeof str2, "%d:%d:%d", hs, ms, ss);
format(Query, sizeof(Query),
"UPDATE `users` \
 SET `admin` = '%d', \
 `vip` = '%d', \
 `LastOn` = '%s', \
 `LastTime` = '%s', \
 `speedboost` = '%d', \
 `score` = '%d', \
 `money` = '%d', \
 `hours` = '%d', \
 `minutes` = '%d', \
 `seconds` = '%d', \
 `mb` = '%d', \
 `SaveSkin` = '%d' \
 `UseSkin` = '%d'\
 `kills` = '%d', \
 `deaths` = '%d', \
 `cookies` = '%d' \
 WHERE `username` = '%s'"
,
 User[playerid][Admin],
 User[playerid][VIP],
 DB_Escape(str),
 DB_Escape(str2),
 User[playerid][SBoost],
 GetPlayerScore(playerid),
 LastMoney[playerid],
 User[playerid][Hours],
 User[playerid][Minutes],
 User[playerid][Seconds],
 User[playerid][MB],
 User[playerid][SSkin],
 User[playerid][USkin],
 User[playerid][Kills],
 User[playerid][Deaths],
 User[playerid][Cookies],
 DB_Escape(GetName(playerid))
);
db_query(Database, Query);
Reply
#2

After the user registers, you can use COUNT() to get the new total of registered users. Here's a tutorial on it: http://www.techonthenet.com/sql/count.php

Also, what does
pawn Код:
DB_Escape(str);
print? Don't see a point in escaping this strings.


PS: Integers don't require ' '
Reply
#3

The LastOn and LastTime (getdate and gettime) works correctly.

Код:
[DEBUG] LastOn: 10-5-2013
[DEBUG] LastTIme: 17:29:31
But i don't understand why it saves as Null.
Reply
#4

Sorry to bump but BUMP.

The null problem annoys me, crashing me everytime i disconnect it saves as null and when the server tries to load it, i always crash
Reply
#5

Were LastOn and LastTime created as VARCHAR in the table?
Reply
#6

I'm guessing there's already a default function on SQLite that gets the Player's Last On and LastTime have you tried using the function
pawn Код:
NOW()
for more information click this link: http://www.w3schools.com/sql/sql_func_now.asp

EDIT: Have you tried using them? instead of gettime and getdate?

Quote from the website
Quote:

The NOW() Function
The NOW() function returns the current system date and time.

SQL NOW() Syntax

Reply
#7

Yes.

Код:
'LastOn' VARCHAR(30), 'LastTime' VARCHAR(30)
Reply
#8

Quote:
Originally Posted by pds2012
Посмотреть сообщение
I'm guessing there's already a default function on SQLite that gets the Player's Last On and LastTime have you tried using the function
pawn Код:
NOW()
for more information click this link: http://www.w3schools.com/sql/sql_func_now.asp

EDIT: Have you tried using them? instead of gettime and getdate?

Quote from the website
Sorry for double post.

How do i use this NOW() thing?
Reply
#9

Quote:
Originally Posted by _Jake_
Посмотреть сообщение
Yes.

Код:
'LastOn' VARCHAR(30), 'LastTime' VARCHAR(30)
That's wrong.

It should be either:
pawn Код:
`LastOn` VARCHAR(30), `LastTime` VARCHAR(30)
or

pawn Код:
LastOn VARCHAR(30), LastTime VARCHAR(30)
Reply
#10

Actually you can't use NOW() function while updating Player's information, you can only use NOW() function while inserting (While player is registering)

pawn Код:
/*new y, m, d;
new hs, ms, ss;
gettime(hs, ms, ss);
getdate(y, m, d);
new str[35],
    str2[35]
;
format(str, sizeof str, "%d-%d-%d", m, d, y);
format(str2, sizeof str2, "%d:%d:%d", hs, ms, ss);*/


format(Query, sizeof(Query),
"UPDATE `users` \
 SET `admin` = '%d', \
 `vip` = '%d', \
 `LastOn` = '%s', \
 `speedboost` = '%d', \
 `score` = '%d', \
 `money` = '%d', \
 `hours` = '%d', \
 `minutes` = '%d', \
 `seconds` = '%d', \
 `mb` = '%d', \
 `SaveSkin` = '%d' \
 `UseSkin` = '%d'\
 `kills` = '%d', \
 `deaths` = '%d', \
 `cookies` = '%d' \
 WHERE `username` = '%s'"
,
 User[playerid][Admin],
 User[playerid][VIP],
 GetTodaysDate(),
 User[playerid][SBoost],
 GetPlayerScore(playerid),
 LastMoney[playerid],
 User[playerid][Hours],
 User[playerid][Minutes],
 User[playerid][Seconds],
 User[playerid][MB],
 User[playerid][SSkin],
 User[playerid][USkin],
 User[playerid][Kills],
 User[playerid][Deaths],
 User[playerid][Cookies],
 DB_Escape(GetName(playerid))
);
db_query(Database, Query);

GetTodaysDate()
{
    new
        DateString[ 20+5 ], //+5 just to make sure that the string value is enough.
        Date[ 6 ]
    ;
            //Year      //Month     //Day
    getdate(Date[ 0 ], Date[ 1 ], Date[ 2 ]);
            //Hour      //Minutes   //Seconds
    gettime(Date[ 3 ], Date[ 4 ], Date[ 5 ]);
   
    format(DateString, sizeof (DateString), "%d/%d/%d %d:%d:%d", Date[ 2 ], Date[ 1 ], Date[ 0 ], Date[ 3 ], Date[ 4 ], Date[ 5 ]);
    return DateString;
}
EDIT:
Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
That's wrong.

It should be either:
pawn Код:
`LastOn` VARCHAR(30), `LastTime` VARCHAR(30)
or
pawn Код:
LastOn VARCHAR(30), LastTime VARCHAR(30)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)