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

std::string_view + other non null-terminated input support for insertion #175

Open
Xeverous opened this issue Dec 1, 2018 · 0 comments
Open

Comments

@Xeverous
Copy link

Xeverous commented Dec 1, 2018

Right now there is such thing in the implementation:

	// Convert char* to string to trigger op<<(..., const std::string )
	template<std::size_t N> inline database_binder& operator <<(database_binder& db, const char(&STR)[N]) { return db << std::string(STR); }
	template<std::size_t N> inline database_binder& operator <<(database_binder& db, const char16_t(&STR)[N]) { return db << std::u16string(STR); }

	 inline database_binder& operator <<(database_binder& db, const std::string& txt) {
		int hresult;
		if((hresult = sqlite3_bind_text(db._stmt.get(), db._next_index(), txt.data(), -1, SQLITE_TRANSIENT)) != SQLITE_OK) {
			errors::throw_sqlite_error(hresult, db.sql());
		}

		return db;
	}

The implementation builds temporary strings (unneded allocation) and loses the information on their length by passing -1.

This looks like a simple thing to fix - while also giving the opportunity to add support for non-null-terminated strings such as std::string_view. I propose database_binder::bind_next(T* ptr, int length).

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

1 participant