Discuss / Python / ???

???

Topic source

viper1090

#1 Created at ... [Delete] [Delete and Lock User]
attrs['__update__'] = 'update `%s` set %s where `%s`=?' % (tableName, ', '.join(map(lambda f: '`%s`=?' % (mappings.get(f).name or f), fields)), primaryKey)

这里的"__update__",为什么不用下面的方式呢

attrs['__update__'] = 'update `%s` set %s where `%s=`' % (tableName, ', '.join(map(lambda f: '%s=?' % f, escaped_fields)), primaryKey)

可以直接使用escaped_fields,而且使用这个语句更加简单一点,但是你的语句有两个地方写错了

1,第三个%s的符号`的位置要在s的后面而不是在=号后

2,少写了一个?符号

正确的写法如下

attrs['__update__'] = 'update `%s` set %s where `%s`=?' % (tableName, ', '.join(map(lambda f: '%s=?' % f, escaped_fields)), primaryKey)


  • 1

Reply