V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
agentwx
V2EX  ›  Python

sql 占位符的数量问题

  •  
  •   agentwx · 2015-09-30 10:25:51 +08:00 · 2863 次点击
    这是一个创建于 3144 天前的主题,其中的信息可能已经有所发展或是发生改变。

    用的是 python 的语言,由于数据表是动态生成的,然后属性的数量也是不确定的(根据用户的模板里的具体内容) , 那么在用 sql 的时候,对应的占位符的数量如何动态生成呢?
    比如这个 u"insert into %s(%s) VALUES(?,?,?,?)", 这里是四个属性,如果是更多属性,这里的占位符?如何生成

    另:为了调试程序,刚开始使用的是 sqlite, 用的是 apsw 包

    1 条回复    2015-09-30 11:48:54 +08:00
    msg7086
        1
    msg7086  
       2015-09-30 11:48:54 +08:00
    组装字符串会吗?
    特地去学了一下 python ,研究出以下做法:
    >>> '?,'*3+'?'
    '?,?,?,?'
    >>> string.join(['?']*4, ',')
    '?,?,?,?'
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   6209 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 02:49 · PVG 10:49 · LAX 19:49 · JFK 22:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.