LibreOffice Logo LibreOffice Logo Extensions, Documentation and Templates repository

logo250 Sqlite for LibreOffice on Windows

Adds sqlite3 support to LibreOffice on Windows.

Base Calc Draw Impress Macro Presentations Writer
Download latest

latest release: 2024-03-21 11:13:15

Description

Description

The sqlite3 module is a powerful part of the Python standard library; it lets us work with a fully featured on-disk SQL database without installing any additional software.

This extension adds sqlite3 support to LibreOffice on Windows.

 

Example

The demo create a database in the user's home directory called test.db and creates a table called fish with three columns: name, species, and tank_number. It then adds two rows of data to the table, and then reads the data back out. It then modifies the data in the table, and then deletes one of the rows.

>>> from sql_util import SqlCtx
>>> from pathlib import Path
>>> cs = Path.home() / "Documents/test.db"

# Creating a Connection to a SQLite Database
>>> with SqlCtx(cs) as db:
...     print(db.connection.total_changes)
... 
0

# Creating a table in the database
>>> with SqlCtx(cs) as db:
...     _ = db.cursor.execute("CREATE TABLE fish (name TEXT, species TEXT, tank_number INTEGER)")
... 


# Adding Data to the SQLite Database
>>> with SqlCtx(cs) as db:
...     with db.connection:
...         _ = db.cursor.execute("INSERT INTO fish VALUES ('Sammy', 'shark', 1)")
...         _ = db.cursor.execute("INSERT INTO fish VALUES ('Jamie', 'cuttlefish', 7)")
...     print(db.connection.total_changes)
... 
2

# Reading Data from the SQLite Database
>>> with SqlCtx(cs) as db:
...     rows = db.cursor.execute("SELECT name, species, tank_number FROM fish").fetchall()
...     for row in rows:
...         for key in row.keys():
...             print(f"{key} = {row[key]}")
... 
name = Sammy
species = shark
tank_number = 1
name = Jamie
species = cuttlefish
tank_number = 7

>>> with SqlCtx(cs) as db:
...     target_fish_name = "Jamie"
...     rows = db.cursor.execute(
...         "SELECT name, species, tank_number FROM fish WHERE name = ?",
...         (target_fish_name,),
...     ).fetchall()
...     for row in rows:
...         for key in row.keys():
...             print(f"{key} = {row[key]}")
... 
name = Jamie
species = cuttlefish
tank_number = 7


# Modifying Data in the SQLite Database
>>> with SqlCtx(cs) as db:
...     new_tank_number = 2
...     moved_fish_name = "Sammy"
...     with db.connection:
...         _ = db.cursor.execute("UPDATE fish SET tank_number = ? WHERE name = ?", (new_tank_number, moved_fish_name))
...         rows = db.cursor.execute("SELECT name, species, tank_number FROM fish").fetchall()
...         for row in rows:
...             for key in row.keys():
...                 print(f"{key} = {row[key]}")
... 
name = Sammy
species = shark
tank_number = 2
name = Jamie
species = cuttlefish
tank_number = 7


# Deleting Data from the SQLite Database
>>> with SqlCtx(cs) as db:
...     target_fish_name = "Sammy"
...     with db.connection:
...         _= db.cursor.execute("DELETE FROM fish WHERE name = ?", (target_fish_name,))
...         rows = db.cursor.execute("SELECT name, species, tank_number FROM fish").fetchall()
...         for row in rows:
...             for key in row.keys():
...                 print(f"{key} = {row[key]}")
... 
name = Jamie
species = cuttlefish
tank_number = 7

 

 

Homepage: https://github.com/Amourspirit/python-libreoffice-sqlite3-win-ext#readme

Repository: https://github.com/Amourspirit/python-libreoffice-sqlite3-win-ext

Release Description Compatibility Operating Systems License Release notes Updated  
1.0.3 startup fix 7.0 Windows MIT Minor fix for startup dialog 2023-11-04 20:39:42 Download
1.0.0 Initial Release 7.0 Windows MIT Initial Release 2023-10-28 16:27:22 Download

Related Extensions

Pandas for LibreOffice

Logo for Pandas for LibreOffice

Pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language.&

09-2024

2770

★ ★ ★ ★ ★

Include Python Path for LibreOffice

Logo for Include Python Path for LibreOffice

Give the ability to include external python paths in LibreOffice. Making other python packages available in Python macros and scripts.

05-2024

2207

Not rated yet

Python Numpy Extension for LibreOffice

Logo for Python Numpy Extension for LibreOffice

Numpy is The fundamental package for scientific computing with Python.
This is a LibreOffice extension that allows you to use Numpy in LibreOffice python macros and scripts.

09-2024

2263

Not rated yet

OooDev GUI Automation for Windows

Logo for OooDev GUI Automation for Windows

Although the LibreOffice API gives access to many parts of the LibreOffice application, it does not give access to everything. This project is an extension that allows access to the GUI. This project a set of python modules to automate the LibreO

04-2024

919

Not rated yet

Feedback

☆ ☆ ☆ ☆ ☆

Post your review

You cannot post reviews until you have logged in. Login Here.

Reviews

No one has commented on this page yet.

RSS feed for reviews on this page | RSS feed for all reviews