sqlalchemy里engine.execute('select 1').scalar()是什么意思?

zibuyule
  • 28

sqlalchemy里engine.execute('select 1').scalar()是什么意思?
select 1 是什么?
scalar()这个方法是什么意思,怎么用呀?

In [25]: import sqlalchemy

In [26]: engine = create_engine('mysql+mysqldb://root:aptech@localhost:3306/test',echo=True)

In [27]: engine.execute('select 1').scalar()
2015-04-16 17:24:22,277 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'sql_mode'
2015-04-16 17:24:22,277 INFO sqlalchemy.engine.base.Engine ()
2015-04-16 17:24:22,278 INFO sqlalchemy.engine.base.Engine SELECT DATABASE()
2015-04-16 17:24:22,278 INFO sqlalchemy.engine.base.Engine ()
2015-04-16 17:24:22,279 INFO sqlalchemy.engine.base.Engine show collation where Charset = 'utf8' and Collation = 'utf8_bin'
2015-04-16 17:24:22,279 INFO sqlalchemy.engine.base.Engine ()
2015-04-16 17:24:22,281 INFO sqlalchemy.engine.base.Engine SELECT CAST('test plain returns' AS CHAR(60)) AS anon_1
2015-04-16 17:24:22,281 INFO sqlalchemy.engine.base.Engine ()
2015-04-16 17:24:22,282 INFO sqlalchemy.engine.base.Engine SELECT CAST('test unicode returns' AS CHAR(60)) AS anon_1
2015-04-16 17:24:22,282 INFO sqlalchemy.engine.base.Engine ()
2015-04-16 17:24:22,283 INFO sqlalchemy.engine.base.Engine SELECT CAST('test collated returns' AS CHAR CHARACTER SET utf8) COLLATE utf8_bin AS anon_1
2015-04-16 17:24:22,284 INFO sqlalchemy.engine.base.Engine ()
2015-04-16 17:24:22,285 INFO sqlalchemy.engine.base.Engine select 1
2015-04-16 17:24:22,285 INFO sqlalchemy.engine.base.Engine ()
Out[27]: 1L

回复
阅读 6.7k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