-
Notifications
You must be signed in to change notification settings - Fork 86
Timeout #462
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
Open
boekeljasper
wants to merge
5
commits into
blue-yonder:master
Choose a base branch
from
boekeljasper:timeout
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Timeout #462
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #include <turbodbc/cursor.h> | ||
| #include <turbodbc/make_description.h> | ||
|
|
||
| #include <turbodbc/buffer_size.h> | ||
|
|
||
| #include <cpp_odbc/statement.h> | ||
| #include <cpp_odbc/error.h> | ||
|
|
||
| #include <boost/variant/get.hpp> | ||
| #include <sqlext.h> | ||
| #include <stdexcept> | ||
|
|
||
| #include <cstring> | ||
| #include <sstream> | ||
| #include <codecvt> | ||
|
|
||
| #include <simdutf.h> | ||
|
|
||
| namespace { | ||
|
|
||
| std::u16string as_utf16(std::string utf8_encoded) { | ||
| size_t expected_utf16_chars = simdutf::utf16_length_from_utf8(utf8_encoded.data(), utf8_encoded.size()); | ||
| std::unique_ptr<char16_t[]> utf16{new char16_t[expected_utf16_chars]}; | ||
| size_t utf16_chars = simdutf::convert_utf8_to_utf16le(utf8_encoded.data(), utf8_encoded.size(), utf16.get()); | ||
| return std::u16string(utf16.get(), utf16_chars); | ||
| } | ||
| } | ||
|
|
||
| namespace turbodbc { | ||
|
|
||
| cursor::cursor(std::shared_ptr<cpp_odbc::connection const> connection, | ||
| turbodbc::configuration configuration) : | ||
| connection_(connection), | ||
| configuration_(std::move(configuration)), | ||
| command_() | ||
| { | ||
| } | ||
|
|
||
| cursor::~cursor() = default; | ||
|
|
||
| void cursor::prepare(std::string const & sql) | ||
| { | ||
| reset(); | ||
| auto statement = connection_->make_statement(); | ||
| if (configuration_.options.prefer_unicode) { | ||
| statement->prepare(as_utf16(sql)); | ||
| } else { | ||
| statement->prepare(sql); | ||
| } | ||
|
|
||
| statement->set_attribute(SQL_ATTR_QUERY_TIMEOUT, static_cast<std::intptr_t>(5)); | ||
|
|
||
| command_ = std::make_shared<command>(statement, configuration_); | ||
| } | ||
|
|
||
| void cursor::execute() | ||
| { | ||
| command_->execute(); | ||
| auto raw_result_set = command_->get_results(); | ||
| if (raw_result_set) { | ||
| results_ = raw_result_set; | ||
| } | ||
| } | ||
|
|
||
| std::shared_ptr<result_sets::result_set> cursor::get_result_set() const | ||
| { | ||
| return command_->get_results(); | ||
| } | ||
|
|
||
| bool cursor::more_results() const | ||
| { | ||
| return command_->more_results(); | ||
| } | ||
|
|
||
| int64_t cursor::get_row_count() | ||
| { | ||
| return command_->get_row_count(); | ||
| } | ||
|
|
||
| std::shared_ptr<cpp_odbc::connection const> cursor::get_connection() const | ||
| { | ||
| return connection_; | ||
| } | ||
|
|
||
| std::shared_ptr<turbodbc::command> cursor::get_command() | ||
| { | ||
| return command_; | ||
| } | ||
|
|
||
| void cursor::reset() | ||
| { | ||
| results_.reset(); | ||
| if(command_) { | ||
| command_->finalize(); | ||
| } | ||
| command_.reset(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #pragma once | ||
|
|
||
| #include <turbodbc/configuration.h> | ||
| #include <turbodbc/command.h> | ||
| #include <turbodbc/column_info.h> | ||
| #include <turbodbc/result_sets/result_set.h> | ||
|
|
||
| #include <cpp_odbc/connection.h> | ||
|
|
||
| #include <memory> | ||
|
|
||
|
|
||
| namespace turbodbc { | ||
|
|
||
| /** | ||
| * TODO: Cursor needs proper unit tests | ||
| */ | ||
| class cursor { | ||
| public: | ||
| cursor(std::shared_ptr<cpp_odbc::connection const> connection, | ||
| turbodbc::configuration configuration); | ||
|
|
||
| void prepare(std::string const &sql); | ||
|
|
||
| void execute(); | ||
|
|
||
| void reset(); | ||
|
|
||
| void add_parameter_set(std::vector <nullable_field> const ¶meter_set); | ||
|
|
||
| int64_t get_row_count(); | ||
|
|
||
| bool more_results() const; | ||
|
|
||
| std::shared_ptr <result_sets::result_set> get_result_set() const; | ||
|
|
||
| std::shared_ptr<cpp_odbc::connection const> get_connection() const; | ||
|
|
||
| std::shared_ptr <turbodbc::command> get_command(); | ||
|
|
||
| ~cursor(); | ||
|
|
||
| private: | ||
| std::shared_ptr<cpp_odbc::connection const> connection_; | ||
| turbodbc::configuration configuration_; | ||
| std::shared_ptr <turbodbc::command> command_; | ||
| std::shared_ptr <result_sets::result_set> results_; | ||
| }; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What is this rename about?