Comments (5)
Hi,
A resultset lifetime is bound to its statement parent object which lifetime is also bound to its parent connection object.
OCILIB C++ object are used as value object but are smart pointers that keeps track internally of these relationships.
When an OCILIB goes out of scope, all of its children are cleaned.
In your executequery function:
- you create a connection
- you create a statement
- you create a resultset
- you return the resultset
Before execute query returns, the destructor of the connection object is invoked. As they is no more reference to it, it cleans it and it leads to free the statement and then the resultset.
You don't really need to use smart pointers as ocilib object are already smart pointers.
You just need to keep references to ocilib objects. You do that by having valid objects.
Your method getconnection could just return a plain connection object instead of shared_ptr (as the connection object is already a smart pointer).
Then your execute query could just return a simple structure with 3 fields : connection object, statement object and resultset object.
In executequery, you create the statement and the resultset.
And return the struct by initializing it with the 3 objects.
And then the results will be valid after returning from execute query.
Vincent
from ocilib.
Current c++ Api objects keep tracks of the C API handles, not C++ objects.
I agree that maintaining a reference to resultset should keep the connection object in memory.
I will make some changes in v4.8 for that.
from ocilib.
Why the number of results with Resultset::GetCount()
is zero ?
But it is valuable after using Next()
the code snippet:
ocilib::Statement stmt(conn);
stmt.Execute(sql);
conn.Commit();
auto rs = stmt.GetResultset();
rs.GetCount(); // return 0
rs.Next();
rs.Get("xxx"); // is right
from ocilib.
GetCount() returns the number of fetched rows. It is updated after each fetch operation.
There is no way to get row count in advance except using scrollable cursors
from ocilib.
Closing the issue as not a bug and and more related to API usage.
from ocilib.
Related Issues (20)
- OCI_RefToText() return garbage when charset is OCI_CHARSET_WIDE HOT 1
- Error occurred at OcilibEnvironmentInitialize: Cannot load OCI shared library (oci.dll) HOT 4
- Regarding the use of connection pool to obtain links, will it be automatically recycled by connection pool? HOT 1
- I don't know why I suddenly reported this error: ocilib\include\ocilibcpp\detail\exception.hpp(92): error C2061: syntax error: identifier 'nothrow' HOT 1
- Regarding using ocilib::Pool to get links ,what happens if the maximum link is reached? HOT 1
- symbol not found in flat namespace '_OCIAQDeq' (macOS arm64) HOT 3
- Wrapper for OCINlsGetInfo() HOT 1
- On connection pool problem HOT 6
- On the limitation of the number of preprocessing bindings? HOT 1
- Why does ocilib::Resultset restrict the default construct? HOT 1
- crash with using change notification HOT 1
- Free memory after dequeue HOT 1
- DCN getObjectName display mess code HOT 1
- Invalid problem of batch std::vector<ocilib::Date > date display. HOT 4
- C++ Value types perform handle assignment instead of value assignment
- Two doubts ! HOT 1
- Reusing prepared statement hangs HOT 2
- OcilibElementSetRaw bug HOT 1
- Pool connection is never released (C++) HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocilib.