Giter Club home page Giter Club logo

sqlpp11-connector-mysql's People

Contributors

andidog avatar dalzhim avatar fpoms avatar islc avatar kovdan01 avatar lucianodasilva avatar marmand avatar ravenx8 avatar rbock avatar tizbac avatar toxe avatar wopss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlpp11-connector-mysql's Issues

Why is it necessary to pass database parameter when creating a connection?

In line 53-56 of file: https://github.com/rbock/sqlpp11-connector-mysql/blob/master/src/detail/connection_handle.cpp
We have:

if (mysql_select_db(mysql, config.database.c_str()))
{
      throw sqlpp::exception("MySQL error: can't select database '" + config.database + "'");
}

But I think in general, we do not need to set the database when simply creating a connection to the mysql server. Instead, we should first connect to the server, then we type use database_name to conduct queries. Therefore, I suggest to remove the codes mentioned above.

Error reported while installing sqlpp11-mysql

I kept reporting the following error when I installed sqlpp11-mysql again:
I m sure my date path and sqlpp11 path are correct

-- The C compiler identification is GNU 8.3.0 -- The CXX compiler identification is GNU 8.3.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for pthread.h -- Looking for pthread.h - found -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed -- Looking for pthread_create in pthreads -- Looking for pthread_create in pthreads - found -- Found Threads: TRUE CMake Warning (dev) at /usr/local/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:438 (message): The package name passed to find_package_handle_standard_args(MYSQL) does not match the name of the calling package (MySql). This can lead to problems in calling code that expectsfind_packageresult variables (e.g.,_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
cmake/FindMySql.cmake:49 (find_package_handle_standard_args)
CMakeLists.txt:36 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.

-- Found MYSQL: /usr/lib/x86_64-linux-gnu/libmysqlclient.so
-- Using /usr/bin/c++ (compiler id: GNU)
CMake Error at CMakeLists.txt:43 (message):
Can't find file date/date.h

Can't find date/date.h in /home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/../date/include
Please either

CMake Error at CMakeLists.txt:58 (message):
Can't find file sqlpp11/sqlpp11.h

Can't find sqlpp11/sqlpp11.h in /home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/../sqlpp11/include
Please either

  • git clone https://github.com/rbock/sqlpp11 /home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/../sqlpp11/include
  • download and unzip a current version from https://github.com/rbock/sqlpp11 to /home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/../sqlpp11/include
  • set SQLPP11_INCLUDE_DIR to point to the dir containing sqlpp11/sqlpp11.h

-- Configuring incomplete, errors occurred!
See also "/home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/build/CMakeFiles/CMakeOutput.log".
See also "/home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/build/CMakeFiles/CMakeError.log".`

CMakeError.log file:

`Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: /home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/build/CMakeFiles/CMakeTmp

Run Build Command(s):/usr/bin/make -f Makefile cmTC_9eab5/fast && /usr/bin/make -f CMakeFiles/cmTC_9eab5.dir/build.make CMakeFiles/cmTC_9eab5.dir/build
make[1]: Entering directory '/home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_9eab5.dir/src.c.o
/usr/bin/cc -DCMAKE_HAVE_LIBC_PTHREAD -o CMakeFiles/cmTC_9eab5.dir/src.c.o -c /home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/build/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTC_9eab5
/usr/local/bin/cmake -E cmake_link_script CMakeFiles/cmTC_9eab5.dir/link.txt --verbose=1
/usr/bin/cc -rdynamic CMakeFiles/cmTC_9eab5.dir/src.c.o -o cmTC_9eab5
/usr/bin/ld: CMakeFiles/cmTC_9eab5.dir/src.c.o: in function main': src.c:(.text+0x2d): undefined reference to pthread_create'
/usr/bin/ld: src.c:(.text+0x39): undefined reference to pthread_detach' /usr/bin/ld: src.c:(.text+0x45): undefined reference to pthread_cancel'
/usr/bin/ld: src.c:(.text+0x56): undefined reference to `pthread_join'
collect2: error: ld returned 1 exit status
make[1]: *** [CMakeFiles/cmTC_9eab5.dir/build.make:99: cmTC_9eab5] Error 1
make[1]: Leaving directory '/home/mscg/project/sqlpp11-connector-mysql-master/sqlpp11-connector-mysql-master/build/CMakeFiles/CMakeTmp'
make: *** [Makefile:127: cmTC_9eab5/fast] Error 2

Source file was:
#include <pthread.h>

static void* test_func(void* data)
{
return data;
}

int main(void)
{
pthread_t thread;
pthread_create(&thread, NULL, test_func, NULL);
pthread_detach(thread);
pthread_cancel(thread);
pthread_join(thread, NULL);
pthread_atfork(NULL, NULL, NULL);
pthread_exit(NULL);

return 0;
}

`

Installation/Include Issues

How is this installed using CMake along side sqlpp11. I have sqlpp11 installed using the process described on the README on that github page but I am unable to install this project as I get the errors...

-- Using /usr/bin/c++ (compiler id: GNU)
CMake Error at CMakeLists.txt:46 (message):
  Can't find file date.h


Can't find date.h in /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../date 
Please either
  - git clone https://github.com/howardhinnant/date /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../date
  - download and unzip a current version from https://github.com/howardhinnant/date to /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../date
  - set DATE_INCLUDE_DIR to point to the dir containing date.h from the date library

CMake Error at CMakeLists.txt:60 (message):
  Can't find file sqlpp11/sqlpp11.h


Can't find sqlpp11/sqlpp11.h in /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../sqlpp11/include 
Please either
  - git clone https://github.com/rbock/sqlpp11 /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../sqlpp11/include
  - download and unzip a current version from https://github.com/rbock/sqlpp11 to /home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/../sqlpp11/include
  - set DATE_INCLUDE_DIR to point to the dir containing sqlpp11/sqlpp11.h

-- Configuring incomplete, errors occurred!
See also "/home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/build/CMakeFiles/CMakeOutput.log".
See also "/home/andrew/cpp_work/sqlpp11_libs/sqlpp11-connector-mysql/build/CMakeFiles/CMakeError.log".

enum/set support

./ddl2cpp -no-timestamp-warning ~/temp/test_enum.ddl ~/temp/tbl test_enum
testfile:

CREATE TABLE test_enum_set (
  oid int(11) NOT NULL DEFAULT '0',
  set_test set('test1', 'test2') NOT NULL DEFAULT '',
  enum_test enum('Yes','No') DEFAULT 'No'

) ENGINE=InnoDB DEFAULT CHARSET=cp1251;

results in:

Traceback (most recent call last):
  File "./ddl2cpp", line 184, in <module>
    traitslist = [NAMESPACE + '::' + types[sqlColumnType]];
KeyError: 'enum' #or KeyError 'set'

http://dev.mysql.com/doc/refman/5.7/en/constraint-enum.html
http://www.postgresql.org/docs/9.1/static/datatype-enum.html

Can't build DLL on windows

I try to use sqlpp11 on my development Windows machine, where I use Visual Studio to create C# .net core that use C++ DLL that use sqlpp11.
I managed to create Visual Studio project using:

cmake -G "Visual Studio 16 2019"

After few tweaks I managed to configure VS to produce a DLL for tests and windows dev, however I would like to make it easily (CLI) reproducible by other developers.
The command I was trying to use are:

cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=True -DCMAKE_INSTALL_PREFIX=C:\DataLayer\sqlpp11-connector-mysql\build\x64_Debug\lib -DDATE_INCLUDE_DIR=c:\DataLayer\date\include -DSQLPP11_INCLUDE_DIR=c:\DataLayer\sqlpp11\include "-DMYSQL_LIBRARY=C:\dev\mysql-connector-debug-x64\lib\libmysql.lib" "-DMYSQL_INCLUDE_DIR=C:\dev\mysql\include" ....

nmake /f Makefile MACHINE=x64 VC=19 install

The unfortunate outcome of this build is as followed:

connection_handle.cpp.obj : error LNK2019: unresolved external symbol mysql_init referenced in function "public: __cdecl sqlpp::mysql::detail::connection_handle_t::connection_handle_t(class std::shared_ptr<struct sqlpp::mysql::connection_config> const &)" (??0connection_handle_t@detail@mysql@sqlpp@@QEAA@AEBV?$shared_ptr@Uconnection_config@mysql@sqlpp@@@std@@@Z)
connection_handle.cpp.obj : error LNK2019: unresolved external symbol mysql_real_connect referenced in function "public: __cdecl sqlpp::mysql::detail::connection_handle_t::connection_handle_t(class std::shared_ptr<struct sqlpp::mysql::connection_config> const &)" (??0connection_handle_t@detail@mysql@sqlpp@@QEAA@AEBV?$shared_ptr@Uconnection_config@mysql@sqlpp@@@std@@@Z)
connection_handle.cpp.obj : error LNK2019: unresolved external symbol mysql_ping referenced in function "public: bool __cdecl sqlpp::mysql::detail::connection_handle_t::is_valid(void)" (?is_valid@connection_handle_t@detail@mysql@sqlpp@@QEAA_NXZ)
connection_handle.cpp.obj : error LNK2019: unresolved external symbol mysql_options referenced in function "public: __cdecl sqlpp::mysql::detail::connection_handle_t::connection_handle_t(class std::shared_ptr<struct sqlpp::mysql::connection_config> const &)" (??0connection_handle_t@detail@mysql@sqlpp@@QEAA@AEBV?$shared_ptr@Uconnection_config@mysql@sqlpp@@@std@@@Z)
connection_handle.cpp.obj : error LNK2019: unresolved external symbol mysql_close referenced in function "void __cdecl sqlpp::mysql::detail::handle_cleanup(struct MYSQL *)" (?handle_cleanup@detail@mysql@sqlpp@@YAXPEAUMYSQL@@@Z)
sqlpp-mysql.dll : fatal error LNK1120: 34 unresolved externals
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.22.27905\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.22.27905\bin\HostX86\x64\nmake.exe"' : return code '0x2'
Stop.

It's worth mentioning that when BUILD_SHARED_LIBS=False everything built smoothly.

BTW, very cool project.

best practice for managing db connection?

Dear:
The sample code on the project page shows a way to init a db connection

    auto config = std::make_shared<mysql::connection_config>();
    config->user = "root";
    config->database = "sqlpp_mysql";
    config->debug = true;
    mysql::connection db(config);

I am wondering if this is the standard way of calling this lib in real projects?
How can I address the issue of database connection pool for better resource reusing while using the sqlpp11-mysql-connector?

MSVC does not support and, or, etc in lieu of &&, ||, etc...

Hi,

Just downloaded the current version of sqlpp11-connector-mysql and tried to compile the tests with Visual Studio 2015 Update 2 and it fails because it does not yet support:

and, or, ..... instead of &&, || ...

The solution seems very simple: just #define these words. The only question: where is the best place? Do we create a separate .h and include it in all .h?

Regards,
Juan

How to return mysql auto incorrect when inserting a record in the table?

Dear, to return the field of auto increment of my table, currently I need to make a select with the data that were inserted to search for this information.

Somehow, it would be possible, when making an insertion, to return the line added in the database so that I can retrieve data such as auto increment fields and fields updated by internal triggers.

In my case, I need to return id AUTO_INCREMENT and created_time DATETIME

My actual code is:

int User::insertUser(const std::string &username, const std::string &password, const std::string &email)
{
    m_connection->insert(insert_into(m_userTable).set(
        m_userTable.username = username, m_userTable.password = password, m_userTable.email = email));
                
    const auto &row = m_connection->run(
        select(all_of(m_userTable)).from(m_userTable)
            .where(m_userTable.username == username and m_userTable.password == password and m_userTable.email == email)
    );
    return row.front().id;
}

mysql/connection_config.h operator==

bool operator==(const connection_config& other) const
      {
        return (other.host == host and other.user == user and other.password == password and
                  other.database == database /* redundant:
from http://dev.mysql.com/doc/refman/5.7/en/mysql-real-connect.html
  "db is the database name. If db is not NULL, the connection       
   sets the default database to this value."
I think it's a redundant check, one can connect to multiple databases 
using single connection
*/
                 and other.charset == charset and other.auto_reconnect == auto_reconnect and
                other.debug == debug);
      }

or database name must be optional argument

Memory leak if exception is thrown in connection constructor

connection::connection(const std::shared_ptr<connection_config>& config)
: _handle(new detail::connection_handle_t(config))
{
if (mysql_set_character_set(_handle->mysql.get(), _handle->config->charset.c_str()))
{
throw sqlpp::exception("MySQL error: can't set character set " + _handle->config->charset);
}
if (mysql_select_db(_handle->mysql.get(), _handle->config->database.c_str()))
{
throw sqlpp::exception("MySQL error: can't select database '" + _handle->config->database + "'");
}
}

_handle is init with a new object, but if an exception is thrown by the constructor this memory is not deleted due the fact C++ will not call the destructor due the invalid object creation.

Memory should delete in the constructor itself before throwing the exception.

How to obtain libraries mysqlclient and mysqlclient_r on UBUNTU 16.04?

While building sqlpp11-connector-mysql, I found the libraries mysqlclient and mysqlclient_r were missing on my ubuntu 16.04.
I am wondering which package should I install to obtain these two libraries.

Why do not use mariadb client instead of mysqlclient (just as what you did under MSVC)?

how can I set mysql options

Hi,

this is what I want to do

mysql_options(mysql_conn->_handle->mysql.get(), MYSQL_OPT_CONNECT_TIMEOUT,  &m_iOverTime);
mysql_options(mysql_conn->_handle->mysql.get(), MYSQL_OPT_READ_TIMEOUT,  &m_iOverTime);  
mysql_options(mysql_conn->_handle->mysql.get(), MYSQL_OPT_WRITE_TIMEOUT, &m_iOverTime);  

but _handle is private in sqlpp::mysql::connection, I cant find any public function to do this.

Merge develop master

Hello,
Could you please merge develop and master branches?

Thanks for the great lib!

Changes made --- yet not able to push changes

Hi Roland,

Got a new laptop and installed everything. Changes have been made to this project and have commited them in GitHub Desktop for Windows, yet when I choose Pull Request to join with Master, it tells me I don't have permission.

My branch is called "make-it-work-with-MSVC".

This is my first experience wiuth using GitHub for "group development" so please give me a small push here so I can share the changes...

Regards,
Juan Dent

database name not used

I downloaded today and it did not work out of the box.
I got the sql error: can not select db ' '

  1. I needed to modify the code in connection_handle.cpp from:
    if (!mysql_real_connect(mysql.get(), config->host.empty() ? nullptr : config->host.c_str(),
    config->user.empty() ? nullptr : config->user.c_str(),
    config->password.empty() ? nullptr : config->password.c_str(),
    nullptr , config->port,
    config->unix_socket.empty() ? nullptr : config->unix_socket.c_str(),
    config->client_flag))

to:
if (!mysql_real_connect(mysql.get(), config->host.empty() ? nullptr : config->host.c_str(),
config->user.empty() ? nullptr : config->user.c_str(),
config->password.empty() ? nullptr : config->password.c_str(),
config->database.empty() ? nullptr : config->database.c_str(),
config->port,
config->unix_socket.empty() ? nullptr : config->unix_socket.c_str(),
config->client_flag))

Why is the config->database variable not used?

Platform: windows.

Test with MySQL 5.7

I received an offline report saying that some of the current tests fail due to bad table layout.

Error when compiling

I compiled the code successfully yesterday, but today when I compile the newest version of code on branch master, I get the following error.

-- Using /usr/lib64/ccache/c++ (compiler id: GNU)
CMake Error at /usr/share/cmake3/Modules/FindPackageHandleStandardArgs.cmake:164 (message):
  MySQL_INCLUDE_DIR (missing: MySQL_LIBRARY)
Call Stack (most recent call first):
  /usr/share/cmake3/Modules/FindPackageHandleStandardArgs.cmake:445 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindMySQL.cmake:50 (find_package_handle_standard_args)
  CMakeLists.txt:40 (find_package)

-- Configuring incomplete, errors occurred!

I do not understand why it says I am missing MySQL_LIBRARAY, help.

Xcode 7.2 does not support thread_local => no way to build the MySQL connector for sqlpp11

Hi,

After much searching around, I have been stopped by the frustrating reality that Xcode 7.2 does not yet support thread_local variables and thus it is currently impossible to build "sqlpp11-connector-mysql-master". Connection.cpp uses this like so:

void execute_statement(detail::connection_handle_t& handle, const std::string& statement)
{
thread_local MySqlThreadInitializer threadInitializer;

    if (handle.config->debug)
      std::cerr << "MySQL debug: Executing: '" << statement << "'" << std::endl;

    if (mysql_query(handle.mysql.get(), statement.c_str()))
    {
      throw sqlpp::exception("MySQL error: Could not execute MySQL-statement: " +
                             std::string(mysql_error(handle.mysql.get())) + " (statement was >>" + statement +
                             "<<\n");
    }
  }

If someone knows a workaround, I would be deeply grateful! Such a shame for a great library...'

Thanks again,
Juan

Add support for the TIME datatype

Can not figure out how to do it myself. The TIME is just a HH:MM:SS type without a date part.
How to model it with std::chrono::... types?

build failed on linux

Hello, recently I get sqlpp11 and mysql-connector from github. And I try to build it on Linux but get a failed.
My work env likes: Linux VM-16-4-ubuntu 5.4.0-77-generic, g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, cmake version 3.16.3, tencent clound.
build error msg likes:

make -j4
[  3%] Building CXX object src/CMakeFiles/sqlpp-mysql.dir/connection.cpp.o
[  7%] Building CXX object src/CMakeFiles/sqlpp-mysql.dir/detail/connection_handle.cpp.o
[ 11%] Building CXX object src/CMakeFiles/sqlpp-mysql.dir/prepared_statement.cpp.o
In file included from /root/git_pro/sqlpp11-connector-mysql/src/connection.cpp:33:
/root/git_pro/sqlpp11-connector-mysql/include/sqlpp11/mysql/connection.h: In static member function ‘static sqlpp::mysql::connection::_context_t& sqlpp::mysql::connection::_serialize_interpretable(const T&, sqlpp::mysql::connection::_context_t&)’:
/root/git_pro/sqlpp11-connector-mysql/include/sqlpp11/mysql/connection.h:127:25: error: ‘serialize’ is not a member of ‘sqlpp’
  127 |         return ::sqlpp::serialize(t, context);
      |                         ^~~~~~~~~
/root/git_pro/sqlpp11-connector-mysql/include/sqlpp11/mysql/connection.h: In static member function ‘static sqlpp::mysql::connection::_context_t& sqlpp::mysql::connection::_interpret_interpretable(const T&, sqlpp::mysql::connection::_context_t&)’:
/root/git_pro/sqlpp11-connector-mysql/include/sqlpp11/mysql/connection.h:133:25: error: ‘serialize’ is not a member of ‘sqlpp’
  133 |         return ::sqlpp::serialize(t, context);
      |                         ^~~~~~~~~
In file included from /root/git_pro/sqlpp11-connector-mysql/include/sqlpp11/mysql/connection.h:314,
                 from /root/git_pro/sqlpp11-connector-mysql/src/connection.cpp:33:
/root/git_pro/sqlpp11-connector-mysql/include/sqlpp11/mysql/serializer.h: At global scope:
/root/git_pro/sqlpp11-connector-mysql/include/sqlpp11/mysql/serializer.h:36:10: error: ‘serializer_t’ is not a class template
   36 |   struct serializer_t<mysql::serializer_t, concat_t<First, Args...>>
      |          ^~~~~~~~~~~~
make[2]: *** [src/CMakeFiles/sqlpp-mysql.dir/build.make:89: src/CMakeFiles/sqlpp-mysql.dir/connection.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:133: src/CMakeFiles/sqlpp-mysql.dir/all] Error 2
make: *** [Makefile:141: all] Error 2

Can you help me? Thanks very much!

Prepared Statement Select does not call mysql_free_result

I have a couple of long living prepared statements. When i call a select prepared statement, its results apparently never call mysql_free_result, which causes other statements to fail with "Command out of sync" exceptions, even though the result instance has fallen out of scope.

Update and insert prepared statements do not seem to have issues. Could this be a bug or am i missing a mechanism to force a select prepared statement to release its mysql results?

Which supported datatype is best for handling money amounts?

Hi Roland,
As I am starting a small project to begin use of your library, I found decimal and numeric are not allowed data types (but they are the only that allow exact 2 decimal places for money amounts). I guess one could use double, but that is not exact.

I would like to know what you suggest.
Thanks!
Juan

undefined reference to `mysql_thread_safe'

I have the same issue as mentioned here: #22 (comment)

Since there is no solution provided in the link above, any help would be appreciated.

I have this libs installed on ubuntu 16.04:

dpkg -l|grep mysql
ii  libmysqlclient-dev          5.7.20-0ubuntu0.16.04.1               amd64        MySQL database development files
ii  libmysqlclient20:amd64      5.7.20-0ubuntu0.16.04.1               amd64        MySQL database client library
ii  libmysqlcppconn-dev         1.1.7-0ubuntu1                        amd64        MySQL Connector for C++ (development files)
ii  libmysqlcppconn7v5          1.1.7-0ubuntu1                        amd64        MySQL Connector for C++ (library)
ii  mysql-common                5.7.20-0ubuntu0.16.04.1               all          MySQL database common files, e.g. /etc/mysql/my.cnf
cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"

The full error log:

/usr/bin/c++   -std=c++11 -w -Wno-unknown-pragmas -Wno-sign-compare -Woverloaded-virtual -Wwrite-strings -Wno-unused -O3 -fopenmp  -rdynamic CMakeFiles/tep.dir/TEP/TEP2/main.cpp.o  -o tep -Wl,-rpath,/build/nomos-c/build:/usr/local/lib -lpthread nomos-c/build/libnomos-c.so -lmysqlclient /usr/local/lib/liblog4cpp.so /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_chrono.so /usr/local/lib/libboost_system.so /usr/local/lib/libboost_date_time.so /usr/local/lib/libboost_atomic.so /usr/local/lib/libcppnetlib-client-connections.a /usr/local/lib/libcppnetlib-server-parsers.a /usr/local/lib/libcppnetlib-uri.a -ltacopie -lcpp_redis -lmysqlclient -lsqlpp-mysql -lcurl -lpthread -lgsl -lblas -lrt -lpthread /usr/local/lib/libboost_thread.so /usr/local/lib/libboost_chrono.so /usr/local/lib/libboost_system.so /usr/local/lib/libboost_date_time.so /usr/local/lib/libboost_atomic.so -lssl -lcrypto 
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::MySqlThreadInitializer::MySqlThreadInitializer()':
connection.cpp:(.text+0xae): undefined reference to `mysql_thread_safe'
connection.cpp:(.text+0xe8): undefined reference to `mysql_thread_init'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::MySqlThreadInitializer::~MySqlThreadInitializer()':
connection.cpp:(.text+0x11b): undefined reference to `mysql_thread_end'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::execute_statement(sqlpp::mysql::detail::connection_handle_t&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0x23d): undefined reference to `mysql_query'
connection.cpp:(.text+0x281): undefined reference to `mysql_error'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::execute_prepared_statement(sqlpp::mysql::detail::prepared_statement_handle_t&)':
connection.cpp:(.text+0x48b): undefined reference to `mysql_stmt_bind_param'
connection.cpp:(.text+0x4b4): undefined reference to `mysql_stmt_error'
connection.cpp:(.text+0x542): undefined reference to `mysql_stmt_execute'
connection.cpp:(.text+0x56b): undefined reference to `mysql_stmt_error'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::(anonymous namespace)::prepare_statement(sqlpp::mysql::detail::connection_handle_t&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, unsigned long, unsigned long)':
connection.cpp:(.text+0x768): undefined reference to `mysql_stmt_init'
connection.cpp:(.text+0x81c): undefined reference to `mysql_stmt_prepare'
connection.cpp:(.text+0x860): undefined reference to `mysql_error'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::connection(std::shared_ptr<sqlpp::mysql::connection_config> const&)':
connection.cpp:(.text+0xae7): undefined reference to `mysql_set_character_set'
connection.cpp:(.text+0xba5): undefined reference to `mysql_select_db'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::select_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0xdd7): undefined reference to `mysql_store_result'
connection.cpp:(.text+0xe7c): undefined reference to `mysql_error'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::run_prepared_insert_impl(sqlpp::mysql::prepared_statement_t&)':
connection.cpp:(.text+0x1025): undefined reference to `mysql_stmt_insert_id'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::run_prepared_update_impl(sqlpp::mysql::prepared_statement_t&)':
connection.cpp:(.text+0x1063): undefined reference to `mysql_stmt_affected_rows'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::run_prepared_remove_impl(sqlpp::mysql::prepared_statement_t&)':
connection.cpp:(.text+0x10a1): undefined reference to `mysql_stmt_affected_rows'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::insert_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0x11a8): undefined reference to `mysql_insert_id'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::update_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0x122a): undefined reference to `mysql_affected_rows'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::remove_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
connection.cpp:(.text+0x127a): undefined reference to `mysql_affected_rows'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::connection::escape(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const':
connection.cpp:(.text+0x1327): undefined reference to `mysql_real_escape_string'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::detail::prepared_statement_handle_t::~prepared_statement_handle_t()':
connection.cpp:(.text._ZN5sqlpp5mysql6detail27prepared_statement_handle_tD2Ev[_ZN5sqlpp5mysql6detail27prepared_statement_handle_tD5Ev]+0x23): undefined reference to `mysql_stmt_close'
//usr/local/lib/libsqlpp-mysql.a(connection.cpp.o): In function `sqlpp::mysql::detail::result_handle::~result_handle()':
connection.cpp:(.text._ZN5sqlpp5mysql6detail13result_handleD2Ev[_ZN5sqlpp5mysql6detail13result_handleD5Ev]+0x23): undefined reference to `mysql_free_result'
//usr/local/lib/libsqlpp-mysql.a(char_result.cpp.o): In function `sqlpp::mysql::char_result_t::next_impl()':
char_result.cpp:(.text+0x944): undefined reference to `mysql_fetch_row'
char_result.cpp:(.text+0x966): undefined reference to `mysql_fetch_lengths'
//usr/local/lib/libsqlpp-mysql.a(bind_result.cpp.o): In function `sqlpp::mysql::bind_result_t::bind_impl()':
bind_result.cpp:(.text+0xf62): undefined reference to `mysql_stmt_bind_result'
bind_result.cpp:(.text+0xf93): undefined reference to `mysql_stmt_error'
//usr/local/lib/libsqlpp-mysql.a(bind_result.cpp.o): In function `sqlpp::mysql::bind_result_t::next_impl()':
bind_result.cpp:(.text+0x110b): undefined reference to `mysql_stmt_fetch'
bind_result.cpp:(.text+0x1375): undefined reference to `mysql_stmt_fetch_column'
bind_result.cpp:(.text+0x13a9): undefined reference to `mysql_stmt_error'
bind_result.cpp:(.text+0x14e0): undefined reference to `mysql_stmt_error'
//usr/local/lib/libsqlpp-mysql.a(connection_handle.cpp.o): In function `sqlpp::mysql::detail::connection_handle_t::connection_handle_t(std::shared_ptr<sqlpp::mysql::connection_config> const&)':
connection_handle.cpp:(.text+0x19c): undefined reference to `mysql_init'
connection_handle.cpp:(.text+0x220): undefined reference to `mysql_options'
connection_handle.cpp:(.text+0x3ce): undefined reference to `mysql_real_connect'
connection_handle.cpp:(.text+0x417): undefined reference to `mysql_error'
//usr/local/lib/libsqlpp-mysql.a(connection_handle.cpp.o): In function `sqlpp::mysql::detail::connection_handle_t::~connection_handle_t()':
connection_handle.cpp:(.text+0x56c): undefined reference to `mysql_close'
collect2: error: ld returned 1 exit status
CMakeFiles/tep.dir/build.make:112: recipe for target 'tep' failed
make[2]: *** [tep] Error 1
make[2]: Leaving directory '/build'
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/tep.dir/all' failed
make[1]: Leaving directory '/build'
make[1]: *** [CMakeFiles/tep.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2

Crash of queries due to MYSQL_RES that is NULL

Hello,

We encountered a crash in very special conditions that are hard to reproduce (we did not understand all the issue yet), leading to a NULL MYSQL_RES* and a crash when entering mysql_fetch_row with a NULL pointer, when doing a SELECT statement.

We found that the origin of the crash is the following:

    char_result_t connection::select_impl(const std::string& statement)
    {
      execute_statement(*_handle, statement);
      std::unique_ptr<detail::result_handle> result_handle(
          new detail::result_handle(mysql_store_result(_handle->mysql.get()), _handle->config->debug));
      if (!result_handle)
      {
        throw sqlpp::exception("MySQL error: Could not store result set: " +
                               std::string(mysql_error(_handle->mysql.get())));
      }

      return {std::move(result_handle)};
}

Given the following implementation of result_handle that contains an operator!(), the check if (!result_handle) should most likely be written if (!*result_handle) instead, because otherwise the operator!() used is the one of unique_ptr (with a check if the ptr is null - that does not make sense because the ptr is new-ed right above) instead of the one of result_handle that checks if MYSQL_RES is null.

Do you think this fix could be integrated?

Thank you,
Best regards,
Louis

Mac osX build

Hello,

I'm not able to build on macox 10.14.5. There is some strange error with boost 1.0.69.
MacBook:build $
cmake .. -DDATE_INCLUDE_DIR=../../date-2.4.1/include/ -DSQLPP11_INCLUDE_DIR=../../sqlpp11-0.58/include/ -DUSE_MARIADB=1

Apple XCode does not have thread_local, thus we need to wrap that via boost thread
-- Boost version: 1.69.0
-- Found the following Boost libraries:
-- thread
-- system
-- chrono
-- date_time
-- atomic
-- Using /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ (compiler id: AppleClang)
including date from /Users/m4gyars/Project/core2/setup/date-2.4.1/include
including sqlpp11 from /Users/m4gyars/Project/core2/setup/sqlpp11-0.58/include
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/m4gyars/Project/core2/setup/sqlpp11-connector-mysql-0.25/build

MacBook:build$ make && sudo make install
Scanning dependencies of target sqlpp-mysql
[ 4%] Building CXX object src/CMakeFiles/sqlpp-mysql.dir/connection.cpp.o
/Users/m4gyars/Project/core2/setup/sqlpp11-connector-mysql-0.25/src/connection.cpp:30:10: fatal error: 'boost/thread/tss.hpp' file not found
#include <boost/thread/tss.hpp> // libc++ does not have thread_local yet.
^~~~~~~~~~~~~~~~~~~~~~

1 error generated.
make[2]: *** [src/CMakeFiles/sqlpp-mysql.dir/connection.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/sqlpp-mysql.dir/all] Error 2
make: *** [all] Error 2

Any idea to solve this ?

Thanks

CMAKE 3.4.3 GIVES WARNING: POLICY CMP0054 NOT SET

When I run CMake 3.4.3 on the CMakeLists.txt file for this project I get the following warning and I am not sure if I should set policy CMP0054 or leave it unset...

Regards,
Juan

Warning is as follows:

CMake Warning (dev) at CMakeLists.txt:32 (if):
Policy CMP0054 is not set: Only interpret if() arguments as variables or
keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.

Quoted variables like "MSVC" will no longer be dereferenced when the policy
is set to NEW. Since the policy is not set the OLD behavior will be used.
This warning is for project developers. Use -Wno-dev to suppress it.

Data is truncated with MariaDB Connector/C 3.0.1+

When using MariaDB Connector/C 3.0.1 or newer the data is truncated because of this line

meta_data.bound_text_buffer.resize(8);

in bind_result_t::_bind_text_result, which will get just 8 characters from database and later will fail at

mysql_stmt_fetch_column(_handle->mysql_stmt, _handle->result_params.data() + r.index, r.index, 0);

in bind_result_t::next_impl() with error

MySQL: Fetch column after reallocate failed: error-code: 1, stmt-error: , stmt-errno: 2051

A possible fix would be to resize it to the cloumn's length

auto result_meta_data = mysql_stmt_result_metadata(_handle->mysql_stmt);
if (result_meta_data)
{
    auto fields = mysql_fetch_fields(result_meta_data);
    if (fields)
    {
        auto charset = mariadb_get_charset_by_nr(fields[index].charsetnr);
        meta_data.bound_text_buffer.resize(fields[index].length / charset->char_maxlen);
    }

    mysql_free_result(result_meta_data);
}

OS: Windows
Arch: x64
Compiler: MSVC++ 2017 (latest)
Standard: C++17
MariaDB version: 10.3.8 (Dockerized container, image mariadb:latest)
MariaDB Connector/C: 3.0.6

ddl2cpp issues

  1. does not work with default mysql's show create table because of '`' around table/column names
  2. does not recognize 'timestamp' column type

