这是 tx.sql
DECLARE @Cnt INT,
@ParticipantID UNIQUEIDENTIFIER
SELECT ParticipantID INTO #ids
FROM dbo.rbd_Participants
/* sun */
WHERE surname='Пупкин'
这是python脚本
with open('tx.sql', 'r') as f:
script = f.read().decode('utf8')
script = re.sub(r'\/\*.*?\*\/', '', script, flags=re.DOTALL)multiline comment
script = re.sub(r'--.*$', '', script, flags=re.MULTILINE) line comment
sql = []
do_execute = False
for line in script.split(u'\n'):
line = line.strip()
if not line:
continue
elif line.upper() == u'GO':
do_execute = True
else:
sql.append(line)
do_execute = line.endswith(u';')
#print line
cur.execute(u'\n'.join(sql).encode('utf8'))
问题线:script = f.read().decode('utf8')
UnicodeDecodeError:“utf8”编解码器无法解码位置 134 中的字节 0xc0:无效的起始字节
我试过了
script = f.read().decode('cp1251')
但线
cur.execute(u'\n'.join(sql).encode('utf8'))
print (u'\n'.join(sql)).encode('utf8')
DECLARE @Cnt INT,
@ParticipantID UNIQUEIDENTIFIER
SELECT ParticipantID INTO #ids
FROM dbo.rbd_Participants
WHERE surname='РџСѓРїРєРёРЅ'
如何做出正确的线条?
WHERE surname='РџСѓРїРєРёРЅ'
必须有一个字符串
WHERE surname='Пупкин'