V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
pierre1994
V2EX  ›  Python

[求助] python 对建表语句进行解析,直接以字典形式生成表的信息

  •  
  •   pierre1994 · Aug 9, 2016 · 4056 views
    This topic created in 3549 days ago, the information mentioned may be changed or developed.

    类似入下的建表 sql :

    CREATE TABLE runoob_tbl(
       runoob_id INT NOT NULL AUTO_INCREMENT,
       runoob_title VARCHAR(100) NOT NULL,
       runoob_author VARCHAR(40) NOT NULL,
       submission_date DATE,
       PRIMARY KEY ( runoob_id )
    );
    

    如何通过 python 直接将这段 sql 转换成以字段与字段类型组成一个字典?

    5 replies    2016-08-14 16:09:10 +08:00
    pierre1994
        1
    pierre1994  
    OP
       Aug 9, 2016
    用 sqlparse 和正则尝试了下,都不太成功
    pierre1994
        2
    pierre1994  
    OP
       Aug 9, 2016
    求助
    guyskk
        3
    guyskk  
       Aug 9, 2016
    如果 SQL 语句格式比较统一的话,先按行分隔,再按空格分隔就可以了。
    murmur
        4
    murmur  
       Aug 9, 2016
    还不如虚拟一个数据库和数据表去执行以下 执行这点表才多少开销 然后去拿真实的 table scheme 就完了
    pierre1994
        5
    pierre1994  
    OP
       Aug 14, 2016
    @murmur 一次使用确实不如,但是计划是做批量操作,所以。。。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   981 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 20:05 · PVG 04:05 · LAX 13:05 · JFK 16:05
    ♥ Do have faith in what you're doing.