emplace & move constructor

maybe I'm missing something, but here's the question
I want to make a map<config, connection>, so I could manage different servers/users connections without making unneeded connections.
map.emplace(config, std::move(sqlpp::mysql::connection(config))) fails to compile saying (gcc 5.2):

error: use of deleted function ‘sqlpp::mysql::connection::connection(const sqlpp::mysql::connection&)’

How do I deal with this situation? Implement a move constructor?

parameter buffer is NULL for MYSQL_TYPE_STRING parameters!

Hi Roland,

Building with a debug build of MySQL I have found what I think is a bug. Looking at the following function you can verify that meta_data.bound_text_buffer.size() is 0. Or putting it another way, meta_data.bound_text_buffer.data() is NULL. This causes an assert violation inside mysql-5.7.12\mysql-5.7.12\libmysql\libmysql.c, line 4078, DBUG_ASSERT(param->buffer_length != 0);. Please see if you can confirm this...

void bind_result_t::_bind_text_result(size_t index, const char** value, size_t* len)
    {
      if (_handle->debug)
        std::cerr << "MySQL debug: binding text result at index: " << index << std::endl;

      detail::result_meta_data_t& meta_data = _handle->result_param_meta_data[index];
      meta_data.index = index;
      meta_data.len = len;
      meta_data.is_null = nullptr;
      meta_data.text_buffer = value;

      MYSQL_BIND& param = _handle->result_params[index];
      param.buffer_type = MYSQL_TYPE_STRING;
      param.buffer = meta_data.bound_text_buffer.data();
      param.buffer_length = meta_data.bound_text_buffer.size();
      param.length = &meta_data.bound_len;
      param.is_null = &meta_data.bound_is_null;
      param.is_unsigned = false;
      param.error = &meta_data.bound_error;
    }

