SFS2X & mySQL

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

MaxHammer
Posts: 9
Joined: 07 Jul 2010, 23:37
Location: Kingston, Ontario, Canada
Contact:

SFS2X & mySQL

Postby MaxHammer » 11 Sep 2011, 04:26

Im using Unity 3.3, mySQL and SFS2X.

I'd like to view the results of a simple database query. The query is simply returning the record count of a table.

The following is my server-side extension:

Code: Select all

   public void handleClientRequest(User player, ISFSObject params)
   {
      IDBManager dbManager = getParentExtension().getParentZone().getDBManager();
      String sql = "SELECT COUNT(*) AS CNT FROM PLANET";
      
      try
        {
         // Obtain a resultset
           ISFSArray res = dbManager.executeQuery(sql);
          
           // Populate the response parameters
           ISFSObject response = new SFSObject();
           response.putSFSArray("count", res);
          
           // Send back to requester
           send("planetCount", response, player);
        }


The following is my Response Handler in Unity (C#):

Code: Select all


   private void OnExtensionResponse(BaseEvent evt) {
      try {
         Debug.Log("Start of Try");
         string cmd = (string)evt.Params["cmd"];
         ISFSObject dt = (SFSObject)evt.Params["params"];
if (cmd=="planetCount")
         {
            Debug.Log("Received Response from Server");
            int id = dt.GetInt("count");
            Debug.Log("Planet count is " + id.ToString());
         }



The error thrown is that it cannot convert the type to Int.

So I assume that the issue is because ISFSArray is being passed and I'm treating it as an int... How would I expose the value being passed? I looked at all the examples I could get my hands on and they all use GetInt() to receive passed data from a database.

Any help would be greatly appriciated.

MaxHammer
MaxHammer
Posts: 9
Joined: 07 Jul 2010, 23:37
Location: Kingston, Ontario, Canada
Contact:

Postby MaxHammer » 20 Sep 2011, 00:02

Solved - all it took was a crash course on SFSObject and SFSArray.

There wasn't actually only one error - there were many problems with the code...

If anyone has a similar issue please pm me and I'll post code.

MaxHammer
JimmiQR
Posts: 39
Joined: 03 Jan 2009, 01:08
Location: Boston, Massachusetts, United States of America
Contact:

Re: SFS2X & mySQL

Postby JimmiQR » 14 Feb 2013, 01:42

(in case others are reading about this issue)

I am not sure, but I think the issue is COUNT(*) actually returns as a long, not an int, from the Database. If you do dt.GetLong("count").intValue(), (or just keep it as a long) then you will have better luck, at least I did.
User avatar
Lapo
Site Admin
Posts: 21347
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFS2X & mySQL

Postby Lapo » 14 Feb 2013, 08:29

A simple way to see what's returned in the SFSObject is to trace its whole content.

Code: Select all

trace(sfsObj.getDump())
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 9 guests