MySQL中如何插入blob类型数据
来源:互联网 发布:帝国cms漏洞 编辑:程序博客网 时间:2024/04/29 00:56
等具体研究完写篇完整的,现在只是作为一个标记,以免忘记mysql_real_escape_string函数。
mysql_real_escape_string()
unsigned long mysql_real_escape_string(MYSQL *mysql, char *to, const char *from, unsigned long length)
Note that mysql
must be a valid, open connection. This is needed because the escaping depends on the character set in use by the server.
Description
This function is used to create a legal SQL string that you can use in an SQL statement. See Section 9.1.1, “Strings”.
The string in from
is encoded to an escaped SQL string, taking into account the current character set of the connection. The result is placed in to
and a terminating null byte is appended. Characters encoded are NUL
(ASCII 0), ‘/n
’, ‘/r
’, ‘/
’, ‘'
’, ‘"
’, and Control-Z (see Section 9.1, “Literal Values”). (Strictly speaking, MySQL requires only that backslash and the quote character used to quote the string in the query be escaped. This function quotes the other characters to make them easier to read in log files.)
The string pointed to by from
must be length
bytes long. You must allocate the to
buffer to be at least length*2+1
bytes long. (In the worst case, each character may need to be encoded as using two bytes, and you need room for the terminating null byte.) When mysql_real_escape_string()
returns, the contents of to
is a null-terminated string. The return value is the length of the encoded string, not including the terminating null character.
If you need to change the character set of the connection, you should use the mysql_set_character_set()
function rather than executing a SET NAMES
(or SET CHARACTER SET
) statement. mysql_set_character_set()
works like SET NAMES
but also affects the character set used by mysql_real_escape_string()
, which SET NAMES
does not.
Example
char query[1000],*end;end = strmov(query,"INSERT INTO test_table values(");*end++ = '/'';end += mysql_real_escape_string(&mysql, end,"What's this",11);*end++ = '/'';*end++ = ',';*end++ = '/'';end += mysql_real_escape_string(&mysql, end,"binary data: /0/r/n",16);*end++ = '/'';*end++ = ')';if (mysql_real_query(&mysql,query,(unsigned int) (end - query))){ fprintf(stderr, "Failed to insert row, Error: %s/n", mysql_error(&mysql));}
The strmov()
function used in the example is included in the mysqlclient
library and works like strcpy()
but returns a pointer to the terminating null of the first parameter.
Return Values
The length of the value placed into to
, not including the terminating null character.
Errors
None.
- MySQL中如何插入blob类型数据
- mysql 如何手动插入数据blob类型数据
- MySQL 中Blob类型数据的插入和读取
- mysql中应用blob类型的数据
- mybatis中插入和读取mysql的blob/text类型数据
- oracle中如何向带有blob字段类型的表插入数据
- java.sql.Blob类型如何插入到MySQL数据库
- 插入,查询Blob类型数据
- oracle 向表中插入BLOB类型数据
- oracle 向表中插入BLOB类型数据
- MySQL BLOB类型数据操作
- MySQL BLOB类型数据操作
- MySQL存储 BLOB 类型数据
- 如何处理BLOB类型数据之一:上传文件并保存到BLOB中
- 如何处理BLOB类型数据之二:下载BLOB内容并保存到文件中
- mysql blob数据的插入与查询
- 使用PreparedStatement向数据表中插入、修改、删除、获取Blob类型的数据
- 如何向mysql中插入大量数据
- 圣诞快乐
- 人与鱼之见解
- 如何读取结构体的数值
- 用.net实现注册用户使用RadioButtonList,DropDownList与数据库绑定,使用DropDownList实现省市联动
- 线程的快跑与等待
- MySQL中如何插入blob类型数据
- const和static readonly的区别
- 关于BI中OLAP的MDX语句及各类分析实现 同比增长率
- A Taste of AOP from Solving Problems with OOP and Design Patterns (Part III) zz
- c++中嵌入python入门1
- 深拷贝与浅拷贝探析
- python脚本语言
- 利用ASP.NET输出指定内容的WORD、EXCEL、TXT、HTM
- Windows CE授权费用