Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Cena on Jun 17, 2016, 10:12 AM

Title: Database
Post by: Cena on Jun 17, 2016, 10:12 AM
My db is'nt saving i tryed many things QuerySQL( sqliteDB, "UPDATE Accounts SET Cash='" + Cash + "', Bank='" + Bank + "', Kills='" + Kills + "', Deaths='" + Deaths + "', Level='" + Level + "', LastUsedIP='" + LastUsedIP + "' WHERE Name='" + player.Name + "' AND NameLower='" + player.Name.tolower() + "'" );

also tryed this in a function and in onPlayerPart but still not working :( . I tryed to execute this in db it is working there but in script it not working.... plz help
Title: Re: Database
Post by: . on Jun 17, 2016, 10:16 AM
Christ man. Who dafuq uses that many concatenations. Why cant you use functions like format() to make the query. Easier to spot the syntax errors.

Besides, the official plugin does not report query errors. Which means you must manually execute the query in a program that can locate the error or use an alternate (http://forum.vc-mp.org/?topic=420.0) SQLite plugin.

Either way. No one has the patience and time to look through all that crap to find your missing quote or comma. You dig this hole your self. Now you get out of it.

Integers in quotes? Who does that. (thankfully sqlite does implicit conversions).

QuerySQL(sqliteDB,
    format(@"UPDATE [Accounts] SET
        [Cash]=%i,
        [Bank]=%i,
        [Kills]=%i,
        [Deaths]=%i,
        [Level]=%i,
        [LastUsedIP]='%s'
        WHERE [Name]='%s' AND [NameLower]='%s';",
        Cash,
        Bank,
        Kills,
        Deaths,
        Level,
        LastUsedIP,
        player.Name,
        player.Name.tolower()
    )
);
Title: Re: Database
Post by: ysc3839 on Jun 17, 2016, 10:26 AM
Quote from: . on Jun 17, 2016, 10:16 AMChrist man. Who dafuq uses that many concatenations. Why cant you use functions like format() to make the query. Easier to spot the syntax errors.

Besides, the official plugin does not report query errors. Which means you must manually execute the query in a program that can locate the error or use an alternate (http://forum.vc-mp.org/?topic=420.0) SQLite plugin.

Either way. No one has the patience and time to look through all that crap to find your missing quote or comma. You dig this hole your self. Now you get out of it.

Integers in quotes? Who does that. (thankfully sqlite does implicit conversions).

QuerySQL(sqliteDB,
    format(@"UPDATE [Accounts] SET
        [Cash]=%i,
        [Bank]=%i,
        [Kills]=%i,
        [Deaths]=%i,
        [Level]=%i,
        [LastUsedIP]='%s'
        WHERE [Name]='%s' AND [NameLower]='%s';",
        Cash,
        Bank,
        Kills,
        Deaths,
        Level,
        LastUsedIP,
        player.Name,
        player.Name.tolower()
    )
);
I suggest use SQL bind, which can prevent SQL injection.
Title: Re: Database
Post by: . on Jun 17, 2016, 10:40 AM
Quote from: ysc3839 on Jun 17, 2016, 10:26 AMI suggest use SQL bind, which can prevent SQL injection.

That's what I use but unfortunately neither SQLite plugins have that functionality :D
Title: Re: Database
Post by: vito on Jun 17, 2016, 01:16 PM
Good point about injections in vc-mp... currently only way I know is remove any quotes symbols and backslashes.
Title: Re: Database
Post by: KAKAN on Jun 17, 2016, 01:41 PM
Quote from: vito on Jun 17, 2016, 01:16 PMGood point about injections in vc-mp... currently only way I know is remove any quotes symbols and backslashes.
escapeSQLString. Though, I believe you don't need this for an average VCMP player. They will just play, they don't have a intention to hax :D
Title: Re: Database
Post by: ysc3839 on Jun 17, 2016, 02:14 PM
Quote from: KAKAN on Jun 17, 2016, 01:41 PM
Quote from: vito on Jun 17, 2016, 01:16 PMGood point about injections in vc-mp... currently only way I know is remove any quotes symbols and backslashes.
escapeSQLString. Though, I believe you don't need this for an average VCMP player. They will just play, they don't have a intention to hax :D
escapeSQLString is OK. But SQL bind is more convenient.
Title: Re: Database
Post by: KAKAN on Jun 17, 2016, 04:15 PM
Quote from: ysc3839 on Jun 17, 2016, 02:14 PM
Quote from: KAKAN on Jun 17, 2016, 01:41 PM
Quote from: vito on Jun 17, 2016, 01:16 PMGood point about injections in vc-mp... currently only way I know is remove any quotes symbols and backslashes.
escapeSQLString. Though, I believe you don't need this for an average VCMP player. They will just play, they don't have a intention to hax :D
escapeSQLString is OK. But SQL bind is more convenient.
I don't even think that SQL Bind is needed for VCMP( unless SLC plays )
Title: Re: Database
Post by: ysc3839 on Jun 17, 2016, 04:25 PM
Quote from: KAKAN on Jun 17, 2016, 04:15 PM
Quote from: ysc3839 on Jun 17, 2016, 02:14 PM
Quote from: KAKAN on Jun 17, 2016, 01:41 PM
Quote from: vito on Jun 17, 2016, 01:16 PMGood point about injections in vc-mp... currently only way I know is remove any quotes symbols and backslashes.
escapeSQLString. Though, I believe you don't need this for an average VCMP player. They will just play, they don't have a intention to hax :D
escapeSQLString is OK. But SQL bind is more convenient.
I don't even think that SQL Bind is needed for VCMP( unless SLC plays )
I disagree. :(
Title: Re: Database
Post by: EK.IceFlake on Jun 18, 2016, 06:56 AM
Well...
I was playing on my server and it was a fresh install so I had to make me admin... I didn't want SQLite browser so I tried injecting the code... didn't work :(
I typed: /saveloc '; update players set level=24 where lower(name)='ext-d.crysta;blue';--
no luck :(
I didn't have any SQLite injection protection
Title: Re: Database
Post by: ysc3839 on Jun 18, 2016, 07:25 AM
Quote from: ext-d.CrystalBlue on Jun 18, 2016, 06:56 AMWell...
I was playing on my server and it was a fresh install so I had to make me admin... I didn't want SQLite browser so I tried injecting the code... didn't work :(
I typed: /saveloc '; update players set level=24 where lower(name)='ext-d.crysta;blue';--
no luck :(
I didn't have any SQLite injection protection
Show your /saveloc code.
Title: Re: Database
Post by: Thijn on Jun 18, 2016, 11:04 AM
And show your database structure.