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

動(dòng)態(tài)創(chuàng)建占位符以在 SQLite 表中為一行插入多個(gè)列

Dynamically creating a placeholder to insert many column values for a row in SQLite table(動(dòng)態(tài)創(chuàng)建占位符以在 SQLite 表中為一行插入多個(gè)列值)
本文介紹了動(dòng)態(tài)創(chuàng)建占位符以在 SQLite 表中為一行插入多個(gè)列值的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

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

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.

推薦答案

根據(jù) values 中項(xiàng)目的數(shù)量構(gòu)建一個(gè)字符串,例如:

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)

如果它不符合您的架構(gòu),您就會(huì)遇到問(wèn)題,但這是另一個(gè)問(wèn)題...

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

這篇關(guān)于動(dòng)態(tài)創(chuàng)建占位符以在 SQLite 表中為一行插入多個(gè)列值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

What SQL Server Datatype Should I Use To Store A Byte[](我應(yīng)該使用什么 SQL Server 數(shù)據(jù)類(lèi)型來(lái)存儲(chǔ)字節(jié) [])
Interpreting type codes in sys.objects in SQL Server(解釋 SQL Server 中 sys.objects 中的類(lèi)型代碼)
Typeorm Does not return all data(Typeorm 不返回所有數(shù)據(jù))
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轉(zhuǎn)換為“2016-07-01 13:12:22小時(shí)格式?)
MS SQL: Should ISDATE() Return quot;1quot; when Cannot Cast as Date?(MS SQL:ISDATE() 是否應(yīng)該返回“1?什么時(shí)候不能投射為日期?)
主站蜘蛛池模板: 精品国产一区二区三区性色av | 免费成人高清在线视频 | 日本久久精品 | 日韩三极 | 日本成人在线观看网站 | 日韩国产中文字幕 | 亚洲欧美日韩中文字幕一区二区三区 | 国产欧美精品一区二区色综合 | 欧美精品久久久 | 精品国产99 | 一区二区成人 | 精品久久久久久久久久 | 精品亚洲一区二区三区四区五区 | 激情三区 | 97精品超碰一区二区三区 | 日韩欧美中文字幕在线观看 | 国产精品免费一区二区三区四区 | 亚洲天天干 | 亚洲一区二区三区视频 | 粉嫩av久久一区二区三区 | 最新中文字幕在线 | 久久网一区二区 | av网站在线免费观看 | 国产一区二区三区色淫影院 | 国产精品久久久久久吹潮 | 免费久草 | www精品| 中文字幕免费视频 | 亚洲精品无 | 精品www | 亚洲国产一区在线 | 国产激情一区二区三区 | 久久精品国产一区二区 | 欧美在线视频一区 | 91福利在线观看视频 | 四虎永久影院 | 精品一区二区三区在线视频 | 亚洲国产成人精品女人 | 青青久久 | 9久久| 男人的天堂视频网站 |