Fix issue 15880 by pre-describing ODBC parameters

Rather than modifying nanodbc to silently handle missing
SQLDescribeParam support, describe parameters in the application
before binding them. This approach keeps nanodbc pristine and
moves the workaround logic to KiCad where the issue occurs.

The fix pre-describes parameters as VARCHAR with size 255 in
DatabaseConnection::SelectOne before attempting to bind them.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15880
This commit is contained in:
Seth Hillbrand
2026-01-29 16:31:44 -08:00
parent 0c9e02c965
commit acbcb5e014
3 changed files with 20 additions and 20 deletions
+18 -1
View File
@@ -400,7 +400,6 @@ bool DATABASE_CONNECTION::SelectOne( const std::string& aTable,
try
{
statement.prepare( *m_conn, query );
statement.bind( 0, aWhere.second.c_str() );
}
catch( std::exception& e )
{
@@ -414,6 +413,24 @@ bool DATABASE_CONNECTION::SelectOne( const std::string& aTable,
return false;
}
// Pre-describe parameter as VARCHAR to avoid SQLDescribeParam call. Some ODBC drivers
// (Microsoft Access, Excel, CSV) don't implement SQLDescribeParam.
try
{
statement.describe_parameters( { 0 }, { SQL_VARCHAR }, { 255 }, { 0 } );
statement.bind( 0, aWhere.second.c_str() );
}
catch( std::exception& e )
{
m_lastError = e.what();
wxLogTrace( traceDatabase, wxT( "Exception while binding parameter for SelectOne: %s" ),
m_lastError );
Disconnect();
return false;
}
wxLogTrace( traceDatabase, wxT( "SelectOne: `%s` with parameter `%s`" ), toUTF8( query ),
aWhere.second );