php - Retrieve autoincrement ID through ODBC -
i'm adding new features legacy application written in php uses oracle 9i database through odbc functions. i've created table has sequence , trigger generate auto-incrementing ids.
now, i'm struggling find way make insert , obtain generated id afterwards:
- the odbc library not appear have dedicated
lastinsertid
method. - running query
returning
clause triggers:ora-00439: feature not enabled: returning clause client type
. - i'm able run
returning
clause if enclose inbegin...end
block it's of little help: out parameters apparently not supported unified odbc driver php uses.
do need hard-code sequence name , use seq_name.currval
in rest of transaction? need ensure right value if there're concurrent accesses?
update: added third point failed attemps
best bet might code insert pl/sql api on database side return id use. e.g.)
create function insert_yourtable(p_f1 number, p_f2 varchar2, ... p_fn varchar2) return number idval number; begin insert yourtable(f1, f2,...fn) values (p_f1, p_f2, ...p_fn) returning your_id_value idval; return idval; end; /
then call prepared statement out param , use id rest of transaction.
whoops - saw "no out params comment...."
ok, guess need manage ui. drop trigger table, a
select yourseq.nextval dual;
to next available key value, store locally, , of work using retrieved id insert id field in table. sequence ensure have transactional security on id.
what pain in butt implementation of odbc!
Comments
Post a Comment