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:

php mysqli_num_rows () in mysql

Think of it, though I have prepared a tool but it is a strange one: executing a class, execute 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")   

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 COUNT () query first you will not often know the number of results.

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.

cursor.rowcount :

Although this code applies to the cursor class module Supports the database engine itself, for the determination of one row, the / / rows were selected for Quirky.

For the execution () statement, the number of modifications is expressed in rowcount .

As required is the Python DB API device, 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>

Emphasis mine.

For your specific query, You can add a sub-selection to add:

  data = sql.sqlExec ("select (select count from user)"   

This large For tables not all are efficient, however.

If you only need all one line, 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

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -