Re: problems with currval and rollback

From: Pandurangan R S <pandurangan(dot)r(dot)s(at)gmail(dot)com>
To: Assad Jarrahian <jarraa(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: problems with currval and rollback
Date: 2005-12-23 06:13:26
Message-ID: 5e744e3d0512222213y76d8ebb0le51a69bd362f852e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Refer http://www.postgresql.org/docs/8.1/static/functions-sequence.html

On 12/23/05, Assad Jarrahian <jarraa(at)gmail(dot)com> wrote:
> Hi all,
> So I started to make some changes with my code here and there
> (nothing to do with the relevant lines) and suddenly currval and
> rollback don't work.
>
> try{
> db.setAutoCommit(false);
> addLM.setInt(1, lm.getOrigin());
> .......
> addLM.executeUpdate();
> sql = db.createStatement();
> ResultSet result = sql.executeQuery("SELECT
> currval('lm_id_seq');");
> if (result. next()){
> db.commit();
> db.setAutoCommit(true);
> else{
> db.rollback(); //reverse all changes
> db.setAutoCommit(true);
> }
> catch(SQLException ex){
> try {
> db.rollback();
> db.setAutoCommit(true);
> } catch (SQLException e) {
> throw e;
> }
> throw ex;
> }
>
> What happens is that the it inserts a db, but cannot get a value back
> using currval (ERROR: ERROR: currval of sequence "lm_id_seq" is not
> yet defined in this session 55000 ) , yet the db gets the addlm
> inserted.
>
>
> Shouldn't it rollback?
> Furthermore, why would currval suddenly stop working?
>
> Much thanks for your feedback in advance.
>
> -assad
>
> ---------------------------(end of broadcast)---------------------------
> TIP 9: In versions below 8.0, the planner will ignore your desire to
> choose an index scan if your joining column's datatypes do not
> match
>

--
Regards
Pandu

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ludek Finstrle 2005-12-23 10:05:17 Re: ODBC connection string, MS Access
Previous Message Michael Fuhr 2005-12-23 06:05:10 Re: query for a time interval