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

Issue regarding the overloading of SQLite::Statement::bind #464

Open
pya789 opened this issue Apr 15, 2024 · 0 comments
Open

Issue regarding the overloading of SQLite::Statement::bind #464

pya789 opened this issue Apr 15, 2024 · 0 comments

Comments

@pya789
Copy link

pya789 commented Apr 15, 2024

Using nm -gC libSQLiteCpp.a | grep SQLite::Statement::bind to get the result.
U SQLite::Statement::bind(int, char const*)
U SQLite::Statement::bind(int, std::string const&)
0000000000000594 T SQLite::Statement::bindNoCopy(int, char const*)
00000000000005e6 T SQLite::Statement::bindNoCopy(int, void const*, int)
000000000000051c T SQLite::Statement::bindNoCopy(int, std::string const&)
000000000000063a T SQLite::Statement::bind(int)
0000000000000474 T SQLite::Statement::bind(int, char const*)
00000000000004c8 T SQLite::Statement::bind(int, void const*, int)
00000000000003fc T SQLite::Statement::bind(int, std::string const&)
00000000000003ac T SQLite::Statement::bind(int, double)
00000000000002c8 T SQLite::Statement::bind(int, int)
0000000000000310 T SQLite::Statement::bind(int, unsigned int)
0000000000000362 T SQLite::Statement::bind(int, long)

my code↓
const std::string &softId is a formal parameter.

try
    {
        SQLite::Statement query(SQLITE_DB, "UPDATE local_softs SET install_status = ? WHERE soft_id = ?");
        query.bind(1, installResult != 0 ? 2 : 1);
        query.bind(2, softId);
        query.exec();
    }
    catch (const std::exception &e)
    {
        spdlog::error("InstallError: {}", e.what());
    }

libSQLiteCpp.a|libsqlite3.a was compiled in Scenario 2 environment.

target_link_libraries(xp-tasks PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/libSQLiteCpp.a)
target_link_libraries(xp-tasks PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/lib/libsqlite3.a)

Scenario 1
os version:g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
sqlite version:3.31.1
error:/usr/bin/ld: CMakeFiles/xp-tasks.dir/src/task/task.cpp.o: in function Task::Install(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': /home/pya789/project/xp-tasks/src/task/task.cpp:172: undefined reference to SQLite::Statement::bind(int, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)'

tips
Using softId.c_str() is normal in this case because it conforms to the signature of SQLite::Statement::bind(int, char const*). This means that the char const* type returned by softId.c_str() can be passed as a parameter to the bind function, allowing it to be used normally in this situation.

Scenario 2
os version:g++ (GCC) 9.3.1 20200408 (Red Hat 9.3.1-2)
sqlite version:3.7.17
Everything is normal

My English is not good, using translation, sorry.😂

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