Regards,
Juan

Not being able to compile

I downloaded this project and ran:

cmake CMakeLists.txt
make

and get this error:

Scanning dependencies of target sqlpp-mysql
[ 6%] Building CXX object src/CMakeFiles/sqlpp-mysql.dir/connection.cpp.o
In file included from /Users/juandent/Programs/C++/sqlpp11-connector-mysql-master/src/connection.cpp:30:
/Users/juandent/Programs/C++/sqlpp11-connector-mysql-master/src/detail/prepared_statement_handle.h:31:10: fatal error: 'mysql/mysql.h' file not
found

include <mysql/mysql.h>

     ^

1 error generated.

Any help will be greatly appreciated!!

Juan

How to create mysql::connection without config

I try to create class contain mysql::connection object:

class Database {

Database(std::shared_ptrmysql::connection_config config) {
// set config code ???
}

private:
mysql::connection db;
}

but i the error "error: no matching function for call to ‘sqlpp::mysql::connection::connection()’" at "mysql::connection db" line.

How do I initialize my db variable in Database constructor?
Thanks!

error compiling with VStudio 2015 update 2

Hi Roland,

The code

auto prepared_update = db.prepare(
        update(tab)
        .set(tab.colDayPoint = parameter(tab.colDayPoint)).unconditionally());

gives this compiler error:

**error C2440: 'static_cast': cannot convert from 
'const sqlpp::parameter_list_t<sqlpp::detail::type_vector<sqlpp::parameter_t<sqlpp::day_point,T>>>' 
to 
'TabDateTime_::ColDayPoint::_alias_t::_member_t<sqlpp::parameter_value_t<sqlpp::day_point>> &'
          with
          [
              T=sqlpp::column_t<TabDateTime,TabDateTime_::ColDayPoint>
          ]**

I have no idea why this is happening ...

Do you?

Regards,
Juan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.