lecosson / assql

Automatically exported from code.google.com/p/assql
0 stars 0 forks source link

ResultSet.getRows does not list the first row #50

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Execute a statement and get a ResultSet back in the data Object
2. var results:ArrayCollection = resultSet.getRows();
3. notice that results.getItemAt(0); is actually row 1 instead of row 0
   Also notice that resultSet.numColumns is 1 less than it should be

What is the expected output? What do you see instead?
getItemAt(0) should return the first row, not the second
resultSet.numColumns should return the number of columns, not the index of
the last column

What version of the product are you using? On what operating system?
ASSQL Beta 2.6 

Original issue reported on code.google.com by will.per...@gmail.com on 21 Jun 2008 at 12:10

GoogleCodeExporter commented 9 years ago
I cannot seem to reproduce this issue. Is there anything else I could possibly 
try to
reproduce this.

What types of columns are you selecting (int, blob etc)?

Thanks,

Matt

Original comment by macl...@gmail.com on 22 Jun 2008 at 11:37

GoogleCodeExporter commented 9 years ago
I have a table named BeatMeUpTooAcct of size 2 containing columns:
name: tinytext
identity: varchar(32)   [this is a table index]
pass: tinytext
updated: timestamp
type: int(4)
levelPlays: int(32)

Code after doing the DB connection:

