MySQL parameter binding fails but inline succeeds





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have a string of approximately 4.8MB (containing only BASE64-karakters, proven).



However, when I try to bind the string using this statement:



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


Mysql returns:



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


However, when I include the content-string directly in the query (inline), the insert succeeds. The inline-query I use (skipped part of the content in the middle):



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


Why does binding fail, but inlining the exact same string succeeds?



EDIT:



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









share|improve this question

























  • Please show us more code, apparently something is happening in setString, or before that.

    – Bart Friederichs
    Nov 23 '18 at 15:17











  • @BartFriederichs, we have made a simple test. I have added the example to the original question

    – Thomas van Hesteren
    Nov 23 '18 at 15:23











  • What is Content's type?

    – Bart Friederichs
    Nov 23 '18 at 15:30











  • The inline version looks a lot like base64 encoding and the string in the error message looks suspiciously not base64 encoded. I guess Content is not getting encoded when converted to a string.

    – Tim Seguine
    Nov 23 '18 at 15:30













  • @BartFriederichs, good question. I assume you mean the MySQL datatype of the column Content? This is LONGTEXT

    – Thomas van Hesteren
    Nov 23 '18 at 15:38


















0















I have a string of approximately 4.8MB (containing only BASE64-karakters, proven).



However, when I try to bind the string using this statement:



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


Mysql returns:



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


However, when I include the content-string directly in the query (inline), the insert succeeds. The inline-query I use (skipped part of the content in the middle):



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


Why does binding fail, but inlining the exact same string succeeds?



EDIT:



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









share|improve this question

























  • Please show us more code, apparently something is happening in setString, or before that.

    – Bart Friederichs
    Nov 23 '18 at 15:17











  • @BartFriederichs, we have made a simple test. I have added the example to the original question

    – Thomas van Hesteren
    Nov 23 '18 at 15:23











  • What is Content's type?

    – Bart Friederichs
    Nov 23 '18 at 15:30











  • The inline version looks a lot like base64 encoding and the string in the error message looks suspiciously not base64 encoded. I guess Content is not getting encoded when converted to a string.

    – Tim Seguine
    Nov 23 '18 at 15:30













  • @BartFriederichs, good question. I assume you mean the MySQL datatype of the column Content? This is LONGTEXT

    – Thomas van Hesteren
    Nov 23 '18 at 15:38














0












0








0








I have a string of approximately 4.8MB (containing only BASE64-karakters, proven).



However, when I try to bind the string using this statement:



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


Mysql returns:



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


However, when I include the content-string directly in the query (inline), the insert succeeds. The inline-query I use (skipped part of the content in the middle):



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


Why does binding fail, but inlining the exact same string succeeds?



EDIT:



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









share|improve this question
















I have a string of approximately 4.8MB (containing only BASE64-karakters, proven).



However, when I try to bind the string using this statement:



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


Mysql returns:



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


However, when I include the content-string directly in the query (inline), the insert succeeds. The inline-query I use (skipped part of the content in the middle):



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


Why does binding fail, but inlining the exact same string succeeds?



EDIT:



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






c++ mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 15:24







Thomas van Hesteren

















asked Nov 23 '18 at 15:09









Thomas van HesterenThomas van Hesteren

5318




5318













  • Please show us more code, apparently something is happening in setString, or before that.

    – Bart Friederichs
    Nov 23 '18 at 15:17











  • @BartFriederichs, we have made a simple test. I have added the example to the original question

    – Thomas van Hesteren
    Nov 23 '18 at 15:23











  • What is Content's type?

    – Bart Friederichs
    Nov 23 '18 at 15:30











  • The inline version looks a lot like base64 encoding and the string in the error message looks suspiciously not base64 encoded. I guess Content is not getting encoded when converted to a string.

    – Tim Seguine
    Nov 23 '18 at 15:30













  • @BartFriederichs, good question. I assume you mean the MySQL datatype of the column Content? This is LONGTEXT

    – Thomas van Hesteren
    Nov 23 '18 at 15:38



















  • Please show us more code, apparently something is happening in setString, or before that.

    – Bart Friederichs
    Nov 23 '18 at 15:17











  • @BartFriederichs, we have made a simple test. I have added the example to the original question

    – Thomas van Hesteren
    Nov 23 '18 at 15:23











  • What is Content's type?

    – Bart Friederichs
    Nov 23 '18 at 15:30











  • The inline version looks a lot like base64 encoding and the string in the error message looks suspiciously not base64 encoded. I guess Content is not getting encoded when converted to a string.

    – Tim Seguine
    Nov 23 '18 at 15:30













  • @BartFriederichs, good question. I assume you mean the MySQL datatype of the column Content? This is LONGTEXT

    – Thomas van Hesteren
    Nov 23 '18 at 15:38

















Please show us more code, apparently something is happening in setString, or before that.

– Bart Friederichs
Nov 23 '18 at 15:17





Please show us more code, apparently something is happening in setString, or before that.

– Bart Friederichs
Nov 23 '18 at 15:17













@BartFriederichs, we have made a simple test. I have added the example to the original question

– Thomas van Hesteren
Nov 23 '18 at 15:23





@BartFriederichs, we have made a simple test. I have added the example to the original question

– Thomas van Hesteren
Nov 23 '18 at 15:23













What is Content's type?

– Bart Friederichs
Nov 23 '18 at 15:30





What is Content's type?

– Bart Friederichs
Nov 23 '18 at 15:30













The inline version looks a lot like base64 encoding and the string in the error message looks suspiciously not base64 encoded. I guess Content is not getting encoded when converted to a string.

– Tim Seguine
Nov 23 '18 at 15:30







The inline version looks a lot like base64 encoding and the string in the error message looks suspiciously not base64 encoded. I guess Content is not getting encoded when converted to a string.

– Tim Seguine
Nov 23 '18 at 15:30















@BartFriederichs, good question. I assume you mean the MySQL datatype of the column Content? This is LONGTEXT

– Thomas van Hesteren
Nov 23 '18 at 15:38





@BartFriederichs, good question. I assume you mean the MySQL datatype of the column Content? This is LONGTEXT

– Thomas van Hesteren
Nov 23 '18 at 15:38












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449055%2fmysql-parameter-binding-fails-but-inline-succeeds%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449055%2fmysql-parameter-binding-fails-but-inline-succeeds%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini