nukedzn / node-informix

A node.js native client for IBM Informix
18 stars 10 forks source link

Prepared Statement error after completing a successful entry #53

Closed ajozz13 closed 6 years ago

ajozz13 commented 6 years ago

Hello, I created a wrap function returning a promise that executes, captures a serial key after insertion. and ends the context after each successful entry, however on a subsequent calls the following error message is captured;

Error: A Statement is already prepared with the same ID. at /home/aochoa/services/ibc_informix/node_modules/informix/lib/statement.js:176:16 at new Promise () at /home/aochoa/services/ibc_informix/node_modules/informix/lib/statement.js:171:11 at

I understood that upon closing the context the prepared statement gets dismissed, is this correct?

here is the code of the wapper function

this.contextStatement = function( qry, vals ){

    var serial = -1;
    return new Promise( ( resolve, reject ) => {
        var ctx = this.informix.createContext();
        ctx.begin()
        .then( function(){
            return ctx.prepare( qry );
        //  return ctx.prepare( "insert into users(username, full_name, station, clearance) values (?, ?, ?, ?)" );
        })
        .then( function( statement ){
            return statement.exec( vals );
        })
        .then( function( cursor ){
            serial = cursor.serial();
            cursor.close();
            return ctx.commit();
        })
        .then( function(){
            ctx.end();
            resolve( serial );
        })
        .catch( function( err ){
            reject( err );
        })
    });
};
uatuko commented 6 years ago

Hi, No, prepared statements created within a context don't get dismissed when the context ends. The context is only used to tie the statement to a connection within the connection pool (so the transactions work properly).

Although, I agree when closing a context all prepared statements within that context should be freed as well. I'll take a look.

Thanks for reporting this.

ajozz13 commented 6 years ago

Thanks for checking...will statement free() call close the statement?

Regards Alberto

On Feb 24, 2018 17:52, "Uditha Atukorala" notifications@github.com wrote:

Hi, No, prepared statements created within a context don't get dismissed when the context ends. The context is only used to tie the statement to a connection within the connection pool (so the transactions work properly).

Although, I agree when closing a context all prepared statements within that context should be freed as well. I'll take a look.

Thanks for reporting this.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nukedzn/node-informix/issues/53#issuecomment-368266710, or mute the thread https://github.com/notifications/unsubscribe-auth/AAld11tjqypZFlz_8FTiK3MEaOHvdNalks5tYJLIgaJpZM4SR9hv .

uatuko commented 6 years ago

Yup, that'll do the trick.

ajozz13 commented 6 years ago

Great...I'll try the functionality calling the free statement before closing the context. Regards Alberto

On Feb 24, 2018 18:37, "Uditha Atukorala" notifications@github.com wrote:

Yup, that'll do the trick.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nukedzn/node-informix/issues/53#issuecomment-368269159, or mute the thread https://github.com/notifications/unsubscribe-auth/AAld15Ent39cU-2mki8_Wwxn9DxDC7Snks5tYJ1AgaJpZM4SR9hv .