Quantcast
Channel: MySQL Forums - Connector/C++
Viewing all 527 articles
Browse latest View live

windows example fails STRING TOO LONG (1 reply)

$
0
0
Hello,
I installed vs14 2015 linked to vs14 version of 2.0.3 prebuild library. I created a project with the exact source code from
http://dev.mysql.com/doc/dev/connector-cpp/devapi_ref.html

When I run the example, I got
Creating session on localhost, port 33060 ...
STD EXCEPTION: string too long
The exception happens at Impl::from_utf8(*this, utf8) where utf8="root".
// TODO: make utf8 conversions explicit

string(const char *other)
{
if (!other)
return;
std::string utf8(other);
--> Impl::from_utf8(*this, utf8);
}


catch (std::exception &ex)
{
cout << "STD EXCEPTION: " << ex.what() << endl;
return 1;
}

Would you please help?

driver->connect() Segmentation Fault (6 replies)

$
0
0
I could compile this code with no error messages. But when I execute the binary I get a segmentation fault error. The problem is in this line:

con = driver->connect("tcp://127.0.0.1:3306", "root", "*******");

I've tried a lot of things and I'm out of ideas. Even though compilation was ok, maybe I made a mistake there somehow.
If you can help me I will really appreciate it.

-----------------------------------------------------


#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace std;

int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' AS _message'..." << endl;

try {
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;

driver = sql::mysql::get_mysql_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "*******");

} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line "<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}

cout << endl;

return EXIT_SUCCESS;
}

CDK Error: unexpected message (no replies)

$
0
0
I've downloaded the mysql-connector-c++-2.0.3 source code and compiled it with cmake. After that, to test the code, I've compiled the files in the testapp directory using cmake. The MySQL57 service is installed and running. To test it I connected to it without problems through the MySQL Workbench. However when I run the devapi_test in the testapp directory it immediately catches an exception on the following line of code:
XSession sess("localhost", port, user, pwd);
The message from the exception is:
ERROR: CDK Error: unexpected message
The port, user, and password are exactly the same as those I used to connect through the Workbench, and the server is installed locally. The error message doesn't really help to figure out what I did wrong. Does anybody have any idea of how I can proceed?

How to fast fill table (1 reply)

$
0
0
I have table of flags of bitcoin blocks - if the are confirmed (stage 0,1,2)
Initially I must "Insert..Ignore" 450'000 rows of (key,0)
At start table can several records
567, 1
753, 2
where 567 and 753 are keys
I must do:
0,0
1,0
2,0
3,0
....
566, 0
567, 1
568, 0
....
753, 2
...
449999, 0
I try: (MySqlDB my class)
MySqlDB db(user, password);
for (int i = start; i < start + count; i++)
{
db.execute("insert ignore blocks_confirmed (block_height, mysql) values ("+to_string(i)+", 0)");
}

but is very slow about 30 minutes
I better way? I ask and get:
SELECT * FROM x;
test=> WITH RECURSIVE x AS
(
SELECT 1 AS a, 0 AS b, 0 AS c
UNION ALL
SELECT 1+a, b, c FROM x WHERE a<100000
)
SELECT * FROM x;

But how to implement in code with C++ connector?

VS 2015 - C++ Connector 1.1.8, unresolved external symbol - get_driver_instance (1 reply)

$
0
0
Hi,

I am very new to C++ so this is probably down to a lack of experience on my part but after working through lots of issues and Google solutions, I have now got to the end of a very frustrating day with just one error left.

LNK2001 unresolved external symbol "class sql::mysql::MySQL_Driver * __cdecl sql::mysql::get_driver_instance(void)" (?get_driver_instance@mysql@sql@@YAPEAVMySQL_Driver@12@XZ) mysql-connector-c++-1.1.8-console E:\VisualStudio\mysql-connector-c++-1.1.8-console\mysql-connector-c++-1.1.8-console\mysql-connector-c++-1.1.8-console\mysql-connector-c++-1.1.8-console.obj 1

I have "E:\VisualStudio\mysql-connector-c++-noinstall-1.1.8-winx64\mysql-connector-c++-noinstall-1.1.8-winx64\lib" & "C:\Program Files\MySQL\MySQL Connector.C 6.1\lib" in my linker additional libs.

