Answers for "fetchone python sqlite"

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

sqlite python connection

import sqlite3

try:
    sqliteConnection = sqlite3.connect('SQLite_Python.db')
    cursor = sqliteConnection.cursor()
    print("Database created and Successfully Connected to SQLite")

    sqlite_select_Query = "select sqlite_version();"
    cursor.execute(sqlite_select_Query)
    record = cursor.fetchall()
    print("SQLite Database Version is: ", record)
    cursor.close()

except sqlite3.Error as error:
    print("Error while connecting to sqlite", error)
finally:
    if (sqliteConnection):
        sqliteConnection.close()
        print("The SQLite connection is closed")
Posted by: Guest on July-27-2020

Code answers related to "SQL"

Browse Popular Code Answers by Language