Page 1 of 1
result set index fragmentation problem
Posted: 27 Mar 2007, 23:22
by anandkanatt
Hi all,
I am stuck with an interesting problem;
STEP 1. I query 81 rows from DB
STEP2. I get the query done properly
STEP3. I send the result object back to the called extention.
STEP4. I get the result at client side.
Now when I print the Array which contains my 81 records i see that the order of the records has changed(at server end the order is proper). Why is this happening ?? is there a workaround ??
i could not notice any specific pattern for index fragmentation but all the time i run the application, same pattern of fragmentation occoured.
And i tried sorting but it dint seem working on my array i used both sort and sortOn methods.
and to make things worser all my smaller result set queries are working properly.
Please help
Regards
Anand
Posted: 28 Mar 2007, 06:54
by anandkanatt
hey can any one guess why the code given below makes SFS hang ? and also makes the java.exe run as if its has some sort of memory leak ... going on drinking all my memory.
Code: Select all
//-------------------------------<getPlots>--------------------\\
if (cmd == "getPlots") {
//Initialising the response object.
var response = {};
//response object command executed trace.
response._cmd = "getPlots";
//response object result = false (Default).
response.ok = false;
//response object errmsg = Error Message if any.
response.errmsg = "";
//response object max block user count if any.
response.max = 0;
//checking if any relations exists with the player or not
sql = "CALL stp_lkdrm_getPlots("+params.idBlock+");";
var queryRes = dbase.executeQuery(sql);
//response object district database data
response.db = [];
if (queryRes.size() != 0) {
// Cycle through all records in the ResultSet
for (var i = 0; i<queryRes.size(); i++) {
// Get a record
var tempRow = queryRes.get(i);
// This object will hold the record data that we'll send to the client
var item = {};
var sTempPlotAddress = params.idDistrict+"."+params.idQuarter+"."+params.idZone+"."+params.idBlock+"."+tempRow.getItem("plot_id");
for (var i in roomList) {
//Checking if plot exists or not ... if yes then we get the usercount
if (roomList[i].getName() == sTempPlotAddress) {
// From the record object we can get each field value
item.name = tempRow.getItem("plot_name");
item.id = tempRow.getItem("plot_id");
item.ucount = roomList[i].getUserCount();
response.max += roomList[i].getUserCount();
//Checking if the user is in the plot .... if yes we need
//to set the inRoom Property to true to render the plot map accordingly
if (roomList[i].getId() == fromRoom) {
item.inRoom = true;
} else {
item.inRoom = false;
}
} else {
// From the record object we can get each field value
item.name = tempRow.getItem("plot_name");
item.id = tempRow.getItem("plot_id");
item.ucount = 0;
item.inRoom = false;
}
} response.db.push(item);
}
response.ok = true;
} else {
response.errmsg = "Could not get the list of plots !";
response.ok = false;
}
_server.sendResponse(response, -1, null, [user]);
//-------------------------------</getPlots>--------------------\\
This code is run in an extension at zone level. this code is connected with the 81 row problem because this is what is done to the queried rows in the extension.
What i am trying to achieve here is that, i have a list of rooms in my db and i query it from db; then i am checking if any room is already existing in server that match my room name/id ... if yes i want the object pushed into the response.db to have inRoom set to True.
Please help me with both problems of mine ....
Regards
Anand
Posted: 28 Mar 2007, 06:56
by Lapo
If you use indexed Arrays it should work without problems.
I suppose you're working in AS, server side?
Can you show the code that builds the array that is sent back?
Posted: 28 Mar 2007, 07:28
by anandkanatt
thanks for that quick reply lapo ..
The send post of mine contains the code that does the query and post processing in the extention.
Regards
Anand
Posted: 28 Mar 2007, 16:36
by anandkanatt
Hi Lapo ....
I got a partially working fix for my 1st problem ....
Code: Select all
aPlotList.sortOn("id", Array.NUMERIC | Array.DESCENDING);
by adding this sortOn with the above said parameters and casting my return datatype of id field to Number in client gave me the array almost perfect i.e i should have got rows in the order 1 to 81 but now i am getting
Code: Select all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
41
Notice the Row id 41 comming after 81 and also specifying the Array.DESCENDING in sort and getting the other way

I am confused too about this behaviour of the code ... as i said before i have type casted the value of id to Number ... so now i dont know whats making a problem now
can u give me some idea why or what is going wrong ??
Posted: 28 Mar 2007, 20:13
by Lapo

incredible
Try outputting the type of each index ( using
typeof() ) in the debug for loop
Just to make sure that "41" isn't a string
Posted: 28 Mar 2007, 22:02
by anandkanatt
guess what all indexes are numbers ....

now i am even more confused ....
Posted: 30 Mar 2007, 16:54
by Lapo
me too, it just looks like a simple AS problem
I will try to do an experiment when I have the time
Posted: 31 Mar 2007, 05:56
by anandkanatt
Lapo wrote:me too, it just looks like a simple AS problem
I will try to do an experiment when I have the time
Ok thanks Lapo
Regards
Anand
Posted: 04 Jun 2007, 17:45
by anandkanatt
any body got any idea how or why this problem occurs ??
to make the problems worse when i make the result set i.e row count to sort from 81 (ODD) to 64(EVEN) i am able to get all the values properly sorted!
Does this error has something to do with off by one bug (O BOB)??
http://en.wikipedia.org/wiki/Off-by-one_error
Or does sorting has to do with odd and even arrays??
please help
Regards
Anand