推荐学习书目
› 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 · Sep 30, 2015 · 3830 views
    This topic created in 4016 days ago, the information mentioned may be changed or developed.

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

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

    1 replies  •  2015-09-30 11:48:54 +08:00
    msg7086
        1
    msg7086  
       Sep 30, 2015
    组装字符串会吗?
    特地去学了一下 python ,研究出以下做法:
    >>> '?,'*3+'?'
    '?,?,?,?'
    >>> string.join(['?']*4, ',')
    '?,?,?,?'
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3760 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:25 · PVG 13:25 · LAX 22:25 · JFK 01:25
    ♥ Do have faith in what you're doing.