如何将二进制std :: string插入BLOB [英] How to INSERT binary std::string into BLOB

查看:199
本文介绍了如何将二进制std :: string插入BLOB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有二进制std :: string,我需要使用我拥有的简单数据层将其插入到BLOB(MySQL)中.因此,我需要执行查询:ExecuteSQL((LPTSTR)strQ).

I have binary std::string and I need insert it into the BLOB (MySQL) using simple data layer I have. So, I need to execute query: ExecuteSQL((LPTSTR)strQ).

当我创建此查询字符串(strQ)时,在添加此二进制字符串后,无法在字符串中添加任何内容-如果终止则只是一种类型,不能添加任何内容.我不想使用mysql_real_escape_string,因为我不仅要保留它对MySQL的使用.

When I am creating this query string (strQ) I cannot add anything to the string after I add this binary string - it just kind if terminated and nothing can be added. I do not want to use mysql_real_escape_string because i want to keep it not only for MySQL.

任何人都可以帮助!!!

Anybody to HELP PLEASE!!!

推荐答案

假定您具有类似以下代码的代码:

Assuming you have code that looks something like this:

std::string s = ...      // populate string somehow
ExecuteSQL( (LPCSTR) s );

那么您有几个问题. Forst,演员表将无法正常工作.在C ++中,每当使用时,几乎可以肯定,您所做的某些不正确的操作会破坏您的代码.您需要使用std :: string成员函数c_str()创建一个以空值结尾的字符串:

Then you have several problems. Forstly, the cast won't work. In C++, whenever you use a cast you are almost certainly doing something incorrect which will break your code. You need to create a null-terminated string using the std::string member function c_str():

ExecuteSQL( s.c_str() );

但是,这可能无法解决所有问题,因为您说自己有二进制字符串.如果该字符串包含零字节,则您的SQL将终止于该字符而不是字符串的末尾.在这种情况下,您可能需要研究显式绑定值.

However, this may not fix all your your problems because you say you hava a binary string. If that string contains the zero byte, then your SQL will terminate at that character rather than the end of string. In that case you probably need to investigate binding your values explicitly.

有关如何将参数绑定到MySQL语句的详细信息,请参见

For details of how to bind a parameter to a MySQL statement, see http://dev.mysql.com/doc/refman/5.1/en/mysql-stmt-bind-param.html

这篇关于如何将二进制std :: string插入BLOB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