Skip to content

Changed the way arguments are chained #29 #31

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

Merged
merged 8 commits into from
Jan 24, 2016
Merged

Changed the way arguments are chained #29 #31

merged 8 commits into from
Jan 24, 2016

Conversation

Killili
Copy link
Collaborator

@Killili Killili commented Jan 23, 2016

Major Changes and General Overhaul of the everything.

-Refactored
exceptions into its own namespace
-removed rvalue references where they
are not needed
-made prepared statments possible
-made them
reusable
-removed some template magic

Major Changes and General Overhaul of the everything.

-Refactored
exceptions into its own namespace
-removed rvalue references where they
are not needed
-made prepared statments possible
-made them
reusable
-removed some template magic
@Killili
Copy link
Collaborator Author

Killili commented Jan 23, 2016

This is somewhat related to #29 but it got a bit out of hand so i made a new pull for this.
Its pretty much what i thought would be possible if we changed every lref of database_binder to a unique pointer so stuff like this is possible now:

try {

        { // scope somewhere else
          // creates a database file 'dbfile.db' if it does not exists.
            database db("dbfile.db");

            db << "drop table if exists test"; // still works as intended cause the database_binder dies at the semicolon
            db <<
                "create table if not exists test ("
                "   id integer primary key autoincrement not null,"
                "   val int"
                ");";

        } // destroy db

        database db("dbfile.db");

        std::cout << "auto&\n";
        auto& pps = db << "select ?"; // get a prepared parsed and ready statment

        int test = 4;
        pps << test; // set a bound var

        pps >> test; // execute and reset statment

        pps << 4; // bind a rvalue
        pps >> test; // and execute again

        auto& pps2 = db << "select 1,2,3,4,5"; // multiple extract test

        pps2 >> [](int a, int b, int c, int d, int e) {
            std::cout << "L " << a << b << c << d << e << "\n"; // still works as intended
        };

    } catch(exception& e) { // and here all statments die...
        cout << e.what() << endl;
    }

@aminroosta
Copy link
Collaborator

Changes are good 👍
But build is failing.

-we are c++11 so no funny bussines with make::unique
Added test for chaining and syntax check.

Added new operator++ to database_binder it executes and resets the
statment, might be extended to something like an iterator someday.
warnings are errors and unused vars are warnings, thats pedantic for
tests...
@Killili
Copy link
Collaborator Author

Killili commented Jan 24, 2016

Ok it took my ~20h but now it looks good!
There is a lot of template magic in the lib so having more builds would be nice.

I can confirm VC2015 and gcc-5.2.1 and gcc-4.8.2(travis) can someone test clang?

Readme follows... ;)

@aminroosta
Copy link
Collaborator

@Killili i can confirm that all 5 tests ran successfully on clang 7.0.2
Great job 👍

if (hresult != SQLITE_DONE) {
throw_sqlite_error(hresult);
}
void set_used(bool state) { execution_started = state; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of two functions overload .used() // getter and .used(bool) // setter functions

@aminroosta
Copy link
Collaborator

@Killili i have added some comments on the code, these are all just suggestions,
you are free to follow or keep names the way they are ;)

@aminroosta
Copy link
Collaborator

@Killili Please go one more iteration on readme file ;)
I recommend writing "sql queries" that work for examples.
Please add your database backup example for shared_connections section ( its a useful example).
Also please draft a new release after you've merged this,
I think there have been so many great changes.

@Killili
Copy link
Collaborator Author

Killili commented Jan 24, 2016

Thx.

Those examples are valid SQL and work, maybe they are a bit short. But i like having examples that dont go through the whole "create table... yada yada" and get right to the point.
The backup routine is a bit long for an example but i will try.
I'm undecided on the getter/setter conventions, both have pros/cons.

@Killili
Copy link
Collaborator Author

Killili commented Jan 24, 2016

As much as i hate the word "iteration" in the context of documentation its done ;)

As for the connection setter: I think that would add inconsistencies to prepared statements, as they have a copy of the connection after they are created. Consider:

database db("orig");
auto ps = db << "select ...";

database db2("new");
db.connection(db2.connection());
auto ps2 = db << "select ...";

ps++; // this will run on DB "orig"
ps2++; // this will run on DB "new"

I dont get what you mean with "draft" a release so i leave that "honor" to you ;)

aminroosta added a commit that referenced this pull request Jan 24, 2016
Changed the way arguments are chained #29
@aminroosta aminroosta merged commit b958f9b into master Jan 24, 2016
@aminroosta
Copy link
Collaborator

@Killili I just wanted to thank you again 😉
Also thanks for database backup example, really useful example 🏆

@Killili Killili deleted the frontier branch January 24, 2016 13:34
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

Successfully merging this pull request may close these issues.

2 participants