当前位置: 首页>>代码示例>>Python>>正文


Python MySQLdb.escape_string方法代码示例

本文整理汇总了Python中MySQLdb.escape_string方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLdb.escape_string方法的具体用法?Python MySQLdb.escape_string怎么用?Python MySQLdb.escape_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MySQLdb的用法示例。


在下文中一共展示了MySQLdb.escape_string方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_provinces

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def write_provinces(path):
    write_insert_header("provinces")

    counter = 0
    rows = csv_to_list(path)
    last_row = len(rows) - 1
    for row in rows:
        if (counter % SPLIT_ROWS == 0):
            print "INSERT INTO `provinces` VALUES"
        if (counter == last_row or counter % SPLIT_ROWS == SPLIT_ROWS - 1):
            print "  ('%s', '%s');" % (row[0], MySQLdb.escape_string(row[1]))
        else:
            print "  ('%s', '%s')," % (row[0], MySQLdb.escape_string(row[1]))
        counter += 1

    write_insert_footer("provinces") 
开发者ID:edwardsamuel,项目名称:Wilayah-Administratif-Indonesia,代码行数:18,代码来源:mdf_mysql_converter.py

示例2: escape

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def escape(self, s):
        """ Makes a string value safe for database queries
        """
        if s is None: return ""
        if asm3.utils.is_str(s):
            s = MySQLdb.escape_string(s)
            s = asm3.utils.bytes2str(s) # MySQLdb.escape_string can return bytes on python3
        elif asm3.utils.is_unicode(s):
            # Encode the string as UTF-8 for MySQL escape_string 
            # then decode it back into unicode before continuing
            s = s.encode("utf-8")
            s = MySQLdb.escape_string(s)
            s = s.decode("utf-8")
        # This is historic - ASM2 switched backticks for apostrophes so we do for compatibility
        s = s.replace("'", "`")
        return s 
开发者ID:bobintetley,项目名称:asm3,代码行数:18,代码来源:mysql.py

示例3: _str_escape

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def _str_escape(s, d):
    if s == None:
        return ''
    return MySQLdb.escape_string(s) 
开发者ID:NetEaseGame,项目名称:iOS-private-api-checker,代码行数:6,代码来源:mysql_escape_warp.py

示例4: mysql_escape

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def mysql_escape(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        newargs = []
        #先转义参数,再执行方法
        for arg in args:
            #字符串,包括中文
            if type(arg) is types.StringType or type(arg) is types.UnicodeType:
                newargs.append(MySQLdb.escape_string(arg))
            
            #字典    
            elif isinstance(arg, dict):
                newargs.append(MySQLdb.escape_dict(arg, {
                                                         types.StringType: _str_escape,
                                                         types.UnicodeType: _str_escape,
                                                         types.IntType: _no_escape,
                                                         types.FloatType: _no_escape
                                                         }))
            #其他类型不转义
            else:
                newargs.append(arg)
                
        newargs = tuple(newargs)
        
        func = f(*newargs, **kwargs)
        
        return func
    return decorated_function 
开发者ID:NetEaseGame,项目名称:iOS-private-api-checker,代码行数:30,代码来源:mysql_escape_warp.py

示例5: _safe

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def _safe(s):
    return '"' + MySQLdb.escape_string(str(s)) + '"' 
开发者ID:bsc-s2,项目名称:pykit,代码行数:4,代码来源:mysqlutil.py

示例6: write_insert_body

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def write_insert_body(table_name, rows):
    counter = 0
    last_row = len(rows) - 1
    for row in rows:
        if (counter % SPLIT_ROWS == 0):
            print "INSERT INTO `%s` VALUES" % (table_name)
        if (counter == last_row or counter % SPLIT_ROWS == SPLIT_ROWS - 1):
            print("  ('%s', '%s', '%s');"
                  % (row[0], row[1], MySQLdb.escape_string(row[2])))
        else:
            print("  ('%s', '%s', '%s'),"
                  % (row[0], row[1], MySQLdb.escape_string(row[2])))
        counter += 1 
开发者ID:edwardsamuel,项目名称:Wilayah-Administratif-Indonesia,代码行数:15,代码来源:mdf_mysql_converter.py

示例7: _check_new_registration

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def _check_new_registration(self, email):
        email = MySQLdb.escape_string(email)
        c = self.db.cursor()
        query = 'SELECT * FROM user_registration WHERE email="%s"' % email
        try:
            c.execute(query)
            self.db.commit()
        except MySQLdb.Error, e:
            self.logger.info(str(e))
            return False 
开发者ID:StorminStanley,项目名称:st2incubator,代码行数:12,代码来源:registration_sensor.py

示例8: genstr

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def genstr(str1):
    if str1:
        return "'" + MySQLdb.escape_string(str1) + "'"
    else:
        return "''" 
开发者ID:h-j-13,项目名称:Malicious_Domain_Whois,代码行数:7,代码来源:run.py

示例9: _mk_condition

# 需要导入模块: import MySQLdb [as 别名]
# 或者: from MySQLdb import escape_string [as 别名]
def _mk_condition(db_column, operator, data):
    op = operator_map.get(operator)
    if not op:
        raise Exception('unsupported operator:' + str(operator))

    # I would prefer to use a prepared statement, but collecting arguments
    # and passing them back along the string everywhere would be awful design.
    # (Also, I didn't find any API from Django to generate a prepared statement
    # without already executing it, e.g. django.db.connection.execute())
    if isinstance(data, int):
        return db_column+op.format(data)
    return db_column+op.format(escape_string(data).decode('utf-8')) 
开发者ID:knipknap,项目名称:django-find,代码行数:14,代码来源:sql.py


注:本文中的MySQLdb.escape_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。