is RAW String or an Object?

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

Moderators: Lapo, Bax

agrios
Posts: 18
Joined: 20 Oct 2010, 20:42

is RAW String or an Object?

Postby agrios » 12 Dec 2010, 19:33

I am trying to write Java extension to handle H2 database in RAW:

Code: Select all


 ArrayList queryRes = db.executeQuery(sql);

        // If data exist...
        if (queryRes != null && queryRes.size() > 0)
        {
            // Cycle through all rows of data
            for (int i = 0; i < queryRes.size(); i++)
            {
                // Get a row of data
                DataRow row = (DataRow) queryRes.get(i);

               String resp[] = new String[2];

                // Add data to the RAW string or there is RAW object?
               resp[0] = row.getItem("username");
               resp[1] = row.getItem("password");
               resp[2] = row.getItem("registration");
                     
                trace("RAW DB processing row #" +i);
            }

            // Prepare response for the client
       String[] response = {"_db", resp};//this is not working!
            // Prepare a list of recipients and put the user that requested the command
              LinkedList recipients = new LinkedList();
              recipients.add(u.getChannel());
            // Send data to client
            sendResponse(response, fromRoom, u, recipients);



But returns nothing.
When can I see examples of using RAW strings in Java server side extensions? :roll:
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 12 Dec 2010, 22:05

RAW message is an array of strings.

Also

Code: Select all

String resp[] = new String[2];


Should be

Code: Select all

String[] resp = new String[2];


Furthermore, the first element of the resp array should be the command. In your case, it would be "_db". Then you use the resp array for the first parameter of the sendResponse method.
Smartfox's forum is my daily newspaper.
agrios
Posts: 18
Joined: 20 Oct 2010, 20:42

Postby agrios » 13 Dec 2010, 01:44

A O.K. then, it makes sense now.

Code: Select all


        String sql = "SELECT * FROM USERS ORDER BY USERNAME";
        ArrayList queryRes = db.executeQuery(sql);
        String[] resp = new String[4];

if (queryRes != null && queryRes.size() > 0)
     {
            // Cycle through all rows of data
            for (int i = 0; i < queryRes.size(); i++)
            {
                // Get a row of data
                DataRow row = (DataRow) queryRes.get(i);

                // Add data to the RAW array
               resp[0] = ("_db");
               resp[1] = row.getItem("USERNAME");
               resp[2] = row.getItem("PASSWORD");
               resp[3] = row.getItem("REGISTRATION");

            }

           
             LinkedList<SocketChannel> recipients=new LinkedList<SocketChannel>();
              recipients.add(u.getChannel());
            // Send data to client
            sendResponse(resp, fromRoom, u, recipients);
}


last row from this query is returning RAW:
_db%-1%row23username%row23password%row23registration

how do I get this -1?
User avatar
BigFIsh
Posts: 1698
Joined: 25 Feb 2008, 19:26
Location: New Zealand

Postby BigFIsh » 13 Dec 2010, 02:06

It's the fromRoom, and it will always be the second element of the receiving array.
Smartfox's forum is my daily newspaper.
agrios
Posts: 18
Joined: 20 Oct 2010, 20:42

Postby agrios » 13 Dec 2010, 02:49

I was expecting fromRoom o be after data.
I am not in the room as yet that's why is returning minus value right?

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 18 guests