LINUX.ORG.RU

Mysq cppconn


0

0

доброе времени суток. ПОдскажите в чем проблема... есть код...

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <stdarg.h>
 
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
 
using namespace std;
 
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
 
int main(int argc, char *argv[]) 
{
        string mphone;
 
        try {
                driver = get_driver_instance();
                con = driver->connect("tcp://127.0.0.1:3306", "xxx", "xxx");
                con->setSchema("test2");
 
                /* получаем номер телефона для отправки смс */
                stmt = con->createStatement();   //SUBSTRING_INDEX(value, ':', 1) as val
                res = stmt->executeQuery("SELECT DRV_MPHONE FROM DRIVER");
                while (res->next())
                {
                        mphone = res->getString("DRV_MPHONE");
                }
                delete res;
                delete stmt;
                delete con;    
        } 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;      
        }
 
        return 0;
}
 


Последнее исправление: vscorpion (всего исправлений: 1)

компилится все безупречно. Но как только я присваиваю переменной String значение из базы переменная VARCHAR то вылетает ошибка

test:/home/project/utils# ./tmp
*** glibc detected *** ./tmp: munmap_chunk(): invalid pointer: 0x00000000015e78c0 ***
======= Backtrace: =========
/lib/libc.so.6[0x7f3013ccf928]
/usr/lib/libstdc++.so.6(_ZNSs6assignERKSs+0x8f)[0x7f30144ee8ef]
./tmp[0x401410]
/lib/libc.so.6(__libc_start_main+0xe6)[0x7f3013c7a1a6]
./tmp(_ZNSt8ios_base4InitD1Ev+0x41)[0x400e09]
======= Memory map: ========
00400000-00402000 r-xp 00000000 08:01 885612                             /home/project/utils/tmp
00602000-00603000 rw-p 00002000 08:01 885612                             /home/project/utils/tmp
015e6000-01607000 rw-p 015e6000 00:00 0                                  [heap]
41000000-41001000 ---p 41000000 00:00 0
41001000-41801000 rw-p 41001000 00:00 0
7f3012cb0000-7f3012cba000 r-xp 00000000 08:01 977710                     /lib/libnss_files-2.7.so
7f3012cba000-7f3012eba000 ---p 0000a000 08:01 977710                     /lib/libnss_files-2.7.so
7f3012eba000-7f3012ebc000 rw-p 0000a000 08:01 977710                     /lib/libnss_files-2.7.so
7f3012ed1000-7f3012f0c000 r-xp 00000000 08:01 974893                     /lib/libncurses.so.5.7
7f3012f0c000-7f301310b000 ---p 0003b000 08:01 974893                     /lib/libncurses.so.5.7
7f301310b000-7f3013110000 rw-p 0003a000 08:01 974893                     /lib/libncurses.so.5.7
7f3013110000-7f30131d3000 r-xp 00000000 08:01 24876                      /usr/lib/libstdc++.so.5.0.7
7f30131d3000-7f30133d2000 ---p 000c3000 08:01 24876                      /usr/lib/libstdc++.so.5.0.7
7f30133d2000-7f30133da000 rw-p 000c2000 08:01 24876                      /usr/lib/libstdc++.so.5.0.7
7f30133da000-7f30133ec000 rw-p 7f30133da000 00:00 0
7f30133ec000-7f3013401000 r-xp 00000000 08:01 977723                     /lib/libnsl-2.7.so
7f3013401000-7f3013600000 ---p 00015000 08:01 977723                     /lib/libnsl-2.7.so
7f3013600000-7f3013602000 rw-p 00014000 08:01 977723                     /lib/libnsl-2.7.so
7f3013602000-7f3013604000 rw-p 7f3013602000 00:00 0
7f3013604000-7f301361a000 r-xp 00000000 08:01 977727                     /lib/libpthread-2.7.so
7f301361a000-7f301381a000 ---p 00016000 08:01 977727                     /lib/libpthread-2.7.so
7f301381a000-7f301381c000 rw-p 00016000 08:01 977727                     /lib/libpthread-2.7.so
7f301381c000-7f3013820000 rw-p 7f301381c000 00:00 0
7f3013820000-7f3013822000 r-xp 00000000 08:01 977715                     /lib/libdl-2.7.so
7f3013822000-7f3013a22000 ---p 00002000 08:01 977715                     /lib/libdl-2.7.so
7f3013a22000-7f3013a24000 rw-p 00002000 08:01 977715                     /lib/libdl-2.7.so
7f3013a24000-7f3013a2c000 r-xp 00000000 08:01 977722                     /lib/libcrypt-2.7.so
7f3013a2c000-7f3013c2c000 ---p 00008000 08:01 977722                     /lib/libcrypt-2.7.so
7f3013c2c000-7f3013c2e000 rw-p 00008000 08:01 977722                     /lib/libcrypt-2.7.so
7f3013c2e000-7f3013c5c000 rw-p 7f3013c2e000 00:00 0
7f3013c5c000-7f3013da6000 r-xp 00000000 08:01 977724                     /lib/libc-2.7.so
7f3013da6000-7f3013fa5000 ---p 0014a000 08:01 977724                     /lib/libc-2.7.so
7f3013fa5000-7f3013fa8000 r--p 00149000 08:01 977724                     /lib/libc-2.7.so
7f3013fa8000-7f3013faa000 rw-p 0014c000 08:01 977724                     /lib/libc-2.7.so
7f3013faa000-7f3013faf000 rw-p 7f3013faa000 00:00 0
7f3013faf000-7f3013fc5000 r-xp 00000000 08:01 974851                     /lib/libgcc_s.so.1
7f3013fc5000-7f30141c5000 ---p 00016000 08:01 974851                     /lib/libgcc_s.so.1
7f30141c5000-7f30141c6000 rw-p 00016000 08:01 974851                     /lib/libgcc_s.so.1
7f30141c6000-7f3014248000 r-xp 00000000 08:01 977729                     /lib/libm-2.7.so
7f3014248000-7f3014447000 ---p 00082000 08:01 977729                     /lib/libm-2.7.so
7f3014447000-7f3014449000 rw-p 00081000 08:01 977729                     /lib/libm-2.7.so
7f3014449000-7f301453a000 r-xp 00000000 08:01 262655                     /usr/lib/libstdc++.so.6.0.10
7f301453a000-7f3014739000 ---p 000f1000 08:01 262655                     /usr/lib/libstdc++.so.6.0.10
7f3014739000-7f301473f000 r--p 000f0000 08:01 262655                     /usr/lib/libstdc++.so.6.0.10
7f301473f000-7f3014742000 rw-p 000f6000 08:01 262655                     /usr/lib/libstdc++.so.6.0.10
7f3014742000-7f3014755000 rw-p 7f3014742000 00:00 0
7f3014755000-7f3014763000 r-xp 00000000 08:01 8975                       /usr/lib/libboost_date_time.so.1.35.0
7f3014763000-7f3014963000 ---p 0000e000 08:01 8975                       /usr/lib/libboost_date_time.so.1.35.0
7f3014963000-7f3014964000 rw-p 0000e000 08:01 8975                       /usr/lib/libboost_date_time.so.1.35.0
7f3014964000-7f3014baf000 r-xp 00000000 08:01 8913                       /usr/lib/libmysqlcppconn.so.1.0.5
7f3014baf000-7f3014cae000 ---p 0024b000 08:01 8913                       /usr/lib/libmysqlcppconn.so.1.0.5
7f3014cae000-7f3014cf6000 rw-p 0024a000 08:01 8913                       /usr/lib/libmysqlcppconn.so.1.0.5
7f3014cf6000-7f3014cf8000 rw-p 7f3014cf6000 00:00 0
7f3014cf8000-7f3014da1000 r-xp 00000000 08:01 8944                       /usr/lib/libibpp.so
7f3014da1000-7f3014fa0000 ---p 000a9000 08:01 8944                       /usr/lib/libibpp.so
7f3014fa0000-7f3014fa5000 rw-p 000a8000 08:01 8944                       /usr/lib/libibpp.so
7f3014fa5000-7f3014fc1000 r-xp 00000000 08:01 977718                     /lib/ld-2.7.so
7f3014fd2000-7f3014fd7000 rw-p 7f3014fd2000 00:00 0
7f3014fd7000-7f301507f000 r-xp 00000000 08:01 1949821                    /opt/firebird/lib/libfbclient.so.2.1.2
7f301507f000-7f301517f000 ---p 000a8000 08:01 1949821                    /opt/firebird/lib/libfbclient.so.2.1.2
7f301517f000-7f301518d000 rw-p 000a8000 08:01 1949821                    /opt/firebird/lib/libfbclient.so.2.1.2
7f301518d000-7f30151a8000 rw-p 7f301518d000 00:00 0
7f30151ad000-7f30151c0000 rw-p 7f30151ad000 00:00 0
7f30151c0000-7f30151c2000 rw-p 0001b000 08:01 977718                     /lib/ld-2.7.so
7fff1d1ad000-7fff1d1c2000 rw-p 7ffffffea000 00:00 0                      [stack]
7fff1d1ff000-7fff1d200000 r-xp 7fff1d1ff000 00:00 0                      [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Аварийный останов
 

подскажите в чем может быть дело...

test:/home/project/utils# make
g++ -DIBPP_LINUX -I./include/boost -I/usr/include/cppconn  -I/usr/include/ibpp  -L./boost/lib -L/usr/lib -libpp -lmysqlcppconn -lboost_date_time  tmp.cpp   -o tmp
/usr/bin/ld: warning: libstdc++.so.5, needed by /usr/lib/libmysqlcppconn.so, may conflict with libstdc++.so.6

версия cppconn 1.0.5 g++4.3 gcc-4.3 система debian 5

файл makefile

#=================================================================================================
#       Make for Bill
#
#=================================================================================================
 
CXX := g++ -DIBPP_LINUX
# -DMYSQLCPPCONN_TRACE_ENABLE
CXXFLAGS := -I./include/boost -I/usr/include/cppconn  -I/usr/include/ibpp
# -I/usr/include/mysql 
# -I./include/soci
#CXXFLAGS := -I/usr/include/mysql -I/usr/local/include/mysql++
#CXXFLAGS := -I/usr/include/mysql
#CXXFLAGS := -I/usr/include/mysql -I/usr/include/cppconn 
#LDFLAGS := -L/usr/local/lib -lmysqlpp -lmysqlclient -lnsl -lz -lm
#LDFLAGS := -L/usr/local/lib -lmysqlclient -lnsl -lz -lm
#LDFLAGS := -L /usr/local/mysql/lib/ -L ../cppconn/ -lmysqlclient -lmysqlcppconn -lmysqlclient -lnsl -lz -lm
LDFLAGS := -L./boost/lib -L/usr/lib -libpp -lmysqlcppconn -lboost_date_time
# -lboost_date_time -lboost_regex-mt
# -lboost_thread-mt
# -lmysqlclient
# -lsoci_core -lsoci_mysql -ldl
#-lboost_regex-mt
# -lboost_thread-mt -lboost_regex -lnsl -lz -lm
EXECUTABLE := main
 
all: tmp
clean:
        rm -f tmp *.o

заранее спасибо

vscorpion
() автор топика
Ответ на: комментарий от vscorpion

/usr/bin/ld: warning: libstdc++.so.5, needed by /usr/lib/libmysqlcppconn.so, may conflict with libstdc++.so.6

mysqlcppcon пересобери. он, похоже, у тебя не к той libstdc++ прилинкован

Sectoid ★★★★★
()
Ответ на: комментарий от Sectoid

Подскажите, пожалуйста где взять исходники mysqlcppconn? у мен ятолько бинарник. Спасибо.

vscorpion
() автор топика
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.