Re: use session: cursor is released

Mike Aubury <[email protected]>
Newsgroups gmane.comp.lang.4gl.aubit.general
Message-ID <CAGAq4WF+NUcDNykreyFB1ySwS0GKuwM_n8vo-4jyA7pXJBq5WQ@mail.gmail.com>
I think the problem here is that you're opening connections using the "open
session" and mixing that with "DATABASE" statements - and its just getting
confused..
The Open session will make itself the 'current' connection,

Theres two ways to fix it ..

1) Put the
    open session remote to database "test2"
    open session here to database "test1"

before we start processing (which is probably better anyway - as you wont
be re-opening the connections all the time)

2) Use an explicit connection instead of the last "database" - and make
sure to reset to that..


I've attached an example for each approach..




On 9 July 2012 16:08, Fernando Ortiz <[email protected]> wrote:

> Hi,
>
> I want to insert some data  in a 'remote' database, I normally use
> 'session' for this, but when there is a open cursor it's released.
>
> I 'remember' there is a 'default' session,  can I use it to avoid this?
>
> Or maybe the session identifier be passed as parameter between modules?
>
>
> [ortiz@adela tmp]$ ./sess1.4ae
> Err:Program ./sess1.4ae stopped at 'sess1.4gl', line number 26.
> Error status number -1.
> cursor "sess1_c_t1" does not exist.
>
> 4gl function call stack :
>     MAIN
>
> { environment}
> A4GL_LEXDIALECT=INFORMIX
> A4GL_LEXTYPE=C
> A4GL_SQLTYPE=pg8
>
> A4GL_ALWAYS_CAST=N
> A4GL_COMPILE_ALONE=Y
> A4GL_DATEASLONG=Y
>
> { sess1.4gl }
> database test1
>
> main
> define lv_id int
> define lv_desc char(3)
>
> { setup tables .... }
> database test1
> whenever error continue
> drop table test1
> whenever error stop
> create table test1 (iden integer, descript char(3))
>     insert into test1 values (1,'aaa')
>     insert into test1 values (2,'bbb')
>     insert into test1 values (3,'ccc')
> database test2
> whenever error continue
> drop table test2
> whenever error stop
> create table test2 (iden integer, descript char(3))
> database test1
> { end of set up   }
>
>     set session to default
> declare c_t1 cursor for select iden from test1
> foreach c_t1 into lv_id
>     call copy_id(lv_id)
> end foreach
>
> { check info is there }
> database test2
> declare c_t2 cursor for select iden, descript from test2
> foreach c_t2 into lv_id, lv_desc
>     display lv_desc
> end foreach
> { end check }
> end main
>
> { for test in same module, the solution should work in another module }
> function copy_id(p_id)
>     define p_id int
>     define lv_desc char(3)
>
>     open session remote to database "test2"
>     open session here to database "test1"
>     use session here for
>        select descript into lv_desc from test1 where iden = p_id
>     use session remote for
>        insert into test2 values (p_id, lv_desc)
> end function
>
> Regards
>
>
> ------------------------------------------------------------------------------
> Live Security Virtual Conference
> Exclusive live event will cover all the ways today's security and
> threat landscape has changed and how IT managers can respond. Discussions
> will include endpoint security, mobile security and the latest in malware
> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
> _______________________________________________
> Aubit4gl-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/aubit4gl-discuss
>
>

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/

_______________________________________________
Aubit4gl-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/aubit4gl-discuss
t2_1.4gl (application/octet-stream, 1.2 KB) - not displayed
t2_2.4gl (application/octet-stream, 1.2 KB) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.