How to get the numbers of data row from sqlite3 database in python -
I'm trying to get the number of rows returned from a sqlite3 database in Python, but it seems that The feature is not available:
Think of it, though I have prepared a tool but it is a strange one: executing a class, execute Is there a function or property that can do without stress? Normally , returns the number of results for a query. However, for SQLite, that property is often set to -1 due to the nature due to the SQLite results a The reason for this is that SQLite produces rows because it finds them in the database, and themselves will not know how many rows are created until the database is finished Happens. Although this code applies to the As required is the Python DB API device, Emphasis mine. For your specific query, You can add a sub-selection to add: This large For tables not all are efficient, however. If you only need all one line, php
mysqli_num_rows () in
mysql
sql and give me the result:
# of results Conclusions G data = sql.sqlExec ("Choose from user") # Run another query for the number of checks, do not have very good working data copy = sql.sqlExec ("select from user") # insert data Try copy and get the length, I did this because I soon inform # as I execute any work of data, the data becomes zero # It is not very good because someone else Can another transaction on the database if the nick of time # len (list (Detacopi)): The data for m: print ( "Name = {}; Password = {}". Format (m ["username"], me ["password"])); Other: Print ("Query Return Nothing")
COUNT () query first you will not often know the number of results.
cursor.rowcount :
cursor class
For the execution () statement, the number of modifications is expressed in
rowcount .
rowcount attribute â "-1 if any
executeXX () cursor or line number of last operation But the interface is not set by ?? contains the
SELECT statement because we can not set the number of rows until all the rows are received. < / P>
data = sql.sqlExec ("select (select count from user)"
cursor.fetchone () instead: < / P>
Use cursor. Execute ('Where is the user used?', (Userid,)) Line = cursor .fetchone () If the line is none: Increase valueError ('such No users Interpretation ") result =" Name = {}; Password = {} ". Format (line ["user name"], line ["password"])
Comments
Post a Comment