I am compiling as x64 Release and have no specific PreProcessor settings above the standard Win32 ones.

NDEBUG
_CONSOLE
_UNICODE
UNICODE

I have tried rebuilding the C++ connector but my activity with cmake did not go well... at all.

I am using;
VS 2015 Community Update 3
MySQL Community 5.7.15
C connector 6.1.6
C++ connector 1.1.8 (installed and src files).
Boost 1.63.0

Any thoughts or suggestions please.

VS 2015 - C++ Connector 1.1.8 - needs to have dll-interface (no replies)

$
0
0
I am trying to build the MySQL C++ connector 1.1.8 from src and have made some headway. I am now down to 28 errors and 403 warnings :-/.

Most of the Warnings are like

Warning C4251 'sql::SQLException::sql_state': class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'sql::SQLException' test_framework E:\VisualStudio\mysql-connector-c++-1.1.8\cppconn\exception.h 61

And the errors are like

Error C2282 'testsuite::TestCase<testsuite::classes::art_resultset::TestSuiteClass>::~TestCase' cannot override 'testsuite::Test::~Test' test_art_resultset e:\visualstudio\mysql-connector-c++-1.1.8\test\framework\test_case.h

I am guessing something to do with static / dynamic linking but am not sure where to look.

The other thread I have posted today is about trying to compile the example program to use this connector, hence now trying to also recompile the connector itself. The original threads title could have been clearer though.

I have managed to compile the 6.1.9 C Connector with only some warnings (mainly datatype to different datatype risks dataloss).

I have also corrected cmake putting in unquoted c:\program files all over the make files but these errors still persist.

Any help / suggestions ?.

Declaring user variable into database using mysql connector c++ (2 replies)

$
0
0
Hello to Everyone,

I am developping a software using c++ and MySQL(for the database). I am currently having the issue that I don't find anything online on how to define
user variables like "@returnValue". Since I want like in all my previous experiences to keep a return status to all my call procedures, I would really like for consistency to have a solution for this. I am also under the impression that many other will have the same questions as they seem to be some links on Google for MySQl Connector/Net but not for c++.
I have tried lines similar to the following:

"SET @ReturnValue ='';"
or
"SET @ReturnValue = STR_TO_DATE('2021-5-13 3:5:9','%Y-%m-%d %H:%i:%S');

They work fine using a mysql console client but not when executing these statements (or prepared statements) under c++.
Have somebody found a workaround or solution for this!?

Thanks a lot in advance!

Armand

I need MInGW libraries (no replies)

$
0
0
mysqlcppconn.lib is in c:\Program Files\MySQL\Connector.C++ 1.1\lib\opt\
but this library is for Visual Studio (only?)
Are possible library for MinGW for CodeBLocks for Windows?

Missing config.h (no replies)

$
0
0
Hi
I´m trying to setup a mysql Environment from scratch. I Think that I have installed Everything correct. All paths in Visual Studio 2015 is there.
- Server 5.7
- MySQL Connector C 6.1
- Code_mysql-connector-c++-1.1.8


I've got an error telling me:
"cannot open source file "config.h"
\Code_mysql-connector-c++-1.1.8\cppconn\resultset.h 30 IntelliSense

I cannot find the config.h anywhere. Where should it be found?

GCC G++/C++ Connect to MySQL on Windows 8.1 (Cygwin) (no replies)

$
0
0
Working on the following example, please help connect to MySQL using G++/C++.

https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-examples-complete-example-1.html

$ gcc --version
gcc.exe (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version
g++.exe (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ c++ --version
c++.exe (tdm64-1) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Aspire@Acer MINGW64 /e/Working/SQL/MySQL/C++
$ g++ -o Example1 Example1.cpp \
> -I /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/boost_1_63_0 \
> -I/e/Working/SQL/MySQL/C++/mysql-connector-c++-noinstall-1.1.8-winx64/include \
> -I/e/Working/SQL/MySQL/C++/mysql-connector-c++-noinstall-1.1.8-winx64/include/cppconn \
> -L/e/Working/SQL/MySQL/C++/mysql-connector-c++-noinstall-1.1.8-winx64/lib/mysqlcppconn
C:\Users\Aspire\AppData\Local\Temp\ccLMCyTM.o:Example1.cpp:(.text+0x4f): undefined reference to `__imp_get_driver_instance'
collect2.exe: error: ld returned 1 exit status


Hence, tried C++ Connector installation from source as in the following: (Installed Boost/CMake/Make) successfully. However, got stuck with the "make clean" step, refer to the following:

https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-installation-source-prerequisites.html

Boost is installed:

http://www.boost.org/doc/libs/1_63_0/more/getting_started/unix-variants.html

$ c++ -I /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/boost_1_63_0 \
> /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/example.cpp \
> -o /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/example \
> /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/boost_1_63_0/Boost-Build/boost/bin.v2/libs/regex/build/gcc-mingw-5.1.0/release/link-static/threading-multi/libboost_regex-mgw51-mt-1_63.a

$ ./example.exe < /e/Working/SQL/MySQL/C++/Boost/Unix-Variants/jayne.txt
Will Success Spoil Rock Hunter?

https://dev.mysql.com/doc/connector-cpp/en/connector-cpp-installation-source-unix.html

"C:\Program Files\CMake\bin\cmake.exe" -G "MinGW Makefiles" -DWITH_BOOST="E:\Working\SQL\MySQL\C++\Boost\Unix-Variants\boost_1_63_0"

E:\Working\SQL\MySQL\C++>git clone https://github.com/mysql/mysql-connector-cpp
Cloning into 'mysql-connector-cpp'...
remote: Counting objects: 16511, done.
remote: Total 16511 (delta 0), reused 0 (delta 0), pack-reused 16511
Receiving objects: 100% (16511/16511), 7.77 MiB | 610.00 KiB/s, done.
Resolving deltas: 100% (13018/13018), done.
Checking connectivity... done.
Checking out files: 100% (739/739), done.

E:\Working\SQL\MySQL\C++>cd mysql-connector-cpp

E:\Working\SQL\MySQL\C++\mysql-connector-cpp>"C:\Program Files\CMake\bin\cmake.exe" -G "MinGW Makefiles" -DWITH_BOOST="E:\Working\SQL\MySQL\C++\Boost\Unix-Varia
nts\boost_1_63_0"
-- The C compiler identification is GNU 5.1.0
-- The CXX compiler identification is GNU 5.1.0
-- Check for working C compiler: C:/TDM-GCC-64/bin/gcc.exe
-- Check for working C compiler: C:/TDM-GCC-64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/TDM-GCC-64/bin/g++.exe
-- Check for working CXX compiler: C:/TDM-GCC-64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
Building on system: Windows-6.3.9600 (AMD64)
Using cmake generator: MinGW Makefiles
Using 64bit generator
Building shared connector library
-- Boost version: 1.63.0
Configuring CDK as part of MySQL_CONCPP project
WITH_TESTS: OFF
CDK include path: E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/include;E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/include
-- Performing Test HAVE_MOVE_SEMANTICS
-- Performing Test HAVE_MOVE_SEMANTICS - Failed
-- Boost version: 1.63.0
Configuring Protobuf build using cmake generator: MinGW Makefiles
-- The C compiler identification is GNU 5.1.0
-- The CXX compiler identification is GNU 5.1.0
-- Check for working C compiler: C:/TDM-GCC-64/bin/gcc.exe
-- Check for working C compiler: C:/TDM-GCC-64/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/TDM-GCC-64/bin/g++.exe
-- Check for working CXX compiler: C:/TDM-GCC-64/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE
Using pthreads for protobuf code
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/protobuf
Protobuf include path: E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/protobuf/protobuf-2.6.0/src
WITH_SSL: OFF
-- Performing Test HAVE_STATIC_ASSERT
-- Performing Test HAVE_STATIC_ASSERT - Failed
-- Performing Test HAVE_IS_SAME
-- Performing Test HAVE_IS_SAME - Failed
-- Performing Test HAVE_SHARED_PTR
-- Performing Test HAVE_SHARED_PTR - Failed
-- Looking for sys/endian.h
-- Looking for sys/endian.h - not found
-- Looking for sys/byteorder.h
-- Looking for sys/byteorder.h - not found
-adding static library: cdk_mysqlx_objs
-adding static library: cdk_proto_mysqlx_objs
-adding static library: cdk_foundation_objs
-adding static library: cdk_parser_objs
Merging static libraries into cdk:
- cdk
- protobuf-lite
- cdk_mysqlx_objs
- cdk_proto_mysqlx_objs
- cdk_foundation_objs
- cdk_parser_objs
Wrote configuration header: E:/Working/SQL/MySQL/C++/mysql-connector-cpp/cdk/include/mysql/cdk/config.h
Connector library name: mysqlcppconn2
Connector library will be installed at: lib64
Install location: C:/Users/Aspire/MySQL/MySQL Connector C++ 2.0
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Working/SQL/MySQL/C++/mysql-connector-cpp


E:\Working\SQL\MySQL\C++\mysql-connector-cpp>"C:\Program Files (x86)\GnuWin32\bin\make.exe" clean
cdk/parser/CMakeFiles/cdk_parser.dir/flags.make:6: *** missing separator. Stop.
make[1]: *** [cdk/parser/CMakeFiles/cdk_parser.dir/clean] Error 2
make: *** [clean] Error 2

Please help fix the error.

In a nutshell, how to connect to MySQL using g++/c++ and (not VC++) on Windows without any IDE, the development "environment" being Git Bash/Notepad/MySQL 5.7.14, for Win64 (x86_64)

Thanks

C++ Visual Studio 2008 with mySQL (no replies)

$
0
0
Is it possible to connect a C++ Visual Studio 2008 project to a mySQL database? If so, could somebody please be kind enough to offer some guidance?

Please note, I am using Visual Studio 2008. Is this version still supported? If so, can I download the connector and correct mySQL version from mysql.com?

Kind Regards
Sam

ODBC connector use the SQLBindingParameter error (no replies)

$
0
0
I use the ODBC to connet the mysql server.
But when I use the SQLBindingParameter to bind a output data ,mysql return error code 1414.
Like this:
[MySQL][ODBC 5.3(w) Driver][mysqld-5.7.17-log]OUT or INOUT argument 3 for routine ????.user_login is not a variable or NEW pseudo-variable in BEFORE trigger (1414)

the procedure is under:
CREATE DEFINER=`root`@`localhost` PROCEDURE `user_login`(in user_name varchar(45),in user_password varchar(45),out status_code integer)
BEGIN
declare sel_result integer;
declare sel_pass varchar(45);
select count(*) into sel_result from account where Account_Name=user_name;
if sel_result=0 then
set status_code=0;
else
select Account_Password into sel_pass from account where Account_Name=user_name;
if sel_pass=user_password then
set status_code=1;
else
set status_code=2;
end if;
end if;
END


and the c++ program is under:

short status;
SQLINTEGER nameId = SQL_NTS;
RetCode = SQLBindParameter(hStmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 45, 0, (SQLPOINTER)name.c_str(), name.size(), &nameId);
if (RetCode != SQL_SUCCESS) {
HandleDiagnosticRecord(hStmt, SQL_HANDLE_STMT, RetCode);
}
RetCode = SQLBindParameter(hStmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 45, 0, (SQLPOINTER)password.c_str(), password.size(), &nameId);
RetCode = SQLBindParameter(hStmt, 3, SQL_PARAM_OUTPUT, SQL_C_SSHORT, SQL_INTEGER, 10, 0, &status, sizeof(char), &nameId);
if (RetCode != SQL_SUCCESS) {
HandleDiagnosticRecord(hStmt, SQL_HANDLE_STMT, RetCode);
}
RetCode = SQLPrepare(hStmt, L"{call user_login(?,?,?) }", SQL_NTS);
if (RetCode != SQL_SUCCESS) {
HandleDiagnosticRecord(hStmt, SQL_HANDLE_STMT, RetCode);
}
RetCode = SQLExecute(hStmt);
if (RetCode != SQL_SUCCESS) {
HandleDiagnosticRecord(hStmt, SQL_HANDLE_STMT, RetCode);
}

Connector/C++ (1.1.7 and 1.1.8) : crashes on executeQuery and execute in Visual Studio 2012 (1 reply)

$
0
0
Hi everyone,

I am pretty new to mysql, but after few hours of research on the Internet I didn't find a solution to my problem.

I installed Mysql (server 5.7 and connector/c++) and configured a first database with one table.

However, following the tutorial, my program crash completely when I try to use execute or executeQuery.

Here is the code :

sql::mysql::MySQL_Driver *driver;
sql::Connection *connection;
sql::Statement *stmt;

driver = sql::mysql::get_mysql_driver_instance();
connection = driver->connect("tcp://127.0.0.1:3306", "root" , "123");
stmt = connection->createStatement();
stmt->executeQuery("USE myDatabase");
stmt->executeQuery("INSERT INTO myTable VALUES (NULL, 1, 307 , 'S')");

It crashes at the first execute (USE...)

As it's pretty basic so I don't get why it doesn't work. The include and dll/lib are correctly linked. As a proof, after creating the connection and using isValid() method works well and confirms there is a connection.

Thank you for your help

socket creation when library is loaded (no replies)

$
0
0
Hi

I have a custom c++ application that uses mysql-connector-c++/1.1.5 as a shared object to communicate with our db.

I saw in the debugger that when I run my program, when the library gets loaded it tries to create a linux socket. Even before main() of my application has been called. It looks like that there is some code in the _init() section of the library.

Can someone throw some light on what exactly is the library trying to do here?
I want to defer these socket calls till after main() has been called. Is there a way to do that?

I am running on Linux SL 7.

Thanks
Ankit Pradhan

LIbrary (no replies)

$
0
0
Higuys ... i am new to MySQL . Can you please tel me if we can My SQL library as we can see library functions in c and c++

Use Cross ToolChain in OS X to build source code for ARM platform (no replies)

$
0
0
I download the source code from github.
use ccmake. to configure cross toolchain paths.
generate makefile
use make to build, but failed.

are there any suggestion for this condition?

Thanks.

Segmentation fault in prepared statement when using from concurrent threads (no replies)

$
0
0
Hi,
I am seeing this behavious frequently.Either i am getting a segmentation fault when i am creating a new connnection.(I have seen it in a post that get_driver_instance() isnt thread safe so cannot be fired at the same time from concurrent threads so i have implemented a lock there).But frequently i am seeing segmentation fault in preparesStatement function and i am confused as to how to solve this issue.
Thanks,
Kushal

Getting Rows Matched for Update with non-affected rows (no replies)

$
0
0
When doing an update, if there are no changed rows, but there are matched rows, there does not appear a way to get this information. I'm not sure if it's buried deep inside, like related to field_count, for example.

From what I can see with the C documentation, that SDK has a means to derive this info.

I was planning on using that information to verify the update itself was a properly matched statement (as opposed to a non-existent record).

If there any planned support for this?

MySQL Connector/C++ versions compatible with MySQL server versions 5.5, 5.6 and 5.7 (no replies)

$
0
0
Hi All,

We are an enterprise trying to build a backup and restore solution for MySQL. We plan to use Connector/C++ API to perform locking and run some queries on MySQL DB. Our software is going to provide support for MySQL versions 5.5.5 and above.

Could anyone provide me info on what MySQL Connector/C++ versions are compatible with MySQL server versions 5.5, 5.6 and 5.7 ? Is there a single version of Connector/C++ that I can use with all the above versions ?

Also our software is going to be developed on Linux (RHEL 5 & above and SLES 11 SP4 & above).

Thanks.
Archana

error: undefined ref 'get_driver_instance' (no replies)

$
0
0
Hello,

I've just installed:
mysql-connector-c++-1.1.6-linux-el6-x86-64bit.rpm and copied a simple
program from the MySQL site. When I build the project I get the error
mentioned in the title.

I started with MySQL-connector-c++-1.1.7. First with the rpm only, then I
downloaded the tar file and built it up starting with cmake ect...

Haven't been able to solve this problem on my own and would greatly appreciate
any suggestions.

Thank you,
Jeff
Viewing all 527 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>