Re: use session: cursor is released

Fernando Ortiz <[email protected]>
Newsgroups gmane.comp.lang.4gl.aubit.general
Message-ID <CAKK5tB1d0UO8=ABPhV7GWC6sydq=tcp4pWPJyF_qV+fS-HqZkg@mail.gmail.com>
Both versions work fine ... in same module. I need it in different modules

[root@ocs aubit]# cat q1.4gl
{q1.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))
{ end of set up   }


{ session local defined in p1.4gl should be visible to p2.4gl }
open session local  to database "test1"
{ session remote defined in p1.4gl should be visible to p2.4gl }
open session remote  to database "test2"

set session to local

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 }
set session to remote
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



[root@ocs aubit]# cat q2.4gl
{ q2.4gl }
function copy_id(p_id)
    define p_id int
    define lv_desc char(3)
    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


[root@ocs aubit]# 4glpc q1.4gl q2.4gl -o q.4ae
[root@ocs aubit]# ./q.4ae
Err:Program ./q.4ae stopped at 'q2.4gl', line number 7.
Error status number -206.
relation "test2" does not exist.

4gl function call stack :
    q1.4gl (Line 34) calls  copy_id(p_id=1)
    MAIN


>From the lines of debug.out

API_sql.c            513    dbg (     0,     0,0) A4GLSQL_get_curr_conn
 ()  Call to char* A4GLSQL_get_curr_conn()
pg8.c                706    dbg (     0,     0,0)
A4GLSQLLIB_A4GLSQL_get_curr_conn()  currentConName=q1_local
API_sql.c            521    dbg (     0,     0,0) A4GLSQL_get_curr_conn
 ()  Returning (q1_local)
API_sql.c            336    dbg (     0,     0,0)
A4GLSQL_set_conn_internal()  Call to int
A4GLSQL_set_conn_internal((q2_remote)))
pg8.c                712    dbg (     0,     0,0)
A4GLSQLLIB_A4GLSQL_set_conn_internal()  Set conn q2_remote
pg8.c                721    dbg (     0,     0,0)
A4GLSQLLIB_A4GLSQL_set_conn_internal()  Not found
API_sql.c            344    dbg (     0,     0,0)
A4GLSQL_set_conn_internal()  Returning '1'


[root@ocs aubit]# cat q1.4gl q2.4gl >q.4gl
[root@ocs aubit]# 4glpc q.4gl -o q.4ae
[root@ocs aubit]# ./q.4ae
aaa
bbb
ccc


Thanks

On Mon, Jul 9, 2012 at 11:34 AM, Mike Aubury <[email protected]> wrote:

> 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
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.