Comments (3)
I came across this when looking at reporting a similar issue.
Environment
nanodbc version:2.14
DBMS name/version:Postgres
ODBC connection string:Driver={PostgreSQL ANSI};Uid=postgres;Server=localhost;Port=36947
OS and Compiler: Ubuntu 22.04
CMake settings:
TEST(Example, TestStringBindSingleNullRowFails)
{
const std::string pgConnectionString{
"Driver={PostgreSQL ANSI};Uid=postgres;Server=localhost;Port=36947"};
nanodbc::connection conn(pgConnectionString);
nanodbc::just_execute(conn,
"create temporary table test_table (id integer, name varchar(255))");
nanodbc::just_execute(conn, "truncate test_table");
nanodbc::transaction transaction(conn);
nanodbc::statement statement(conn, "insert into test_table (id, name) values (?, ?)");
std::vector<std::string> ids;
ids.emplace_back("1");
const std::array<bool, 1> notNull{{false}};
statement.bind_strings(0, ids, notNull.data());
bool pass(false);
if (pass) {
// Works if bind null
statement.bind_null(1, 1);
} else {
// Fails if bind string with all nulls
const std::array<bool, 1> null{{true}};
statement.bind_strings(1, ids, null.data());
}
nanodbc::just_execute(statement, static_cast<int>(ids.size()));
transaction.commit();
nanodbc::result result(nanodbc::execute(conn, "select * from test_table"));
ASSERT_TRUE(result.next());
ASSERT_FALSE(result.is_null(0));
// This fails
ASSERT_TRUE(result.is_null(1));
}
If you use the bind_null interface it works, but bind strings does not insert a null and instead will insert the string ignoring the "null" aspect.
from nanodbc.
I believe the issue is in bind_parameter
diff --git a/nanodbc/nanodbc.cpp b/nanodbc/nanodbc.cpp
index 9ece354..ed5ad3c 100644
--- a/nanodbc/nanodbc.cpp
+++ b/nanodbc/nanodbc.cpp
@@ -2239,7 +2239,7 @@ public:
param.scale_, // decimal digits
(SQLPOINTER)buffer.values_, // parameter value
buffer_size, // buffer length
- (buffer.size_ <= 1 ? nullptr : bind_len_or_null_[param.index_].data()));
+ (buffer_size <= 1 ? nullptr : bind_len_or_null_[param.index_].data()));
if (!success(rc))
NANODBC_THROW_DATABASE_ERROR(stmt_, SQL_HANDLE_STMT);
In the one row example the buffer.size_ is 1 and the buffer_size is 2.
Changing it fixes it, so that code is what is causing the issue but I am not 100% sure what the code is supposed to be doing (hence no PR). I am unsure as to why you wouldn't just always pass in the bind_len_or_null_ value but looking through the history that appears to have been there for many years (tracked it back as far as 2bd4e2e).
Not sure if anyone has any insight here.
from nanodbc.
@x-awaken & @HGeorge-Adapdix Thank you for your reports.
Hmm, this is interesting as it looks like an overlooked place that miss the change from buffer.size_
to local variable buffer_size
:
Line 2242 in 71b7f0b
Line 2888 in 71b7f0b
I do not recall anything specific on the use of buffer.size_
in those places, instead of buffer_size_
.
What I'd suggest is to submit PR with
- change from #347 (comment)
- test case from #347 (comment)
and let's see what the CI builds think about it.
I will also try to run local tests of such PR and perhaps add more test cases.
from nanodbc.
Related Issues (20)
- The long string in the result read from the parquet file will be truncated. HOT 1
- Is there any other way to get the return value of a procedure? HOT 3
- Request advice on serializing result-sets to JSON HOT 6
- Encoding for query on SQLServer break characters
- nanodbc exceptions not containing all function output messages HOT 2
- error C2665: 'std::list<nanodbc::connection::attribute,std::allocator<nanodbc::connection::attribute>>::push_back': no overloaded function could convert all the argument types HOT 7
- Add CI jobs using Visual Studio 2022
- Invalid parameter number when using placeholder within a Common Table Expression HOT 1
- "Fetch type out of range" error when calling result.prior(), result.first(), result.last() or result.at_end() HOT 1
- Improve auto_bind_columns to recognise fine-grained types
- docs: Explore migration to hdoc.io for API reference
- FR: support sql-server datetimeoffset HOT 4
- Remove #if __GNUC__ conditions and its cases
- Compilation fails due to the use of deprecated features HOT 2
- Evaluate cmakelang project for formatting and linting CMake scripts
- Evaluate GHA get-cmake to easily install of CMake and Ninja for all workflows
- Invalid descriptor index HOT 2
- How to reset loop? HOT 1
- Significant memory leak when TVP statements used with SQL Server HOT 2
- Connection pooling support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanodbc.