![]() However if you are certain that you're not going to switch, I'd say it's completely OK to take the connection.execute shortcut and be "efficient". That's the main reason you might want to use cursor.execute instead. Perhaps you will only need to change the import line.īut if you use the connection.execute there is a chance that switching won't be that straightforward. they are not part of Python Database API Specification v2.0 (PEP 249).Īs long as you use the standard methods of the Cursor object, you can be sure that if you switch to another database implementation that follows the above specification, your code will be fully portable. This way, you can execute a SELECT statement and iterate over it directly using only a single call on the Connection object.īecause those methods of the connection object are nonstandard, i.e. Instead, the Cursor objects are created implicitly and these shortcut methods return the cursor objects. Using the nonstandard execute(), executemany() and executescript() methods of the Connection object, your code can be written more concisely because you don’t have to create the (often superfluous) Cursor objects explicitly. Would be nice if it was pointed out in the docs that the python module cursor is bit different than what a cursor is in SQL and databases. Regardless of efficiency, it's just a conceptual overhead. Such abstraction is different from what people understand a db cursor to be and hence, the confusion/frustration on the part of users. A full-text search query is made up of phrases, where each phrase is an ordered list of one or more tokens. If you check the docs on Python sqlite module, you can see that a python module cursor is needed even for a CREATE TABLE statement, so it's used for cases where a mere connection object should suffice - as correctly pointed out by the OP. The cursor must be opened and already positioned Not use a regular WHERE clause with predicates. Positioned delete SQL statements for that purpose. The SQL:2003 standard defines positioned update and ![]() So when a database engine and database driver are in the same commit mode (manual commit mode or auto-commit mode), the database driver can pass unmodified SQL. SQL statements are interpreted by a database engine. The SQLite3 driver adapts the Python Database API to the SQLite API. The database cursor characteristic of traversal makes cursorsĪkin to the programming language concept of iterator.Ĭursors can not only be used to fetch data from the DBMS into anĪpplication but also to identify a row in a table to be updated orĭeleted. The SQLite engine has a specific database interface in C. ![]() Traversal, such as retrieval, addition and removal of database Structure that enables traversal over the records in a database.Ĭursors facilitate subsequent processing in conjunction with the In computer science and technology, a database cursor is a control A db cursor is an abstraction, meant for data set traversal. Just a misapplied abstraction it seems to me. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |