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

Running multiple sql querrys in single execSqlSync throws bad_function_call #582

Open
L0ric0 opened this issue Sep 18, 2020 · 2 comments
Open

Comments

@L0ric0
Copy link
Contributor

L0ric0 commented Sep 18, 2020

Describe the bug
when doing multiple sql statements in one execSqlSync call a std::bad_function_call is thrown after the sql did run (at some point i am unable to figure out as i am unable to catch it)

To Reproduce
minimalistic program to reproduce:

#include <drogon/drogon.h>

int main(int argc, char* argv[]){
        std::shared_ptr<drogon::orm::DbClient> db_con = drogon::orm::DbClient::newPgClient("connection parameter", 10);

        //both of the tables will be created
        auto res = db_con->execSqlSync("CREATE TABLE IF NOT EXISTS test1(blub TEXT); CREATE TABLE IF NOT EXISTS test2(blubber TEXT);");
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)
project(drogon-issue VERSION 0.0.1)

add_executable(drogon-issue test.cpp)

find_package(Drogon REQUIRED)
target_link_libraries(drogon-issue PRIVATE ${DROGON_LIBRARIES})
target_include_directories(drogon-issue PRIVATE ${DROGON_INCLUDE_DIRS})

Expected behavior
no exception is thrown

Log

terminate called after throwing an instance of 'std::bad_function_call'
  what():  bad_function_call
Abgebrochen (Speicherabzug geschrieben)

Backtrace

#0  0x00007ffff7408615 in raise () from /usr/lib/libc.so.6
#1  0x00007ffff73f1862 in abort () from /usr/lib/libc.so.6
#2  0x00007ffff778a86a in __gnu_cxx::__verbose_terminate_handler () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/vterminate.cc:95
#3  0x00007ffff7796d9a in __cxxabiv1::__terminate (handler=<optimized out>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:48
#4  0x00007ffff7796e07 in std::terminate () at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_terminate.cc:58
#5  0x00007ffff77970ae in __cxxabiv1::__cxa_throw (obj=<optimized out>, tinfo=tinfo@entry=0x7ffff78c43b0 <typeinfo for std::bad_function_call>, dest=dest@entry=0x7ffff77c1520 <std::bad_function_call::~bad_function_call()>) at /build/gcc/src/gcc/libstdc++-v3/libsupc++/eh_throw.cc:95
#6  0x00007ffff778d7ac in std::__throw_bad_function_call () at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/exception.h:63
#7  0x0000555555632450 in drogon::orm::PgConnection::handleRead() ()
#8  0x0000555555678c48 in trantor::Channel::handleEventSafely() ()
#9  0x000055555566f5f1 in trantor::EventLoop::loop() ()
#10 0x0000555555670c39 in trantor::EventLoopThread::loopFuncs() ()
#11 0x00007ffff77c3c24 in std::execute_native_thread_routine (__p=0x5555556f8f70) at /build/gcc/src/gcc/libstdc++-v3/src/c++11/thread.cc:80
#12 0x00007ffff7f573e9 in start_thread () from /usr/lib/libpthread.so.0
#13 0x00007ffff74cb293 in clone () from /usr/lib/libc.so.6

Desktop (please complete the following information):

  • OS: linus
  • Version: 1.0.0beta21
@an-tao
Copy link
Member

an-tao commented Sep 18, 2020

Currently Drogon doesn’t support multiple sqls to be executed in one calling to interfaces of DbClient

@lldxflwb
Copy link
Contributor

lldxflwb commented Oct 24, 2022

你好,我在开发的时候,遇到了相同的问题,我使用CLION附带的数据库驱动生成了对应的创表语句,在设置了主键,自增,唯一,注释等情况下,会生成如下代码:

create table table_name
(
    test serial
);

comment on column table_name.test is '这是主键';

create unique index table_name_test_uindex
    on table_name (test);

alter table table_name
    add constraint table_name_pk
        primary key (test);

我将其直接复制粘贴进代码中,并执行。
在当次执行并不会发生问题,但是在执行后接着执行下一条语句时,就会发生bad_function_call。
并且该错误无法捕获。
当把多个语句拆分开执行时,错误就消失了。
对此,如果可以的话,是否能将错误进行检查?如果不能支持多语句sql的话,是否可以做一个执行前检查并报错?或者做一个多语句接口使用';'分割自动执行。
如果任何提示都没有的话,个人觉得这个错误将会排查起来比较困难。
感谢~
值得一提的是,发生这个错误的drogon版本是 1.8.1

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

3 participants