Jump to content
  • 0

[SQL] Question regarding query_sql


Epsynus

Question


  • Group:  Members
  • Topic Count:  2
  • Topics Per Day:  0.00
  • Content Count:  4
  • Reputation:   1
  • Joined:  12/26/12
  • Last Seen:  

Alright people I am having some issues understanding the syntax for query_sql

what I am trying to achieve is to delete the character through a script, and the following are the ways I have tried doing it so far.

any help is appriciated and of course I will pay back to the community with my knowledge!

- script game_mechanics -1,{
OnPCDieEvent:
set #id,getcharid(0); //get their character ID
announce strcharinfo(0) +" was killed by "+ rid2name(killerrid),0xFFFF00;
atcommand "@kick "+#id;

//ways I have tried so far
//query_sql("DELETE FROM char WHERE char_id='"+escape_sql(#id)+"'");
//query_sql("DELETE FROM char WHERE char_id='"+getcharid(0)+"'");
query_sql("DELETE FROM 'char' WHERE 'char_id' = '"+getcharid(0)+"' ");

end;

//query_sql from other scripts to help me.
//query_sql("UPDATE `char` SET `pvp_exp` = `pvp_exp`+100 WHERE `char_id` = '"+getcharid(0)+"' ");
//query_sql ("DELETE FROM bountys WHERE name='"+escape_sql(@name2$)+"'");
//query_sql ("UPDATE bountyladder SET target3='"+@name$+"' WHERE char_id="+getcharid(0)+"");
}

all of them produces a simple error

[sql]: DB error - You have an error in your SQL syntax; check the manual that co
rresponds to your MySQL server version for the right syntax to use near ''char'
WHERE 'char_id' = '150000'' at line 1
[Debug]: at c:\kinbel\src\map\script.c:13127 - DELETE FROM 'char' WHERE 'char_id
' = '150000'
[Debug]: Source (NPC): game_mechanics (invisible/not on a map)

EDIT:

okay so I tried this new syntax and now I get a new error which I am not quite sure why I am getting it.

[sql]: DB error - Unknown column '150000' in 'where clause'
[Debug]: at c:\kinbel\src\map\script.c:13127 - DELETE FROM `char` WHERE `char_id
`=`150000`
[Debug]: Source (NPC): game_mechanics (invisible/not on a map)

The new syntax is

query_sql("DELETE FROM `char` WHERE `char_id`=`"+getcharid(0)+"` ");

EDIT2: I solved it... I feel very..very...very stupid.

Edited by Epsynus
Link to comment
Share on other sites

1 answer to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  75
  • Topics Per Day:  0.02
  • Content Count:  2223
  • Reputation:   593
  • Joined:  10/26/11
  • Last Seen:  

Glad you figured it out!

Yes, SQL column, table, and database names go in `backticks` (which are optional; only required if the column/table/database name is a MySQL keyword). Strings and values go in 'single quotes'.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...