py sqlite if entry exists

Solutions on MaxInterview for py sqlite if entry exists by the best coders in the world

showing results for - "py sqlite if entry exists"
Emilio
08 Jan 2017
1for name in ('bar','foo'): 
2    cursor.execute("SELECT rowid FROM components WHERE name = ?", (name,))
3    data=cursor.fetchall()
4    if len(data)==0:
5        print('There is no component named %s'%name)
6    else:
7        print('Component %s found with rowids %s'%(name,','.join(map(str, next(zip(*data))))))
Esteban
11 Jan 2019
1-- Count entries in database
2SELECT count(*);
3
4-- Count rows in table
5SELECT count(*) FROM peoples;
6-- returns the number of rows in this table
7
8-- Count rows with filter
9SELECT count(*) FROM peoples WHERE age = 20;
10-- returns the number of rows/peoples with an age of 20
11
12-- If none (matching) row is in the specified
13-- table it will return 0. So you can
14-- check for "if (SQL_return >= 1)"