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

動態創建占位符以在 SQLite 表中為一行插入多個列

Dynamically creating a placeholder to insert many column values for a row in SQLite table(動態創建占位符以在 SQLite 表中為一行插入多個列值)
本文介紹了動態創建占位符以在 SQLite 表中為一行插入多個列值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我知道可以使用帶有值元組的變量在 SQLite 數據庫中插入許多列值 ('2006-03-28', 'BUY', 'IBM', 1000, 45.00) 和查詢字符串中相應的占位符 (?, ?, ?, ?, ?).我正在我的程序中動態創建值元組,它們最多可容納約 300 個值.我想知道是否有一種安全的(關于 SQL 注入攻擊)方法來動態生成相應的占位符元組字符串 (?, ?, ?, ...) 為查詢字符串?我要求這樣做是為了避免在我的數據庫結構和值元組在整個開發過程中發生變化時繁瑣地計數、添加和刪除 ? .謝謝你的想法.

I know that it's possible to insert many column values in a SQLite database using a variable with a tuple of values ('2006-03-28', 'BUY', 'IBM', 1000, 45.00) and a corresponding placeholder (?, ?, ?, ?, ?) in the query string. I am creating the value tuples dynamically in my program and they may hold up to ~300 values. I am wondering if there is a safe (with respect to SQL injection attacks) way to dynamically generate corresponding the placeholder tuple string (?, ?, ?, ...) for the query string? I ask this to avoid tediously counting, adding and deleting ?s as my database structure and value tuples change throughout development. Thanks for your thoughts.

推薦答案

根據 values 中項目的數量構建一個字符串,例如:

Build a string based on the number of items in your values, eg:

def place_holder(values):
    return '({})'.format(', '.join('?' * len(values)))

values = ['a', 'b', 'c']
ph = place_holder(values)
# (?, ?, ?)

然后是這樣的:

your_cursor.execute('insert into your_table values {}'.format(ph), values)

如果它不符合您的架構,您就會遇到問題,但這是另一個問題...

If it doesn't meet your schema, you'll have issues, but that's another problem...

這篇關于動態創建占位符以在 SQLite 表中為一行插入多個列值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應該使用什么 SQL Server 數據類型來存儲字節 [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數據)
Typeorm .loadRelationCountAndMap returns zeros(Typeorm .loadRelationCountAndMap 返回零)
How to convert #39;2016-07-01 01:12:22 PM#39; to #39;2016-07-01 13:12:22#39; hour format?(如何將“2016-07-01 01:12:22 PM轉換為“2016-07-01 13:12:22小時格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應該返回“1?什么時候不能投射為日期?)
主站蜘蛛池模板: 二区在线观看 | 免费国产一区二区 | 欧美日韩国产在线播放 | 天天有av | 91看片淫黄大片 | av网站网址 | 国产小视频在线观看 | 亚洲第一视频网站 | 国产视频一二三 | 国产又粗又猛又黄又爽无遮挡 | 97精品超碰一区二区三区 | www操 | 欧美日韩亚洲一区二区三区 | 亚洲精品国产精品国自产观看浪潮 | 黄色三级网站 | 免费福利在线观看 | 亚洲一区在线视频 | 少妇一级片 | 欧美专区在线观看 | 国产乱人乱偷精品视频 | 欧美成人精品 | 一区二区三区成人 | 日韩a在线观看 | 国产91精品看黄网站在线观看 | 日韩av免费看 | 日韩免费在线观看 | 欧美人与性动交α欧美精品 | 欧洲精品一区二区 | 成人做爰69片免费 | 亚洲黄色网址 | 九九九热 | 一级片免费在线观看 | 性色在线| 欧美一级二级三级 | 亚洲91av | 欧美国产精品一区二区 | 91福利区 | 免费看毛片网站 | 九九视频在线 | 一级免费毛片 | 激情综合五月婷婷 |