Answers for "sqlite3 insert"

SQL
4

insert records into sqlite table python

import sqlite3

def insertMultipleRecords(recordList):
    try:
        sqliteConnection = sqlite3.connect('SQLite_Python.db')
        cursor = sqliteConnection.cursor()
        print("Connected to SQLite")

        sqlite_insert_query = """INSERT INTO SqliteDb_developers
                          (id, name, email, joining_date, salary) 
                          VALUES (?, ?, ?, ?, ?);"""

        cursor.executemany(sqlite_insert_query, recordList)
        sqliteConnection.commit()
        print("Total", cursor.rowcount, "Records inserted successfully into SqliteDb_developers table")
        sqliteConnection.commit()
        cursor.close()

    except sqlite3.Error as error:
        print("Failed to insert multiple records into sqlite table", error)
    finally:
        if (sqliteConnection):
            sqliteConnection.close()
            print("The SQLite connection is closed")

recordsToInsert = [(4, 'Jos', '[email protected]', '2019-01-14', 9500),
                   (5, 'Chris', '[email protected]', '2019-05-15',7600),
                   (6, 'Jonny', '[email protected]', '2019-03-27', 8400)]

insertMultipleRecords(recordsToInsert)
Posted by: Guest on July-14-2020
1

insert sqlite

-- To insert a single row into a table, you use the following form of the INSERT statement:

INSERT INTO table (column1,column2 ,..)
VALUES( value1,	value2 ,...);Code language: SQL (Structured Query Language) (sql)
Posted by: Guest on August-20-2021
-2

sqlite insert

INSERT INTO TABLE (something1,something2, something3) VALUES (?, ?, ?)
Posted by: Guest on April-17-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language