擅长:python、mysql、java
<pre><code>"attach \"%s\" as toMerge" % "b.db"
</code></pre>
<p>您应该使用<code>'</code>,而不是<code>"</code>,这样就不必转义。</p>
<p>您使用了不推荐使用的旧格式字符串。</p>
<pre><code>'attach "{0}" as toMerge'.format("b.db")
</code></pre>
<p>这将使用来自较新Python版本的新格式字符串特性,如果可能的话,应该使用该特性而不是旧版本。</p>
<pre><code>"attach ? as toMerge"; cursor.execute(cmd, ('b.db', ))
</code></pre>
<p>这个方法完全省略了字符串格式,而是使用了SQLite特性,所以这是正确的方法。</p>
<p>大优势:没有SQL注入的风险</p>