Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

GET LAST INSERTED RECORD

Avatar

Avatar
Level 1
ssmacwilliams
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile

Avatar
Level 1
ssmacwilliams
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
View profile
ssmacwilliams
Level 1

24-11-2008

I am fairly new to flex. So please bear with me no this
question.

I would like to get MYSQL ID of the last record I inserted.
MSQL has as function LAST_INSERT_ID() that is connection based and
will return the last id of the last inserted record. My thought was
in the function contained within the cfc to do 2 queries insert the
record and return the last id directly after (see below). However,
I don't know how I would read the results back into flex. I am
unsure how to write the event handler. Thanks



<cffunction name="insertUser" access="remote"
returntype="query" >

<cfargument name="SSN" required="false" type="string"
hint="SSN"/>

<cfargument name="FNAME" required="false" type="string"
hint="FNAME"/>

<cfargument name="LNAME" required="false" type="string"
hint="LNAME"/>

<cfargument name="CLIENTID" required="false"
type="string" hint="NEW CLIENTID"/>



<cfquery name="insUser" datasource="DBT">

INSERT INTO CLIENT (SSN, FNAME, LNAME) VALUES (

<cfqueryparam value="#ARGUMENTS.SSN#"
cfsqltype="CF_SQL_VARCHAR" maxlength="12"/>,

<cfqueryparam value="#ARGUMENTS.FNAME#"
cfsqltype="CF_SQL_VARCHAR" maxlength="20"/>,

<cfqueryparam value="#ARGUMENTS.LNAME#"
cfsqltype="CF_SQL_VARCHAR" maxlength="30"/>)

</cfquery>

<cfquery name="qRead" datasource="DBT">

SELECT last_insert_id() AS CLIENTID

</cfquery>

<cfreturn qRead >

</cffunction>

Replies

Avatar

Avatar
Affirm 1
Level 2
Zee_Yang
Level 2

Likes

0 likes

Total Posts

29 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile

Avatar
Affirm 1
Level 2
Zee_Yang
Level 2

Likes

0 likes

Total Posts

29 posts

Correct Reply

1 solution
Top badges earned
Affirm 1
View profile
Zee_Yang
Level 2

24-11-2008

I assume you have LCDS installed with CF and you are using
the remote object service,



<mx:RemoteObject

id="myService"

destination="ColdFusion"

source="full.path.to.cfc"

showBusyCursor="true">

<mx:method name="insertUser"
result="insertUser_result(event)" />

</mx:RemoteObject>

...

<mx:Scrpit>

...

private function insertUser_result(event:ResultEvent) {

trace(event.result);

}



event.result will be the id of the newly inserted record.



BTW, I would highly recommend you looking into the data
management servcie. the SQLAssembler can spare you of the CF code
for simple CRUDs like this.