SQL数据插入字符串时转义函数
2015-04-22 17:27
387 查看
函数一:
方法二:
使用:
例如:
字符串中有单引号
std::string CheckString(std::string& strSource) { std::string strOldValue = "'"; std::string strNewValue = "''"; for(std::string::size_type pos(0); pos != std::string::npos; pos += strNewValue.length()) { if ((pos = strSource.find(strOldValue, pos)) != std::string::npos) { strSource.replace(pos, strOldValue.length(), strNewValue); } else { break; } } return strSource; }
方法二:
std::string& replace_all_distinct(std::string& str,const std::string& old_value,const std::string& new_value) { for(std::string::size_type pos(0); pos!=std::string::npos; pos+=new_value.length()) { if((pos=str.find(old_value,pos)) != std::string::npos) str.replace(pos,old_value.length(),new_value); else { break; } } return str; }
使用:
例如:
replace_all_distinct("sub'ject","'","''"); CheckString("subj'e'ct");
字符串中有单引号
相关文章推荐
- SQL自定义函数实现字符串截取转化为整型(主要用于对批量数据的操作)
- sql自定义函数:SF_Split,根据指定的分割符,把一个字符串分割成若干条短数据
- [原创]SQL表值函数:把用逗号分隔的字符串转换成表格数据
- 持久层mybatis的sql向sqlserver插入数据,带小数位的数字字符串自动四舍五入
- sql:日期操作注意的,如果以字符串转日期时的函数,因为数据量大,会出问题
- sql字符串插入函数STUFF
- mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符,可使用本函数来预防数据库攻击。
- MySql数据库-查询、插入数据时转义函数的使用
- MySql数据库-查询、插入数据时转义函数的使用
- SQL里利用自定义函数Group By 数据得到字符串
- SQL数据插入:将截断字符串或二进制数据
- mysql数据库中插入数据时转义函数addslashes()
- sql实现从两个表获取字段组成表数据再插入到函数表中
- [SQL]根据刚刚插入数据的 ID 向另外一张表插入数据(插入的其他字段数据需要对字符串进行分析)
- SQL 插入数据太慢的问题
- oracle_sql_循环插入数据
- Demo of use SQL (Insert logs in system resource usage table)使用sql 的一个示例(插入系统使用日志数据)
- sql 将一个表中的数据插入到另一个表中
- sql 插入多行数据的问题
- sql语句批量插入测试数据