Answers for "sqlite fetchone"

SQL
1

fetchone python sqlite

#Fetches the next row of a query result set, returning a single sequence, or None when no more data is available.
import sqlite3

con = sqlite3.connect(":memory:")
cur = con.cursor()
cur.executescript("""
    create table samples(
        id,
        value
    );
    insert into samples(id, value)
    values (
        '123',
        'abcdef'
    );
    """)
cur.execute("SELECT * from samples")
print cur.fetchone()
OUTPUT
(u'123', u'abcdef')
Posted by: Guest on July-25-2021
2

sqlite3 python

import sqlite3 as lite 
import sys 
 
try: 
    con = lite.connect('products.db') 
    cur = con.cursor()     
    cur.execute("CREATE TABLE drinks(Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Price REAL)") 
    cur.execute("CREATE TABLE fruits(Id INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Price REAL)") 
    con.commit() 
             
except e: 
    if con: 
        con.rollback() 
     
    print("Unexpected error %s:" % e.args[0]) 
    sys.exit(1) 
finally: 
    if con: 
        con.close()
Posted by: Guest on February-07-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language