Coder Social home page Coder Social logo

Comments (5)

vrogier avatar vrogier commented on July 22, 2024

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.

vrogier avatar vrogier commented on July 22, 2024

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.

MagicXran avatar MagicXran commented on July 22, 2024

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.

vrogier avatar vrogier commented on July 22, 2024

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.

vrogier avatar vrogier commented on July 22, 2024

Closing the issue as not a bug and and more related to API usage.

from ocilib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.