Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

mysql - res->getString() crashes the application

HOW IT SHOULD WORK: User clicks on a listbox with multitude of IDs. Then, the edit controls are filed with the data from the specified ID (row).

HOW IT WORKS: It crashes at res->getString

case LBN_SELCHANGE:
{
    string str;
    int index = SendMessage(GetDlgItem(hwnd, IDC_lbList), LB_GETCURSEL, 0, 0);
    string sint = boost::lexical_cast<std::string>(index);
    string smt="SELECT client, telnr, atnrem, papatn, gedapr 
                                   FROM tremreg WHERE id = ";
    string query = smt + sint;
    res = stmt->executeQuery(query.c_str());
    //starts crashing here
    str = res->getString("client");
    SetDlgItemText(hwnd, IDC_eClient, str.c_str());

    str = res->getString("telnr");
    SetDlgItemText(hwnd, IDC_eTelNr, str.c_str());

    str = res->getString("antrem");
    SetDlgItemText(hwnd, IDC_eRemAtn, str.c_str());

    str = res->getString("paprem");
    SetDlgItemText(hwnd, IDC_ePapAtn, str.c_str());

    str = res->getString("gedapr");
    SetDlgItemText(hwnd, IDC_eGedApr, str.c_str());

    delete res;
    delete stmt;
}
break;

CRASH INFO:

Unhandled exception at 0x753C812F in Registracija.exe: 
Microsoft C++ exception:sql::InvalidArgumentException at memory location 0x0018F7AC.

Digging around google I found somebody mentioning that VARCHAR type values should be fetched with getBlob. That did not help at all though, and crashed just the same. getInt works however, and is used in other parts of the program.

QUESTION: What steps should I take to make it work?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

does the same query run properly if you do it in the database directly? Also, are all the returned fields really Strings? And is it valid to call them by name, rather than by the sequence number? I.e. getString(1), etc.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...