aaron3481 / assql

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

Add Responders #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Add responder's to statement to connection / statement to improve usability.

Example:

{{{
var st:Statement = con.createStatement();
st.executeQuery("SELECT * FROM users", new MySqlResponder(resultHandler,
errorHandler);
}}}

or:

{{{
var st:Statement = con.createStatement();
st.executeQuery("SELECT * FROM users", new MySqlResponder(
   function (e:MySqlEvent) {
      //handle result here
   },
   function (e:MySqlErrorEvent) {
      //handle error here
   }
);
}}}

Original issue reported on code.google.com by macl...@gmail.com on 12 May 2008 at 9:49

GoogleCodeExporter commented 9 years ago
Please ignore the {{{ / }}}, I was trying to get code blocks to show up:

---

var st:Statement = con.createStatement();
st.executeQuery("SELECT * FROM users", new MySqlResponder(resultHandler,
errorHandler);

or:

var st:Statement = con.createStatement();
st.executeQuery("SELECT * FROM users", new MySqlResponder(
   function (e:MySqlEvent) {
      //handle result here
   },
   function (e:MySqlErrorEvent) {
      //handle error here
   }
);

Original comment by macl...@gmail.com on 12 May 2008 at 9:51

GoogleCodeExporter commented 9 years ago

Original comment by macl...@gmail.com on 12 May 2008 at 10:39

GoogleCodeExporter commented 9 years ago
Hi,

Is it possible that the responders aren't correctly working yet?
I guess the error/response/result responders are never called...
Here is my code as it is also in the examples:

-----------------------------------------

var st:Statement = con.createStatement();
st.executeQuery("select id from test", new MySqlResponser(
    function (e:MySqlEvent):void 
    {
        var rs:ResultSet = e.resultSet;
        trace(rs.size());
        Alert.show("Returned: " + e.resultSet.getNumber("id"));
    },
    function (e:MySqlErrorEvent):void
    {
        trace("Error: " + e.text);
        Alert.show("Error: " + e.text);
    }
));

-----------------------------------------

I also tried with faulty query so I would get an MySqlErrorEvent, but nothing 
ever 
happens.

I tried debugging in flex, but the console stays empty. I tried the swc file 
and the 
project-files, but same problem with both. I also tried getting the latest 
files 
from the svn, but no luck...

Original comment by davy.mo...@gmail.com on 14 May 2008 at 3:52

GoogleCodeExporter commented 9 years ago
I took you code and changed the table name and it work no problem. The only 
issue is
that you need to call rs.next() before reading a value from the result set.

example:

if ( rs.next() ) {
   Alert.show("Returned: " + e.resultSet.getNumber("id"));
}

Original comment by macl...@gmail.com on 14 May 2008 at 4:18

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Ok sorry for that, but the thing is that I should get at least a trace...

function (e:MySqlEvent):void 
{
        trace('ok');
    var rs:ResultSet = e.resultSet;
        trace(rs.size());
        Alert.show("Returned: " + e.resultSet.getNumber("id"));
}

I'm using Flex 3 and [ServerInformation] Version: 5.0.37-standard is btw. I 
don't 
even get the 'ok' in the debug-console, I tried it with the latest code you 
posted 
in your latest comment, but again no luck. I double checked the query to make 
sure 
table and fields were ok, and all are fine. I get nowhere a trace, nor in the 
responseHandler, nor in the errorHandler. There query is executed though. It's 
just 
the events which doesn't seem to be caught?

I've added in the file Statement.as on line 31 & 40 a trace('ok'); so when the 
handleResponse or the handleError function is called, but again this trace is 
never 
shown, so that explains why the responder functions are never called.
So I guess the problem lies within:

this.addEventListener(MySqlEvent.RESPONSE, handleResponse);
this.addEventListener(MySqlEvent.RESULT, handleResponse);
this.addEventListener(MySqlErrorEvent.SQL_ERROR, handleError);

I guess these events are not dispatched somehow.

Then I added trace('handled'); to handleNextPacket() in QueryHandler.as, and it 
seems that this function is never called too... so that explains why the events 
are 
never dispatched.

My search ended in DataHandler.as, where there is:

/**
 * Called by the Connection and adds a new/recieved packet to
 * the array of packets that need be handled.
**/
public function pushPacket(packet:Packet):void
{
    packets.push(packet);
    newPacket();
}

The last place where I get a trace when a query is executed is in this 
function... 
So this works:

public function pushPacket(packet:Packet):void
{
    trace('ok');
    packets.push(packet);
    newPacket();
}

but whenever I add a trace to the "protected function newPacket():void", nor in 
DataHandler (which is obvious, since it's overridden), nor in QueryHandler.as

Any idea what more I can do in order to find where the issue is located?
Thanks in advance!

Original comment by davy.mo...@gmail.com on 15 May 2008 at 9:23

GoogleCodeExporter commented 9 years ago
I am really not sure what is going on for you. If you checkout the source code 
from
subversion I have added detailed logging to the classes. Before you connection 
you
can set the logging level to all by doing this:

Logger.level = Logger.ALL;

It should then pretty much print out every step that is occurring. If you could 
post
that information here I can try and help you out some more and track this nasty
little bug down!

Thanks

Original comment by macl...@gmail.com on 15 May 2008 at 2:05

GoogleCodeExporter commented 9 years ago
Hi, thanks for the quick reply. Here is the trace result:

[ALL] com.maclema.mysql::Connection                : Set Data Handler To: 
com.maclema.mysql::HandshakeHandler
[ALL] com.maclema.mysql::Connection                : Socket Connected
[ALL] com.maclema.mysql::Connection                : Socket Data (65 bytes)
[ALL] com.maclema.mysql::HandshakeHandler          : Push Packet (Total 
Packets: 0)
[ALL] com.maclema.mysql::HandshakeHandler          : Server Information Packet
[ALL] com.maclema.mysql::HandshakeHandler          : Next Packet
[ALL] com.maclema.mysql::ServerInformation         : Version: 5.0.37-standard
[ALL] com.maclema.mysql::HandshakeHandler          : doHandshake
[ALL] com.maclema.mysql::HandshakeHandler          : doSecureAuthentication
[ALL] com.maclema.mysql::Connection                : Socket Data (11 bytes)
[ALL] com.maclema.mysql::HandshakeHandler          : Push Packet (Total 
Packets: 0)
[ALL] com.maclema.mysql::HandshakeHandler          : Next Packet
[ALL] com.maclema.mysql::HandshakeHandler          : Success Packet
[ALL] com.maclema.mysql::Connection                : Change Database 
(codeit_airlive_rentajewel)
[ALL] com.maclema.mysql::Connection                : Socket Data (11 bytes)
[ALL] com.maclema.mysql::HandshakeHandler          : Push Packet (Total 
Packets: 0)
[ALL] com.maclema.mysql::HandshakeHandler          : Next Packet
[ALL] com.maclema.mysql::HandshakeHandler          : Connect With DB Success 
Packet
[ALL] com.maclema.mysql::Connection                : Unregistered Data Handler
[ALL] com.maclema.mysql::Connection                : Connected
[ALL] com.maclema.mysql::Statement                 : executeQuery
[ALL] com.maclema.mysql::Statement                 : executing a regular 
statement
[ALL] com.maclema.mysql::Connection                : Execute Query (update 
revision 
set revision = revision+1, lastupdate=now())
[ALL] com.maclema.mysql::Connection                : Set Data Handler To: 
com.maclema.mysql::QueryHandler
[ALL] com.maclema.mysql::Statement                 : executeQuery
[ALL] com.maclema.mysql::Statement                 : executing a regular 
statement
[ALL] com.maclema.mysql::Connection                : Execute Query (select 
revision 
from revision)
[ALL] com.maclema.mysql::Connection                : Set Data Handler To: 
com.maclema.mysql::QueryHandler
[ALL] com.maclema.mysql::Connection                : Disconnected

I've added a little trace to QueryHandler.as -> handleNextPacket(), but this is 
not 
giving any result. I saw that Logger.info(this, "New Packet"); was never called 
(see 
trace also), so it's normal that the trace hasn't been called.
I hope this helps you out.

Original comment by davy.mo...@gmail.com on 15 May 2008 at 2:36

GoogleCodeExporter commented 9 years ago
hmm, thats really strange, it looks like the connection is closing before the 
query
is executed.

Is your connection variable at a global scope?

Good:

private var con:Connection;

private function connect():void {
  con = new Connection(...);
  ...
}

Bad:

private function connect():void {
   var con:Connection = new Connection(...);
}

It is also strange that this line never gets traced: (inside 
Connection.onSocketClose)

Logger.info(this, "Socket Closed (Expected: " + expectingClose +")");

You aren't by chance calling disconnect() somehow at the same time as 
executeQuery?
Maybe put a trace inside Connection.disconnect.

Other than that it almost looks like MySQL is closing the socket for some 
reason. I
have seen this behavior sometimes when authentication fails, but your handshake 
is
succeeding fine, and the switch database call is also working.

Original comment by macl...@gmail.com on 15 May 2008 at 3:07

GoogleCodeExporter commented 9 years ago
Opened in new Issue. Issue #12

Original comment by macl...@gmail.com on 15 May 2008 at 3:11