2015-08-13 68 views
0

我已经使用C++/C,MySQL C++连接器和ncurses/CDK编写了一个程序。它编译得很好,并且在x86/64架构上运行良好。然而,它在Raspberry Pi B +(ArchLinux)上运行时会崩溃。Arch-Linux/arm上的C++ MySQL连接器

我意识到这是一个相当难回答的问题,但也许更有经验的人可以提供帮助。

这里的(希望)相关代码:

//Open Connection to the Database 
    nrpeout::MYSQL_CON localhost("127.0.0.1", 3306, "root", "toor"); 

    //localhost.write_attributes_to_console(); 
    con = localhost.open_database_connection(); 

    //Create a new object of type nrpeoutputquery 
    nrpeout::Nrpeoutputquery current_query("SELECT * FROM nrpeout", con); 

    //Execute query 
    res = current_query.execute_query(); 

    //Close Database Connection 
    localhost.close_database_connection(con); 


    } catch (sql::SQLException &e) { 
     //Handle SQL-Exceptions 
     std::cout << "# ERR: SQLException in " << __FILE__; 
     std::cout << "(" << __FUNCTION__ << ") on line " 
     << __LINE__ << std::endl; 
     std::cout << "# ERR: " << e.what(); 
     std::cout << " (MySQL error code: " << e.getErrorCode(); 
     std::cout << ", SQLState: " << e.getSQLState() << ")" << std::endl; 
    } catch(...) { 
     //Handle Standard Exceptions 
     std::cout << "Unknown Exception raised. Please contact your Administrator" << std::endl; 
    } 
nrpeout::NrpeResultSet* currentResults = new nrpeout::NrpeResultSet(res); 

使用Valgrind的和GDB,我试图缩小误差跌到哪里我创建对象“currentResults”的路线。

这里的成员函数保存查询结果:

nrpeout::NrpeResultSet::NrpeResultSet(sql::ResultSet* res) 
{ 
     for (unsigned int i = 0; i < res->rowsCount(); ++i) 
     { 
      res->next(); 
      std::string command = res->getString("command"); 

      //Shorten the String 
      size_t posCommand = command.find("_"); 
      std::string shortened_command = command.substr(posCommand+1); 

      int ret = res->getInt("ret"); 

      std::string text = res->getString("text"); 

      //Shorten the Text 
      size_t posText = text.find("|"); 
      std::string shortened_text = text.substr(0, posText-1); 

      std::string last_updated = res->getString("last_updated"); 

      this->results.push_back(Row(shortened_command, ret, shortened_text, last_updated)); 
     } 
+0

是否存在错误消息或者是否存在异议? – Drew

+0

错误消息:在抛出'sql :: InvalidInstanceException'的实例后终止调用 – Fang

回答

1

嘛,你不捕获异常,你可能要处理。在使用closed databse connections, statements or resultsets时引发InvalidInstanceException。

我的建议是用GDB和捕获异常运行代码:

gdb ./some-program 
    $ catch throw 
    $ r 

被抛出的每个异常后,这将打破。 (但也包括处理的例外情况,因此可能会有相当多的休息时间,具体取决于您需要多长时间才能到达重要部分。)

+0

这实际上帮助我找到并修复了错误。我太早删除了连接对象。即使这不是我的问题的直接解决办法,我会接受这个答案。 – Fang