簡體   English   中英

Arch-Linux / arm上的C ++ MySQL連接器

[英]C++ MySQL-connector on Arch-Linux/arm

我已經使用C ++ / C,MySQL C ++連接器和ncurses / CDK編寫了一個程序。 它可以很好地編譯,並且可以在x86 / 64架構上很好地運行。 但是,在Raspberry Pi B +(ArchLinux)上運行時,它會崩潰。

我意識到這是一個很難回答的問題,但也許經驗豐富的人可以提供幫助。

這是(希望)相關的代碼:

//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));
        }

好吧,您沒有捕獲到可能要處理的異常。 使用封閉的數據庫連接,語句或結果集時,拋出InvalidInstanceException。

我的建議是使用gdb運行代碼並捕獲異常:

    gdb ./some-program
    $ catch throw
    $ r

拋出每個異常后,此操作將中斷。 (但還包括處理的異常,因此可能會有很多中斷,具體取決於您到達重要部分的時間。)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM