Author Topic: Database never updates [Sq-Lite]  (Read 2300 times)

Motley

  • Full Member
  • ***
  • Posts: 253
  • Karma: +32/-34
    • View Profile
Database never updates [Sq-Lite]
« on: August 01, 2016, 03:35:44 pm »
I'm not familiar with sq-lite but i really do not understand why it never updates.

Code: [Select]
function onUpdatePlayerAccount(player, statDB) {
          // format the update query
          local szquery = format( "UPDATE Stats SET Auto_Login=" + Auto_Login[  player.ID ] + ", Kills=" + Kills[  player.ID ] + ", Deaths=" + Deaths[  player.ID ] + ", Money=" + Money[  player.ID ] + ", Bank=" + Bank[  player.ID ] + ", Skin='" + player.Skin + ", Wanted_Level='" + player.WantedLevel + ", Health='" + player.Health + ", Armour='" + player.Armour + "' WHERE Name='" + player.Name + "'" );

          // execute the query
          ::sqlite_query( statDB, szquery );

          MessagePlayer("Done", player);//just a random test
}

Any guidance is appreciated.

Also I do not receive errors

Ankris

  • Full Member
  • ***
  • Posts: 110
  • Karma: +29/-44
    • View Profile
Re: Database never updates [Sq-Lite]
« Reply #1 on: August 01, 2016, 04:01:13 pm »
Code: [Select]
function onUpdatePlayerAccount(player, statDB) {
local szquery = "UPDATE Stats SET Auto_Login=" + Auto_Login[ player.ID ] + ", Kills=" + Kills[ player.ID ] + ", Deaths=" + Deaths[ player.ID ] + ", Money=" + Money[ player.ID ] + ", Bank=" + Bank[ player.ID ] + ", Skin=" + player.Skin + ", Wanted_Level=" + player.WantedLevel + ", Health=" + player.Health + ", Armour=" + player.Armour + " WHERE Name='" + player.Name + "'";
sqlite_query( statDB, szquery );

MessagePlayer("Done", player);
}

Motley

  • Full Member
  • ***
  • Posts: 253
  • Karma: +32/-34
    • View Profile
Re: Database never updates [Sq-Lite]
« Reply #2 on: August 01, 2016, 05:56:15 pm »
Works! Thank you!!

Are you able to describe what I did wrong? I see you removed th brackets making it more of a string, I would of never thought of doing so.  :D

Ankris

  • Full Member
  • ***
  • Posts: 110
  • Karma: +29/-44
    • View Profile
Re: Database never updates [Sq-Lite]
« Reply #3 on: August 01, 2016, 10:12:52 pm »
Format is only useful if you need replace or add something to a string, e.g:

"Around %i of my schoolmates were to %s"

- %i: integer
- %s: string
- %f: float

so: format("Around %i of my schoolmates were to %s", 30, "the party");

%i will be replaced with the integer 30 and %s with the string "the party"



You had a starting ' without finish it. For update a string you need to complete it, so: " Auto_Login='"+Auto_Login[player.ID]+"' ". In integers you don't need any '.

Motley

  • Full Member
  • ***
  • Posts: 253
  • Karma: +32/-34
    • View Profile
Re: Database never updates [Sq-Lite]
« Reply #4 on: August 01, 2016, 11:14:49 pm »
Thanks an awesome example I really was not expecting all of that kuddos  :D ;)

 

© Liberty Unleashed Team.