久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='O8FIw'><style id='O8FIw'><dir id='O8FIw'><q id='O8FIw'></q></dir></style></legend>

      1. <i id='O8FIw'><tr id='O8FIw'><dt id='O8FIw'><q id='O8FIw'><span id='O8FIw'><b id='O8FIw'><form id='O8FIw'><ins id='O8FIw'></ins><ul id='O8FIw'></ul><sub id='O8FIw'></sub></form><legend id='O8FIw'></legend><bdo id='O8FIw'><pre id='O8FIw'><center id='O8FIw'></center></pre></bdo></b><th id='O8FIw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='O8FIw'><tfoot id='O8FIw'></tfoot><dl id='O8FIw'><fieldset id='O8FIw'></fieldset></dl></div>

        <small id='O8FIw'></small><noframes id='O8FIw'>

        • <bdo id='O8FIw'></bdo><ul id='O8FIw'></ul>
        <tfoot id='O8FIw'></tfoot>

        帶有 SQL 通配符和 LIKE 的 Python 字符串格式

        Python String Formats with SQL Wildcards and LIKE(帶有 SQL 通配符和 LIKE 的 Python 字符串格式)

            <tbody id='H5OHT'></tbody>
            <bdo id='H5OHT'></bdo><ul id='H5OHT'></ul>

            <small id='H5OHT'></small><noframes id='H5OHT'>

              <i id='H5OHT'><tr id='H5OHT'><dt id='H5OHT'><q id='H5OHT'><span id='H5OHT'><b id='H5OHT'><form id='H5OHT'><ins id='H5OHT'></ins><ul id='H5OHT'></ul><sub id='H5OHT'></sub></form><legend id='H5OHT'></legend><bdo id='H5OHT'><pre id='H5OHT'><center id='H5OHT'></center></pre></bdo></b><th id='H5OHT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='H5OHT'><tfoot id='H5OHT'></tfoot><dl id='H5OHT'><fieldset id='H5OHT'></fieldset></dl></div>

                <legend id='H5OHT'><style id='H5OHT'><dir id='H5OHT'><q id='H5OHT'></q></dir></style></legend>
                <tfoot id='H5OHT'></tfoot>

                1. 本文介紹了帶有 SQL 通配符和 LIKE 的 Python 字符串格式的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我很難讓 python 中的一些 sql 正確地通過 MySQLdb.是 pythons 字符串格式讓我很生氣.

                  I'm having a hard time getting some sql in python to correctly go through MySQLdb. It's pythons string formatting that is killing me.

                  我的 sql 語句使用帶通配符的 LIKE 關鍵字.我在 Python 中嘗試了許多不同的東西.問題是,一旦我讓其中一個工作起來,MySQLdb 中有一行代碼會在字符串格式上打嗝.

                  My sql statement is using the LIKE keyword with wildcards. I've tried a number of different things in Python. The problem is once I get one of them working, there's a line of code in MySQLdb that burps on string format.

                  嘗試 1:

                  "SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOINtag ON user.id = tag.userId WHERE user.username LIKE '%%s%'" % (query)

                  "SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOIN tag ON user.id = tag.userId WHERE user.username LIKE '%%s%'" % (query)

                  這是不行的.我得到值錯誤:

                  This is a no go. I get value error:

                  ValueError: 索引 128 處不支持的格式字符 ''' (0x27)

                  ValueError: unsupported format character ''' (0x27) at index 128

                  嘗試 2:

                  "SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOINtag ON user.id = tag.userId WHERE user.username LIKE '\%%s\%'" %(查詢)

                  "SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOIN tag ON user.id = tag.userId WHERE user.username LIKE '\%%s\%'" % (query)

                  我從嘗試 1 中得到相同的結果.

                  I get the same result from attempt 1.

                  嘗試 3:

                  like = "LIKE '%" + str(query) + "%'" totalq = "SELECT tag.userId,count(user.id) as totalRows FROM user INNER JOIN tag ON user.id =tag.userId WHERE user.username " + like

                  like = "LIKE '%" + str(query) + "%'" totalq = "SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOIN tag ON user.id = tag.userId WHERE user.username " + like

                  這會正確創建 totalq 變量,但現在當我運行查詢時,我從 MySQLdb 收到錯誤:

                  This correctly creates the totalq variable, but now when I go to run the query I get errors from MySQLdb:

                  文件build/bdist.macosx-10.6-universal/egg/MySQLdb/cursors.py",行158、在執行query = query % db.literal(args) TypeError: not enough格式字符串的參數

                  File "build/bdist.macosx-10.6-universal/egg/MySQLdb/cursors.py", line 158, in execute query = query % db.literal(args) TypeError: not enough arguments for format string

                  嘗試 4:

                  like = "LIKE '\%" + str(query) + "\%'" totalq = "SELECT tag.userId,count(user.id) as totalRows FROM user INNER JOIN tag ON user.id =tag.userId WHERE user.username " + like

                  like = "LIKE '\%" + str(query) + "\%'" totalq = "SELECT tag.userId, count(user.id) as totalRows FROM user INNER JOIN tag ON user.id = tag.userId WHERE user.username " + like

                  這與嘗試 3 的輸出相同.

                  This is the same output as attempt 3.

                  這一切看起來真的很奇怪.python 如何在sql語句中使用通配符?

                  This all seems really strange. How can I use wildcards in sql statements with python?

                  推薦答案

                  問題不是字符串格式化,而是如何根據 Python 中的 db 操作要求執行查詢(PEP 249)

                  It's not about string formatting but the problem is how queries should be executed according to db operations requirements in Python (PEP 249)

                  試試這樣的:

                  sql = "SELECT column FROM table WHERE col1=%s AND col2=%s" 
                  params = (col1_value, col2_value)
                  cursor.execute(sql, params)
                  

                  這里有一些 psycog2 的例子你有一些對mysql也應該有效的解釋(mysqldb也遵循PEP249 dba api guide 2.0:這里是mysqldb的例子)

                  here are some examples for psycog2 where you have some explanations that should also be valid for mysql (mysqldb also follows PEP249 dba api guidance 2.0: here are examples for mysqldb)

                  這篇關于帶有 SQL 通配符和 LIKE 的 Python 字符串格式的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                2. <small id='b5uYZ'></small><noframes id='b5uYZ'>

                  <legend id='b5uYZ'><style id='b5uYZ'><dir id='b5uYZ'><q id='b5uYZ'></q></dir></style></legend>
                      <tbody id='b5uYZ'></tbody>

                        <tfoot id='b5uYZ'></tfoot>

                          <i id='b5uYZ'><tr id='b5uYZ'><dt id='b5uYZ'><q id='b5uYZ'><span id='b5uYZ'><b id='b5uYZ'><form id='b5uYZ'><ins id='b5uYZ'></ins><ul id='b5uYZ'></ul><sub id='b5uYZ'></sub></form><legend id='b5uYZ'></legend><bdo id='b5uYZ'><pre id='b5uYZ'><center id='b5uYZ'></center></pre></bdo></b><th id='b5uYZ'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='b5uYZ'><tfoot id='b5uYZ'></tfoot><dl id='b5uYZ'><fieldset id='b5uYZ'></fieldset></dl></div>
                            <bdo id='b5uYZ'></bdo><ul id='b5uYZ'></ul>
                          • 主站蜘蛛池模板: 337p日本欧洲亚洲大胆精蜜臀 | 国产亚洲一区二区三区在线观看 | 国产专区在线 | 国产在线观看 | 欧美日韩国产精品一区二区 | 日韩精品影院 | 综合国产 | 熟女毛片| 久久久久91| 久久久久久av| 午夜激情在线 | 成年人在线观看视频 | 中文字幕在线观看 | 久久伊人一区二区 | 91大片 | 亚洲精品片 | 欧美精品中文字幕久久二区 | av影音资源 | 日本在线观看网址 | 国产黄色大片网站 | 久久久久久影院 | jizz视频| 久草视| 欧美在线视频一区 | 亚洲一区二区在线视频 | 亚洲精品永久免费 | v亚洲 | 亚洲一区国产精品 | 亚洲综合色丁香婷婷六月图片 | 欧美日韩亚洲二区 | 久久精品二区亚洲w码 | 欧美成人h版在线观看 | 亚洲精久 | 黄色片在线 | 日日干夜夜操天天操 | 国产日韩欧美 | 亚洲国产精品久久人人爱 | 91久久国产综合久久 | 在线免费观看视频黄 | 欧美黄色片 | 91视频在线|