Problem with query

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

Moderators: Lapo, Bax

Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Problem with query

Postby Skills07 » 04 Apr 2017, 17:42

Hello lapo i open this thread because i have a problem on a query called server side

this my log

Code: Select all

04 apr 2017 | 19:43:11,116 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | STATE: WAIT_NEW_PACKET
04 apr 2017 | 19:43:11,119 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | NORMAL SIZED PACKET: 69
04 apr 2017 | 19:43:11,121 | DEBUG | SocketReader | protocol.binary.BinaryIoHandler |     | <<< PACKET COMPLETE >>>
04 apr 2017 | 19:43:11,122 | DEBUG | SFSWorker:Sys:4 | v2.protocol.SFSProtocolCodec |     |
   (sfs_object) p:
      (sfs_object) p:
         (utf_string) username: pluto1
         
      
      (int) r: 2
      (utf_string) c: userdetail
      
   
   (short) a: 13
   (byte) c: 1
   

04 apr 2017 | 19:43:11,141 | DEBUG | SFSWorker:Ext:2 | controllers.v290.ExtensionReqController |     | [Req Type: (Tcp), Sender: { Id: 1, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:55301 }]
04 apr 2017 | 19:43:11,146 | DEBUG | SFSWorker:Ext:2 | controllers.v290.ExtensionReqController |     |
   (sfs_object) p:
      (utf_string) username: pluto1
      
   
   (int) r: 2
   (utf_string) c: userdetail
   

04 apr 2017 | 19:43:11,155 | INFO  | SFSWorker:Ext:2 | Extensions |     | {Server}: Sto richiedendo al server i dettagli di uno user
04 apr 2017 | 19:43:11,158 | INFO  | SFSWorker:Ext:2 | Extensions |     | {Server}: Ho fatto l'accesso per richiedere al server la mia query
04 apr 2017 | 19:43:11,163 | DEBUG | SFSWorker:Ext:2 | v2.db.SFSDBManager |     | Execute Query SQL: com.mysql.jdbc.JDBC42PreparedStatement@575ee75d: select * from users where username = 'pluto1'
04 apr 2017 | 19:43:11,184 | INFO  | SFSWorker:Ext:2 | Extensions |     | {Server}: vediamo cosa contiene l'array[SFSObject, size: 0]
04 apr 2017 | 19:43:11,186 | DEBUG | SFSWorker:Ext:2 | v2.protocol.SFSProtocolCodec |     | {OUT}: CallExtension
04 apr 2017 | 19:43:11,189 | DEBUG | SFSWorker:Ext:2 | protocol.binary.BinaryIoHandler |     | Binary size: 71
12 00 03 00 01 70 12 00 03 00 01 70 12 00 01 00    .....p.....p....
05 65 72 72 6F 72 08 00 0B 4D 79 53 51 4C 20 65    .error...MySQL.e
72 72 6F 72 00 01 72 04 00 00 00 02 00 01 63 08    rror..r.......c.
00 0A 75 73 65 72 64 65 74 61 69 6C 00 01 61 03    ..userdetail..a.
00 0D 00 01 63 02 01                               ....c..         

04 apr 2017 | 19:43:11,189 | DEBUG | SFSWorker:Ext:2 | controllers.v290.ExtensionReqController |     | Extension call executed in: 43.996491
04 apr 2017 | 19:44:53,323 | INFO  | SocketReader | bitswarm.sessions.DefaultSessionManager |     | Session removed: { Id: 1, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:55301 }
04 apr 2017 | 19:44:53,324 | DEBUG | SFSWorker:Sys:3 | entities.managers.SFSRoomManager |     | User: chry removed from Room: The Lobby
04 apr 2017 | 19:44:53,326 | DEBUG | SFSWorker:Ext:4 | v2.buddylist.SFSBuddyListManager |     | Skipping BuddyList save request. No BuddyList available for: chry
04 apr 2017 | 19:44:53,326 | INFO  | SFSWorker:Sys:3 | v2.api.SFSApi |     | User disconnected: { Zone: Login }, ( User Name: chry, Id: 0, Priv: 0, Sess: 127.0.0.1:55301 ) , SessionLen: 107261, Type: Unity


then here my code server-side