connection.addEventListener(Event.CONNECT, function (e:Event):void {
   var st:Statement = connection.createStatement();        
   var token:MySqlToken = st.executeQuery("SELECT name, levelPlays FROM
BeatMeUpTooAcct");              
   token.dispatcher = dispatcher; // an EventDispatcher
   token.addResponder(new AsyncResponder(result, fault, token));
}); 

private static function result(data:Object, token:Object):void {            
  if (token.dispatcher) { // an EventDispatcher
    var event:MySQLEvent = new MySQLEvent();
    event.results = ResultSet(data);                
    token.dispatcher.dispatchEvent(event);              
  }
}

// the EventDispactcher handler:

eventDispatcher.addEventListener(Event.COMPLETE, function (e:MySQLEvent):void {
     var rs:ResultSet = e.results;              
     var row_num:uint = rs.numColumns; // this is off by 1
     var results:ArrayCollection = rs.getRows();
     var row:Object = results.getItemAt(0); // returns row 1 instead of row 0
     trace("returned: " + row.name + " " + row.levelPlays);
}

Original comment by will.per...@gmail.com on 22 Jun 2008 at 11:57

GoogleCodeExporter commented 9 years ago
Table entries:
row 0:  
name:  Will
identity: Will
pass: asd
updated: 2008-06-19 15:15:04
type: 0
levelPlays: 19

row 1:
name: GSilver
identity: GSilver
pass: void
updated: 1981-01-15 00:00:00
type: 0
levelPlays: 0

Original comment by will.per...@gmail.com on 23 Jun 2008 at 12:06

GoogleCodeExporter commented 9 years ago
ok, I created the same table as you and got a similar result.

here is my result handler:

function(data:Object, token:Object):void {
    var rs:ResultSet = ResultSet(data);
    var rows:ArrayCollection = rs.getRows();

    var row:Object = rows.getItemAt(0);

    Alert.show("Num Rows: " + rows.length + ", Cols: " + rs.numColumns + ", Row: " +
row.name + ", " + row.levelPlays);
}

---

rows.length is 2, and rows.getItemAt(0) is GSilver and rows.getItemAt(1) is 
Will.

I also ran the same query in MySql and GSilver also showed up first. 

I think the problem is that when using a text index, it will sort the records
alphabetically.

Do you also get two rows?

Original comment by macl...@gmail.com on 24 Jun 2008 at 4:14

GoogleCodeExporter commented 9 years ago
Sorry, my hosting service has disabled mysql remote access so I'm unable to 
test this
out anymore until I get my VPS working.  I did run the mysql query directly from
phpmyadmin however and it returns the correct results.

Original comment by will.per...@gmail.com on 24 Jun 2008 at 5:56

GoogleCodeExporter commented 9 years ago
I have my VPS working now and am able to test this again.  The same result is
happening still.  
I reran the test with 4 rows in the table (the table has the same structure).
The names in the rows are:
Will
GSilver
Will2
Zack

then I do:
SELECT name, levelPlays FROM BeatMeUpToo

var rs:ResultSet = e.results;               
var row_num:uint = rs.numColumns;  // this returns 2 when it should be 4
var results:ArrayCollection = rs.getRows();

results.length = 3 when it should be 4
results.getItemAt(0) = GSilver
results.getItemAt(1) = Will2
results.getItemAt(2) = Zack

Original comment by will.per...@gmail.com on 28 Jun 2008 at 10:17

GoogleCodeExporter commented 9 years ago
One thing I noticed is that 2 of the table entries (GSilver & Zack) have default
'updated' timestamps.  This may be related.
When the entries were all created, I used:
INSERT INTO $db_acct (name, identity, type, pass, updated) VALUES('$v_name', 
'$v_id',
$v_type, '$v_p', '1981-01-15 00:00:00')

On 2 accounts I've done the following additionally:
UPDATE $db_acct SET updated=NULL WHERE $va_select

setting updated=NULL sets it to current timestamp

Original comment by will.per...@gmail.com on 28 Jun 2008 at 10:22

GoogleCodeExporter commented 9 years ago
I was browsing through the source and noticed this on ResultSet.as line 146:
index = rows.length;
shouldn't this be index = rows.length - 1; ?

Original comment by will.per...@gmail.com on 28 Jun 2008 at 11:51

GoogleCodeExporter commented 9 years ago
There is also in ResultSet:47 :
rs.map[String((i+1))] = i;
not sure if this should be i+1 or just i here

Original comment by will.per...@gmail.com on 28 Jun 2008 at 11:53

GoogleCodeExporter commented 9 years ago
Here is the SQL dump to create the tables exactly how I have them

Original comment by will.per...@gmail.com on 30 Jun 2008 at 6:55

Attachments:

GoogleCodeExporter commented 9 years ago
I used the sql dump provided, and I still get all 4 rows. What version of MySql 
are
you using?

As for the numColumns, that should be 2 because there is only 2 columns 
selected in
the statement.

The reason for "rs.map[String((i+1))] = i;" was more implemented for the 
purpose of
being similar to the java jdbc driver, which uses 1-based column numbers.

Original comment by macl...@gmail.com on 30 Jun 2008 at 7:27

GoogleCodeExporter commented 9 years ago
Oh sorry, got confused with the columns vs rows thing heh, numColumns is 
correct... I
should have been using rs.size() there.  I am still getting a disparity between
results.length and rs.size() though.
results.length = 3
rs.size() = 4
and the first row is chopped off still :-/

Original comment by will.per...@gmail.com on 30 Jun 2008 at 7:34

GoogleCodeExporter commented 9 years ago
Here is an example of the issue:

var results:ArrayCollection = rs.getRows();
for (var r:int= 0; r < rs.size(); r++) {
var row:Object = results.getItemAt(r);                      
trace("Num Rows: " + results.length + ", Row: " + row.name + ", " + 
row.levelPlays +
"num:" + r);
}

Original comment by will.per...@gmail.com on 30 Jun 2008 at 7:37

GoogleCodeExporter commented 9 years ago
I am still getting 4 rows.

With this:
function(data:Object, token:Object):void {
    var rs:ResultSet = ResultSet(data);
    Alert.show("Rows: " + rs.getRows().length + ", Len: " + rs.size());
}

I get: "Len: 4, Size: 4"

Original comment by macl...@gmail.com on 30 Jun 2008 at 10:46

GoogleCodeExporter commented 9 years ago
if you have the source, maybe trying changing the getRows() method in ResultSet 
to
the following:

public function getRows(dateTimesAsStrings:Boolean=false):ArrayCollection
{
    var st:Number = getTimer();

    var oldIndex:int = index;

    first();

    var arr:Array = new Array();
    while ( this.next() ) {
        var obj:Object = new Object();

        columns.forEach(function(c:Field, index:int, arr:Array):void {
            obj[c.getName()] = getCastedValue(c, dateTimesAsStrings);
        });

        arr.push(obj);
    }

    index = oldIndex;

    var run:Number = getTimer()-st;
    Logger.debug(this, "getRows() in " + run + " ms");
    return new ArrayCollection(arr);
}

Original comment by macl...@gmail.com on 30 Jun 2008 at 10:50

GoogleCodeExporter commented 9 years ago
Sorry, I meant this:

public function getRows(dateTimesAsStrings:Boolean=false):ArrayCollection
{
    var st:Number = getTimer();

    var oldIndex:int = index;

    index = -1;

    var arr:Array = new Array();
    while ( this.next() ) {
        var obj:Object = new Object();

        columns.forEach(function(c:Field, index:int, arr:Array):void {
            obj[c.getName()] = getCastedValue(c, dateTimesAsStrings);
        });

        arr.push(obj);
    }

    index = oldIndex;

    var run:Number = getTimer()-st;
    Logger.debug(this, "getRows() in " + run + " ms");
    return new ArrayCollection(arr);
}

Original comment by macl...@gmail.com on 30 Jun 2008 at 10:52

GoogleCodeExporter commented 9 years ago
Figured it out, calling rs.first() is causing the behavior to happen.  Not sure 
if
this is intended or not:

Alert.show("Rows: " + rs.getRows().length + ", Len: " + rs.size());
rs.first();
Alert.show("Rows: " + rs.getRows().length + ", Len: " + rs.size());

Original comment by will.per...@gmail.com on 30 Jun 2008 at 11:36

GoogleCodeExporter commented 9 years ago

Original comment by macl...@gmail.com on 15 Jul 2008 at 5:10