MySQL参数绑定失败,但内联成功

时间:2018-11-23 15:09:41

标签: c++ mysql

我大约有4.8MB的字符串(仅包含BASE64-karakters,已证明)。

但是,当我尝试使用此语句绑定字符串时:

sqlPrepared_userdb_test->setString(1, Content); //Content is approximately 4.8MB

Mysql返回:

Incorrect string value: '\xF7/\x00\x00\xF0...' for column 'Content' at row 1 (error code: 1366, State: HY000)

但是,当我直接在查询(内联)中包含content-string时,插入成功。我使用的内联查询(中间部分的内容已跳过):

INSERT INTO Test (Content) Values('ajHEHAU......8837x=='); //Content is approximately 4.8MB

为什么绑定失败,但是内联完全相同的字符串成功?

编辑:

Log("Inserting content!", false, "Debug");


for (auto& Char : Content) {
    if (Char >= 'a' && Char <= 'z') {
        }
    else if (Char >= 'A' && Char <= 'Z') {
        }
    else if (Char >= '0' && Char <= '9') {
        }
    else if (Char == '+') {
        }
    else if (Char == '/') {
        }
    else if (Char == '=') {
        }
    else {
        string Message = "Char in content: ";
        Message += Char;
        Message += " is not allowed!";
        Error(Message);
        // NO ERROR REPORTED HERE. CONTENT STRING SEEMS GOOD
        }
    }

try {
    sqlPrepared_userdb_test = mysqli_userdb->prepareStatement("INSERT INTO Test (Content) VALUES(?)");
    sqlPrepared_userdb_test->setString(1, Content);
    sqlPrepared_userdb_test->executeUpdate();
    }
catch (sql::SQLException &e) {
    Message = "Database test error: ";
    Message += e.what();
    Message += " (error code: ";
    Message += IntToString(e.getErrorCode());
    Message += ", State: ";
    Message += e.getSQLState();
    Message += ")";
    Log(Message, false, "Error");
    Error("Database");

    // CATCH TRIGGERS

    }

outfile.close();

sqlPrepared_userdb->setString(ParamOffset++, Content);

0 个答案:

没有答案