[Freeswitch-users] dbh:query - insert id

S. Scott 8f27e956 at gmail.com
Sat May 25 20:50:38 MSD 2013


Where the running DB engine supports a stored procedure, it is
straightforward to implement the ID capture regardless of the connection
abstraction (e.g ODBC). Unfortunately, sqlite3 is stored procedures
challenged.

Try reading,

http://chriswolf.heroku.com/articles/2011/01/26/adding-stored-procedures-to-sqlite

I have used his prescription successfully once.



—————
iThing:  Big thumbs & little keys. Please excuse typo, spelling and grammar
errors • Thought of the Day – "With all this manure, there must be a pony
in here somewhere.”

On 2013-05-25, at 11:56, John M <j_mj at aol.com> wrote:

Hi Nathan,

Yes, generally the current connection can make a select query and get the
last inserted id and return that.

It's possible, as suggested by Daniel earlier that doing a subsequent query
for 'select last_insert_id()' may be the best way but that will be assuming
the db connection doesn't refresh as that could potentially return the last
inserted id of a concurrent channel.

For me, I have implemented a solution where I have an extra column where I
insert the channel uuid along with the data I insert as well. Then I make a
select query to the db collecting the id where the uuid matches the current
channel uuid and order by uuid desc.

My expectation/hope is that I won't get 2 uuid's generated by freeswitch
within a few seconds and should be able to rely on the id coming back as
being the last inserted id for the insert query I had just made.

Cheers,
-Jm



 -----Original Message-----
From: Nathan Neulinger <nneul at mst.edu>
To: FreeSWITCH Users Help <freeswitch-users at lists.freeswitch.org>
Sent: Sun, May 26, 2013 1:35 am
Subject: Re: [Freeswitch-users] dbh:query - insert id

 Looking at the code, I'm not seeing anything that would do this. Affected rows
is directly implemented as part of ODBC,
that's why it's easily available.


You could probably do a subsequent select on last_insert_id(), but there is a
high risk of race condition - some other
thread could use the dbh driver in the intervening time.

I don't believe that the last insert id is returned automatically on any of the
mysql api (underlying calls not FS)
calls, and then you have the odbc layer on top of that.

The way I've seen some other packages do it is to implement a mysql
specific sql
execute call that runs the statement,
and then immediately runs a select last_insert_id() and returns it.

-- Nathan

On 05/25/2013 10:01 AM, Lloyd Aloysius wrote:
> William,
>
> Thank you for the reply. Question was related to freeswitch dbh driver. Not
related to sql specific.
>
> Most of the SQL Driver have a method to get the id after the insert record. My
questions was does freeswitch dbh have
> any method to get the id?
>
> For Example dbh have a method dbh:affected_rows() for insert , update.
>
> Like this do we have a method for ID?
>
> Thanks
> Lloyd
> *
-- 
------------------------------------------------------------
Nathan Neulinger                       nneul at mst.edu
Missouri S&T Information Technology    (573) 612-1412
System Administrator - Architect

_________________________________________________________________________
Professional FreeSWITCH Consulting
Services:consulting at freeswitch.orghttp://www.freeswitchsolutions.com

FreeSWITCH-powered IP PBX: The CudaTel Communication
Server

Official FreeSWITCH
Siteshttp://www.freeswitch.orghttp://wiki.freeswitch.orghttp://www.cluecon.com

FreeSWITCH-users mailing
listFreeSWITCH-users at lists.freeswitch.orghttp://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-usershttp://www.freeswitch.org

 _________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting at freeswitch.org
http://www.freeswitchsolutions.com




Official FreeSWITCH Sites
http://www.freeswitch.org
http://wiki.freeswitch.org
http://www.cluecon.com

FreeSWITCH-users mailing list
FreeSWITCH-users at lists.freeswitch.org
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20130525/2e8aec71/attachment.html 


Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list