-
Notifications
You must be signed in to change notification settings - Fork 156
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
adding sqlite::endr, and ability to give functions to database_binder #113
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,10 @@ namespace sqlite { | |
} | ||
|
||
} | ||
void endr() { | ||
execute(); | ||
reset(); | ||
} | ||
|
||
std::string sql() { | ||
#if SQLITE_VERSION_NUMBER >= 3014000 | ||
|
@@ -286,6 +290,10 @@ namespace sqlite { | |
} | ||
}; | ||
|
||
inline void endr(database_binder& db) { | ||
db.endr(); | ||
} | ||
|
||
namespace sql_function_binder { | ||
template< | ||
typename ContextType, | ||
|
@@ -787,6 +795,24 @@ namespace sqlite { | |
val = i; | ||
} | ||
|
||
/// apply a member function | ||
inline database_binder& operator <<(database_binder& db, void (database_binder::* pf)(void)) { | ||
(db.*pf)(); | ||
return db; | ||
} | ||
|
||
/// apply a function pointer | ||
inline database_binder& operator<< (database_binder& db, void (*fun)(database_binder*)) { | ||
fun(&db); | ||
return db; | ||
} | ||
|
||
/// apply a lambda | ||
inline database_binder& operator<< (database_binder& db, std::function<void(database_binder&)>f) { | ||
f(db); | ||
return db; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use our |
||
// std::optional support for NULL values | ||
#ifdef MODERN_SQLITE_STD_OPTIONAL_SUPPORT | ||
template <typename OptionalT> inline database_binder& operator <<(database_binder& db, const std::optional<OptionalT>& val) { | ||
|
@@ -894,6 +920,7 @@ namespace sqlite { | |
// Some ppl are lazy so we have a operator for proper prep. statemant handling. | ||
void inline operator++(database_binder& db, int) { db.execute(); db.reset(); } | ||
|
||
|
||
// Convert the rValue binder to a reference and call first op<<, its needed for the call that creates the binder (be carefull of recursion here!) | ||
template<typename T> database_binder& operator << (database_binder&& db, const T& val) { return db << val; } | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,11 @@ int main() { | |
|
||
} | ||
|
||
auto ppsc = db << "CREATE TABLE tnums(name VARCHAR(30) PRIMARY KEY ASC NOT NULL UNIQUE, num INT NOT NULL);"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This statement is never executed. Either don't save the prepared statement to execute it implicitly or call |
||
auto ppsi = db << "INSERT INTO tnums VALUES (?,?);"; | ||
ppsi << "zero" << 0 << endr; | ||
ppsi << [&](database_binder&dbi) { dbi << "one" << 1; } << endr; | ||
|
||
|
||
} catch(sqlite_exception e) { | ||
cout << "Unexpected error " << e.what() << endl; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have the operator, so I don't think we need a member function. If we keep this function, we may prefer a more descriptive name.