Code: Select all

public class UserDetailHandler extends BaseClientRequestHandler{


   Object obj = null;
   public void handleClientRequest(User user, ISFSObject params) {
      //int id_user = params.getInt("user_id");
      String username = params.getUtfString("username");
      trace("Sto richiedendo al server i dettagli di uno user");
      
      IDBManager dbmanager = getParentExtension().getParentZone().getDBManager();
      
      try{
         trace("Ho fatto l'accesso per richiedere al server la mia query");
         ISFSArray arr = dbmanager.executeQuery("select * from users "
               + "where username = ? "
               , new Object[] {username});
         if (arr.size() > 0)
         {
           SFSObject result = new SFSObject();
           result.putSFSArray("success", arr);
           send("userdetail", result, user);
         }
         
      }catch (SQLException ex) {
         ISFSObject error = new SFSObject();
         trace("vediamo cosa contiene l'array" + error.toString());
         error.putUtfString("error", "MySQL error");
         send("userdetail" , error, user);
   }
      }
}



the consolle print mysql error but is not correct in my database i have one record and if i copy the query on mysql workbench i have this

Code: Select all

SELECT * FROM Users WHERE username = 'pluto1'


i have this

Code: Select all

   3   pluto   disney   0000-00-00 00:00:00   pluto1   123456   pippo3@mail.it   3000   100   3000   germany   sdafda


why my code doesn't work??

i have done this method to all my queries and the other one works
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Problem with query

Postby Lapo » 05 Apr 2017, 07:42

In your code you have users, in your mysql test you have Users with a capital "U"
Depending if you run on Windows, Linux or Mac this may be a problem. Always make sure to use the exact name of the table.

cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Problem with query

Postby Skills07 » 05 Apr 2017, 07:57

We're working on windows.

you think if i write users at the same place of Users i can do my result??

I try and then i post the result.

Thanks for your help
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Problem with query

Postby Skills07 » 05 Apr 2017, 08:16

Lapo i have setted the name of the db and the table

Code: Select all

public class UserDetailHandler extends BaseClientRequestHandler{


   Object obj = null;
   public void handleClientRequest(User user, ISFSObject params) {
      //int id_user = params.getInt("user_id");
      String username = params.getUtfString("username");
      trace("Sto richiedendo al server i dettagli di uno user");
      
      IDBManager dbmanager = getParentExtension().getParentZone().getDBManager();
      
      try{
         trace("Ho fatto l'accesso per richiedere al server la mia query");
         ISFSArray arr = dbmanager.executeQuery("select * from guesswho.users "
               + "where username = ? "
               , new Object[] {username});
         if (arr.size() > 0)
         {
           SFSObject result = new SFSObject();
           result.putSFSArray("success", arr);
           send("userdetail", result, user);
         }
         
      }catch (SQLException ex) {
         ISFSObject error = new SFSObject();
         trace("vediamo cosa contiene l'array" + error.toString());
         error.putUtfString("error", "MySQL error");
         send("userdetail" , error, user);
   }
      }
}


if i write the query in mysql with capital letters or none i have the same result.

How can i solve??
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Problem with query

Postby Skills07 » 06 Apr 2017, 08:30

I have tried to rewrite the code,

all the queries works than this.

in mysql in windows 10, if i write the query in this mode

"SELECT * FROM USERS WHERE USERNAME = 'Pluto1' "

or this

"Select * from Users where username = 'Pluto1' "

or this

"Select * from guesswho.users where username = 'Pluto1' "

all the queries works and i have my record.

Why in smartfox server with mycode i have that the SFSArray.size is 0 with this query??
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Problem with query

Postby Lapo » 06 Apr 2017, 09:42

A good way to know is to print out all the details of the SQL exception.

In your code:

Code: Select all

catch (SQLException ex)
{
   ...
  ex.printStackTrace();
}

This will show all the details in the console.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
Skills07
Posts: 103
Joined: 07 Nov 2016, 14:54
Location: Italy

Re: Problem with query

Postby Skills07 » 06 Apr 2017, 10:13

Solved

this user is a kind of test.

It has a birthdate like 0000-00-00 00:00:00

it this that gives error

Thanks Lapo

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 66 guests