insert query in server side extension...

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
sakthimani
Posts: 7
Joined: 12 Jul 2011, 13:07
Location: India

insert query in server side extension...

Post by sakthimani »

hi ,
i am new to sfs, try code to intereact with mysql database,
i have to insert the login user name into mysql database so,
in client side(flash AS2) i wrote this code:
smartfox.sendXtMessage("details","addData",resObj,"json");

server side:

function handleRequest(cmd, params, user, fromRoom) {
if (cmd == "getData") {
trace("retrive data");
empName = "SELECT user_name FROM logins";
var empRes = dbase.executeQuery(empName);
var response = {}
response._cmd = "getData"
response.db = []
if (empRes != null)
{
for (var i = 0; i < empRes.size(); i++)
{
var tempRow = empRes.get(i)
var item = {}

item.name = tempRow.getItem("user_name")

response.db.push( item )
}
}
else{
trace("DB Query failed")
}
_server.sendResponse(response, -1, null, [user])
}
else if(cmd == "addData"){
trace("Adding data");
adding = "INSERT INTO logins (user_name) VALUES ("
adding += "'" + _server.escapeQuotes(params.name) + "')";
var success = dbase.executeQuery(adding);
if (success)
{
var response = {}
response._cmd = "addData"
response.name = params.name

_server.sendResponse(response, -1, null, [user])
}
else {
trace("not inserted");
}
}
}

getData working fine but addData(insert query) shows error in log

when i try to inser the username "1258"
log error:

[ SEVERE ] [id: 12] (DbManager.executeQuery): DbManager error during query/result creation: INSERT INTO logins (user_name) VALUES ('1258')

and have doubt in the type of data used in sendXtMessage as "json" or "xml" or "str" for getData i am using "str" type it works fine while i am using "str" for addData nothing happen after trace("Adding data"); line in extension

anybody help me ..
thanks...
sakthimani.......
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Post by BigFIsh »

You'll need to use executeCommand method to execute UPDATE/INSERT/DELETE etc calls. executeQuery is used for the SELECT call.
Smartfox's forum is my daily newspaper.
sakthimani
Posts: 7
Joined: 12 Jul 2011, 13:07
Location: India

Post by sakthimani »

BigFIsh wrote:You'll need to use executeCommand method to execute UPDATE/INSERT/DELETE etc calls. executeQuery is used for the SELECT call.
oh no sorry for my blind view .. thanks BigFish
sakthimani.......
Post Reply