Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding 'open environment' and 'get db object' invocation order #150

Closed
rZinnatov opened this issue Nov 30, 2017 · 4 comments
Closed

Comments

@rZinnatov
Copy link
Contributor

Hello guys!

Question

Does the order of invocation the sp_open(env) and sp_getobject(env, "db.test") statements matter?

I tried both cases and it worked in each case. So obviously it doesn't but I tried trivial ones. So is there any case when it does matter?

Why am I concerned

CRUD example says:

void *db = sp_getobject(env, "db.test");
int rc = sp_open(env);

Common Workflow example says:

sp_open(env);
void *db = sp_getobject(env, "db.test");

Thank you!

@pmwkaa
Copy link
Owner

pmwkaa commented Nov 30, 2017

Hi, in that case yes - second case is more correct, thanks for pointing this out.
Database object would be unusable until it gets open. sp_open(env) basically opens all pre-defined databases and replays write-ahead log records. Yet, it it possible to create a new database after sp_open(env) is done by doing sp_open(db).

@rZinnatov
Copy link
Contributor Author

Just to be clear. Open environment first is more correct, is it?

sp_open(env);
void *db = sp_getobject(env, "db.test");

About sp_open(db): Did you mean the following?

sp_open(env);
sp_setstring(env, "db", "test", 0);
void *db = sp_getobject(env, "db.test");
sp_open(db); // Do this because 'db' string was set after sp_open(env)

@pmwkaa
Copy link
Owner

pmwkaa commented Nov 30, 2017

Yes to both questions :)

@rZinnatov
Copy link
Contributor Author

Thank you for the explanations! =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants