dbTalk Databases Forums  

question: how to share connection in combined static and dynamicultralite?

sybase.public.sqlanywhere.ultralite sybase.public.sqlanywhere.ultralite


Discuss question: how to share connection in combined static and dynamicultralite? in the sybase.public.sqlanywhere.ultralite forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michal Seliga
 
Posts: n/a

Default question: how to share connection in combined static and dynamicultralite? - 02-23-2006 , 11:13 AM






hi

this is from docs:

---
To share a single connection
1. Ensure that your application is sharing a single SQLCA, as described in
the previous procedure.
2. Manage the connection using the UltraLite C++ Component.
Use the DatabaseManager::OpenConnection and Connection::Release
methods to open and close connections. Do not use the static interface
connection mechanisms. Once OpenConnection returns, the connection is current
for the SQLCA and is used for any subsequent embedded SQL or static C++ API
statements.
---

i did this but i have problem - all generated classes in uldatabase.cpp require
ULConnection as first parameter of Open (or Execute) methods. when i create
connection using ultralite c++ component what should i send there? NULL doesn't
work...

so question is, how can i get ULConnection pointer when i manage connections
with DatabaseManager object?

thanks in advance...

Reply With Quote
  #2  
Old   
Michal Seliga
 
Posts: n/a

Default Re: question: how to share connection in combined static and dynamicultralite? - 02-23-2006 , 11:26 AM






just for case it will be neede, i have asa 9.0.2.3249, i use c++ api on palm
with codewarrior 9.3

Reply With Quote
  #3  
Old   
Michael Thode
 
Posts: n/a

Default Re: question: how to share connection in combined static and dynamic ultralite? - 02-23-2006 , 03:22 PM



If you don't need your static and dynamic UL code to be part of the same
transaction then you can create a separate connection to the database for
each API. This is the easiest route. UL runs at isolation level zero, so
uncommitted rows on one connection _will_ be visable on the other
connection. The only thing you can't do is insert/update a row on one
connection (without committing it) and then try and update/delete it on
another connection.

If that doesn't work for you and you need to share the connection then that
isn't officially supported in UL. The docs appear to be misleading here.
For sharing a connection mixing dynamic C++ API with ESQL is ok, but not
dynamic C++ and static C++.

Unofficially you can get the functionality you need by altering
%asany9%\src\ulapi.cpp and %asany9%\h\ulapi.h

Add the following method to ulapi.cpp. This will allow you to initialize a
ULConnection object from an existing connection.

bool ULConnection::Attach( ULData *db, ul_char *name )
{
if( db == UL_NULL ) return false;
if( !db->IsOpen() ) return false;
if( IsOpen() ) return false;
_db = db;
_conn = ulpp_setconnect( db->GetCA(), name ); // This line is the
difference between Attach and Open
_open = LastCodeOK();
return _open;
}

Then add the corresponding prototype in ulapi.h in the public section of the
ULConnection class (about line 240 in my copy of the file)

In order to make this work....
1. Share your sqlca as described in the docs
2. Connect using dynamic C++. Name your connection eg add
"CON=myconnection" to the connection parameters
3. Call the new Attach method using the connection name

Note:
Don't call ULConnection::Close on the shared connection, use the dynamic C++
API to close the connection.
Make sure to you make copies of the new ulapi files. They could be
overwritten by an EBF.

Hope that helps,
Mike

"Michal Seliga" <michal.seliga (AT) visicom (DOT) sk> wrote

Quote:
hi

this is from docs:

---
To share a single connection
1. Ensure that your application is sharing a single SQLCA, as described in
the previous procedure.
2. Manage the connection using the UltraLite C++ Component.
Use the DatabaseManager::OpenConnection and Connection::Release
methods to open and close connections. Do not use the static interface
connection mechanisms. Once OpenConnection returns, the connection is
current
for the SQLCA and is used for any subsequent embedded SQL or static C++
API
statements.
---

i did this but i have problem - all generated classes in uldatabase.cpp
require
ULConnection as first parameter of Open (or Execute) methods. when i
create
connection using ultralite c++ component what should i send there? NULL
doesn't
work...

so question is, how can i get ULConnection pointer when i manage
connections
with DatabaseManager object?

thanks in advance...



Reply With Quote
  #4  
Old   
Michal Seliga
 
Posts: n/a

Default Re: question: how to share connection in combined static and dynamicultralite? - 02-24-2006 , 03:34 AM



thank you for answer, i will test it.

Michael Thode wrote:
Quote:
If you don't need your static and dynamic UL code to be part of the same
transaction then you can create a separate connection to the database for
each API. This is the easiest route. UL runs at isolation level zero, so
uncommitted rows on one connection _will_ be visable on the other
connection. The only thing you can't do is insert/update a row on one
connection (without committing it) and then try and update/delete it on
another connection.

If that doesn't work for you and you need to share the connection then that
isn't officially supported in UL. The docs appear to be misleading here.
For sharing a connection mixing dynamic C++ API with ESQL is ok, but not
dynamic C++ and static C++.

Unofficially you can get the functionality you need by altering
%asany9%\src\ulapi.cpp and %asany9%\h\ulapi.h

Add the following method to ulapi.cpp. This will allow you to initialize a
ULConnection object from an existing connection.

bool ULConnection::Attach( ULData *db, ul_char *name )
{
if( db == UL_NULL ) return false;
if( !db->IsOpen() ) return false;
if( IsOpen() ) return false;
_db = db;
_conn = ulpp_setconnect( db->GetCA(), name ); // This line is the
difference between Attach and Open
_open = LastCodeOK();
return _open;
}

Then add the corresponding prototype in ulapi.h in the public section of the
ULConnection class (about line 240 in my copy of the file)

In order to make this work....
1. Share your sqlca as described in the docs
2. Connect using dynamic C++. Name your connection eg add
"CON=myconnection" to the connection parameters
3. Call the new Attach method using the connection name

Note:
Don't call ULConnection::Close on the shared connection, use the dynamic C++
API to close the connection.
Make sure to you make copies of the new ulapi files. They could be
overwritten by an EBF.

Hope that helps,
Mike

"Michal Seliga" <michal.seliga (AT) visicom (DOT) sk> wrote in message
news:43fdddd2$1 (AT) forums-2-dub (DOT) ..
hi

this is from docs:

---
To share a single connection
1. Ensure that your application is sharing a single SQLCA, as described in
the previous procedure.
2. Manage the connection using the UltraLite C++ Component.
Use the DatabaseManager::OpenConnection and Connection::Release
methods to open and close connections. Do not use the static interface
connection mechanisms. Once OpenConnection returns, the connection is
current
for the SQLCA and is used for any subsequent embedded SQL or static C++
API
statements.
---

i did this but i have problem - all generated classes in uldatabase.cpp
require
ULConnection as first parameter of Open (or Execute) methods. when i
create
connection using ultralite c++ component what should i send there? NULL
doesn't
work...

so question is, how can i get ULConnection pointer when i manage
connections
with DatabaseManager object?

thanks in advance...



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.