Skip to content

ODBC binding string longer than 255 #4135

@o4worksp

Description

@o4worksp

I am using Poco 1.12.4 to connect PostgreSQL using ODBC .

#include <Poco/Data/ODBC/Connector.h>
#include <Poco/Data/MySQL/Connector.h>
#include <Poco/Data/Session.h>
#include <Poco/Data/Statement.h>
#include <Poco/Data/RecordSet.h>
#include <iostream>
#include <Poco/Exception.h>
using namespace Poco::Data::Keywords;

int main()
{
    try
    {
        Poco::Data::ODBC::Connector::registerConnector();
        
        std::stringstream connect_str;
        std::string con_str = "Driver={PostgreSQL};Server=127.0.0.1;Port=5432;Databas=postgres;Uid=postgres;Pwd=123ABCdef;";
        Poco::Data::Session session("ODBC", con_str);
        Poco::Data::Statement st(session);

        try
        {
           
            int id;
            std::string file_path = "超长文件名称的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上粉色的方法的沙发上.docx";
            st << "select id from \"test_bind\" where file_path = ?", use(file_path), into(id), now;
            std::cout << id << std::endl;

        }
        catch (const Poco::Exception &ex)
        {
            std::cerr << ex.displayText() << '\n';
        }
    }
    catch (const Poco::Exception &ex)
    {
        std::cerr << "Error: " << ex.displayText() << std::endl;
    }
    Poco::Data::ODBC::Connector::unregisterConnector();

    return 0;
}

create table sql

CREATE TABLE IF NOT EXISTS TEST_BIND (
ID BIGSERIAL NOT NULL,
FILE_PATH VARCHAR(1024) DEFAULT NULL
);

output:

Data too long : Error binding column 0 size=467 ,max size=255

question:

how to bind string longer than 255 using odbc?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions