You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by dw1970 <dw...@gmail.com> on 2021/02/13 04:18:29 UTC

How to return the primary key sequence number after MySQL insert

I am using flex builder 4 to write actionscript to insert a row to a table.
The table has a primary key, say iddCourse with AUTO_INCREMENT. In FB4, I
used to have dataservice PHP to insert row and it will return the sequence
number of the newly created row, ie the generated number stored in
iddCourse. For example before insert, the last sequence number recorded in
iddCourse is 179, the newly created row will have the iddCourse as 180. And,
I am able to get this number 180 through the ResultEvent. The actual code is
as follow:

protected function createCourseHere(event:ResultEvent):void
    {
        rspCreateCourse.token = svcCourse.createCourse(voCourseSaved);
        rspCreateCourse.addEventListener(ResultEvent.RESULT,
onRspCreateCourse);
    }
    
    protected function onRspCreateCourse(event:ResultEvent):void
    {   
        rspCreateCourse.removeEventListener(ResultEvent.RESULT,
onRspCreateCourse);
        voCourseSaved.iddCourse = event.result as int;
        acCourse.addItem(voCourseSaved);
        acCourse = UtilArray.sortAc1(acCourse, "txtCourseCodeE", "S", "A");
        UtilMessage.sendMessage("Course created");
    }

You can see that I use event.result as int to find out the sequence number
of the newly created row. Recently, I changed the data service to
HTTPService instead of PHP (using ZendAMF). And now, the event.result turns
out to be blank, hence unable for me to find out the latest sequence number
created. Of course, I can be make another trip to the server to get the
newly created row by some other key and find out the sequence number, but I
don't to do so. Is there any way to find out the newly created primary key
sequence number by HTTPService Data Service in actionscript from the
ResultEvent?



--
Sent from: http://apache-flex-users.2333346.n4.nabble.com/