System.Diagnostic是通过查询WMI还是通过其他方式获取其数据?(Does System.Diagnostic get its data by querying the WMI or by other means?)
System.Diagnostic是通过查询WMI还是通过其他方式获取其数据? WMI是否查询所有这些操作用于获取系统信息(如运行进程)的最基本方式,还是有更直接的方法?
Does System.Diagnostic get its data by querying the WMI or by other means? Is WMI querying the most basic way all these operations employ to get system information such as running processes, or are there even more direct methods?
原文:https://stackoverflow.com/questions/8570392
最满意答案
当你执行一个纯文本语句时,你可以用你正在使用的DBAPI来控制新的PK值是否可用,以及通过什么方式。 使用SQlite和MySQL DBAPI,您可以将它作为result.lastrowid,它只会为您提供游标的.lastrowid值。 对于PG,Oracle等,没有“.lastrowid” - 正如其他人所说的那样,对于那些可以通过result.fetchone()得到结果的用户,可以使用“RETURNING”(虽然在oracle中使用RETURNING, ),或者如果RETURNING不可用,则可以使用直接序列访问(NEXTVAL in pg)或“post fetch”操作(PG中的CURRVAL,@@ identity或scope_identity() MSSQL)。
听起来很复杂吗? 这就是为什么你最好使用
table.insert()
。 SQLAlchemy提供新生成的PK的主要系统旨在与这些构造一起工作。 一个你在那里,result.last_inserted_ids()
方法给你所有情况下新生成的(可能是复合的)PK,而不管后端。 以上的.lastrowid,序列执行,RETURNING等方法都是为你处理的(0.6使用RETURNING时可用)。When you execute a plain text statement, you're at the mercy of the DBAPI you're using as to whether or not the new PK value is available and via what means. With SQlite and MySQL DBAPIs you'll have it as result.lastrowid, which just gives you the value of .lastrowid for the cursor. With PG, Oracle, etc., there's no ".lastrowid" - as someone else said you can use "RETURNING" for those in which case results are available via result.fetchone() (although using RETURNING with oracle, again not taking advantage of SQLAlchemy expression constructs, requires several awkward steps), or if RETURNING isn't available you can use direct sequence access (NEXTVAL in pg), or a "post fetch" operation (CURRVAL in PG, @@identity or scope_identity() in MSSQL).
Sounds complicated right ? That's why you're better off using
table.insert()
. SQLAlchemy's primary system of providing newly generated PKs is designed to work with these constructs. One you're there, theresult.last_inserted_ids()
method gives you the newly generated (possibly composite) PK in all cases, regardless of backend. The above methods of .lastrowid, sequence execution, RETURNING etc. are all dealt with for you (0.6 uses RETURNING when available).
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
当你执行一个纯文本语句时,你可以用你正在使用的DBAPI来控制新的PK值是否可用,以及通过什么方式。 使用SQlite和MySQL DBAPI,您可以将它作为result.lastrowid,它只会为您提供游标的.lastrowid值。 对于PG,Oracle等,没有“.lastrowid” - 正如其他人所说的那样,对于那些可以通过result.fetchone()得到结果的用户,可以使用“RETURNING”(虽然在oracle中使用RETURNING, ),或者如果RETURNING不可用,则可以使用 ...
-
你可以这样做, User.query.filter_by(id=123).delete() 要么 User.query.filter(User.id == 123).delete() 编辑: 确保commit delete()提交生效。 You can do this, User.query.filter_by(id=123).delete() or User.query.filter(User.id == 123).delete() Make sure to commit for delete() to ...
-
SQLAlchemy - 如何查看新创建记录的主键ID?(SQLAlchemy - How do I see a primary key id for a newly created record?)[2022-07-15]
db.session.flush() #id is a Python builtin... id_= foo.id 发生的事情是,刷新前的原始代码只在程序中,db中没有。 id列可能是在插入时分配的自动生成字段。 插入记录后( flush将更改写入db),SQLAlchemy基本上从执行select id并返回结果(各种数据库使用各种机制)。 现在你已经填充了id。 提交和回滚在性质上与flush不同。 它们会影响数据库中已有的内容。 另外,标记您的评论我需要在DB中添加其他记录时 ... -
两个文件的Base类不同,您需要使用用于继承的Base类,因此从模型文件导入Base : #creatorfile ... from models import Base path="postgresql://postgres:password@localhost/test" engine = create_engine(path, echo=True) Base.metadata.create_all(engine) 删除此行Base = declarative_base() Base class i ...
-
SqlAlchemy无法找到记录(SqlAlchemy can't find record)[2023-07-02]
您是否尝试过以下查询? session.query(DR).filter( DR.dag_id == self.dag_id, DR.run_id == self.run_id ).first() 如果可行,则问题可能是python datetime等式的计算与数据库日期时间相等。 Have you tried the following query? session.query(DR).filter( DR.dag_id == self.dag_id, DR.run_id ... -
在SQLAlchemy中进行验证(Validation in SQLAlchemy)[2021-11-26]
通过空字段,我想你的意思是一个空字符串而不是NULL。 一种简单的方法是添加验证,例如: class Article(Base): ... name = Column(Text, nullable=False, unique=True) ... @validates('name') def validate_name(self, key, value): assert value != '' return value 要在数据库级别 ... -
听起来你可以简单地按降序排序并取第一个结果...... from sqlalchemy import desc qry = session.query(Data).filter( Data.user_id == user_id).order_by( desc(Data.counter).limit(1) 但是,如果您担心对大型数据集进行排序,则可以使用子查询... subqry = session.query(func.max(Data.counter)).filter(Data ...
-
如何在Pylons中创建与SQLAlchemy的关联记录?(How do I create as assoc record with SQLAlchemy in Pylons?)[2021-12-18]
我在本教程中找到了答案。 ledger = model.Ledger() ledger.name = name ledger.users.append(user) meta.Session.add(ledger) meta.Session.commit() I found my answer in this tutorial. ledger = model.Ledger() ledger.name = name ledger.users.append(user) meta.Session.add(ledg ... -
你熟悉Pandas Dataframe吗? 真的很简单(和调试) pandas.read_csv(FILE_NAME) In [5]: pandas.read_csv('/tmp/csvt.csv') Out[5]: Name Shack DB Payments Status 0 Loyiso Dwala I156 13542 37 LightsOnly ON 1 Attwell Fayo I157 13077 32 ...