DatabaseManager Object Server to Client?

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

Moderators: Lapo, Bax

Post Reply
BattleSpace
Posts: 41
Joined: 03 Oct 2005, 20:53
Location: Phoenix, AZ
Contact:

DatabaseManager Object Server to Client?

Post by BattleSpace »

Hello,

I'm using server-side script (actionscript) and executeQuery and return the results in the DatabaseManager object from mysql What I would like to do is build a dataProvider from these results and send it back down to the client to populate a datagrid but I don't think this can be done in AS1 on the server.

On the server, I can access the DatabaseManager object and get the field names from the query results just fine. When I try to pass this same object back to the client for processing, it appears the results are lost.

Is this possible or do I need to step through the DatabaseManager object on the server and build an array of the values... passing the array back down to the client?

What is the best approach for what I'm trying to achieve?

Regards,
Brent
BattleSpace
Posts: 41
Joined: 03 Oct 2005, 20:53
Location: Phoenix, AZ
Contact:

Re: DatabaseManager Object Server to Client?

Post by BattleSpace »

BattleSpace wrote: ... or do I need to step through the DatabaseManager object on the server and build an array of the values... passing the array back down to the client?
I should add that building an array of query results works but I'm just not sure it is the best solution.... or is it?

Any opinions?
Brent
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Post by patso »

Not quite sure if I understood you right but it seems that maybe be your problem is the same or similar to the one discussed here http://forums.smartfoxserver.com/viewtopic.php?t=1766.

About the approach you use - honestly don't know. I think it's good enough - it must something similar to that SFS does behind the scenes to send objects from server side extension to the clients(or I'm wrong).
BattleSpace
Posts: 41
Joined: 03 Oct 2005, 20:53
Location: Phoenix, AZ
Contact:

Post by BattleSpace »

Thanks for the response...

Yes, that thread is using the "populate array" solution that is working for me as well. I'm using XML and have no problem with the protocol.

My utltimate goal was to eliminate the "array" step and either go straight to a dataprovider (which doesn't seem possible in AS1) or send the query down to the client where it is possible to convert to a dataprovider because I'm using AS3.

Sending the query directly to the client will trace the same as on the server but once I step into it in a For loop like on the server nothing is there.

So instead of this:

sql query (server)
array (server)
dataprovider (client)

I wanted to do this:

sql query (server)
dataprovider (server) - send to client

or
sql query (server)
dataprovider (client)

I didn't think it would be necessary to add everything to an array first.

Regards,
Brent
patso
Posts: 380
Joined: 13 Nov 2006, 13:44
Location: Sofia, Bulgaria

Post by patso »

Hmm I take a quick look at the problem you have.

For me it seems that executeQuery returns ArrayList. And the array list internally stores the data as array. So you can get the array this way:

Code: Select all

var resultArray = result.toArray()
where result stores the result from calling executeQuery.

I'm sorry I don't have much experience(I don't have any) in using dbManager. So unfortunately that the only think I can help.

About the building data provider - I'm not sure what you mean but basically try to do as little things you can on the server side when this not affect the security and doesn't generate significant more bandwidth, because even if one operation cost little resources when you have 100 or 1000 user this can slow down the server.
BattleSpace
Posts: 41
Joined: 03 Oct 2005, 20:53
Location: Phoenix, AZ
Contact:

Post by BattleSpace »

Thanks for the response.

I'll look into that "toArray" method later this week and follow up here.

Thanks again,
Brent
BattleSpace
Posts: 41
Joined: 03 Oct 2005, 20:53
Location: Phoenix, AZ
Contact:

Post by BattleSpace »

I finally got around to revisit this issue and try the "toArray" on the results of the executeQuery on the server.

When I send the array back to the client and trace it I get:

[Ljava.lang.Object;@a53de4

With the portion beyond the ";" changing each time.

It isn't an array... but just a string. The only way I actually get this into an array is to step through the entire query results on the server and add them to an array... then send that to the client.

Oh well...
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

This is related with how the internal serializer works with native Actionscript objects and Java objects... to make a long story short it does not work with java arrays and expects native Actionscript arrays.

So, at the moment I'd recommend to build an AS array/object from the result set and send it to the client.

This is also suggesting new improvements to add to the next release: we'll add better support to java lists and arrays to simplify this process. :)
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply