-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
db.vacuum: Add module to manage SQL vaccum #2462
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
MODULE_TOPDIR = ../.. | ||
|
||
PGM = db.vacuum | ||
|
||
include $(MODULE_TOPDIR)/include/Make/Script.make | ||
|
||
default: script |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||||
<h2>DESCRIPTION</h2> | ||||||||
|
||||||||
<em>db.vacuum</em> runs SQL VACUUM or sets up automatic vacuum procedures. | ||||||||
|
||||||||
<h2>NOTES</h2> | ||||||||
|
||||||||
<h2>EXAMPLES</h2> | ||||||||
|
||||||||
<div class="code"><pre> | ||||||||
db.vacuum operation=vacuum | ||||||||
db.vacuum operation=enable_auto_vacuum | ||||||||
db.vacuum operation=disable_auto_vacuum | ||||||||
db.vacuum operation=incremental_vacuum | ||||||||
</pre></div> | ||||||||
|
||||||||
<div class="code"><pre> | ||||||||
db.vacuum driver=sqlite database=/opt/sqlite.db | ||||||||
</pre></div> | ||||||||
|
||||||||
<h2>SEE ALSO</h2> | ||||||||
|
||||||||
<em> | ||||||||
<a href="db.dropdb.html">db.dropdb</a>, | ||||||||
<a href="db.dropcolumn.html">db.dropcolumn</a>, | ||||||||
<a href="db.droptable.html">db.droptable</a>, | ||||||||
<a href="v.db.droprow.html">v.db.droprow</a>, | ||||||||
<a href="v.db.dropcolumn.html">v.db.dropcolumn</a>, | ||||||||
<a href="v.db.droptable.html">v.db.droptable</a>, | ||||||||
<a href="db.login.html">db.login</a>, | ||||||||
<a href="db.connect.html">db.connect</a>, | ||||||||
<a href="db.tables.html">db.tables</a>, | ||||||||
<a href="db.describe.html">db.describe</a> | ||||||||
<a href="db.execute.html">db.execute</a> | ||||||||
</em> | ||||||||
|
||||||||
<p> | ||||||||
<a href="sql.html">GRASS SQL interface</a> | ||||||||
|
||||||||
<h2>AUTHORS</h2> | ||||||||
|
||||||||
Markus Neteler<br> | ||||||||
Driver and database options added by Martin Landa, Czech Technical University in Prague, Czech Republic | ||||||||
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(affiliation taken from other HTML file under |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,86 @@ | ||||||
#!/usr/bin/env python3 | ||||||
|
||||||
############################################################################ | ||||||
# | ||||||
# MODULE: db.vacuum | ||||||
# AUTHOR(S): Vaclav Petras | ||||||
# PURPOSE: Interface to db.execute to drop an attribute table | ||||||
# COPYRIGHT: (C) 2022 by Vaclav Petras and the GRASS Development Team | ||||||
# | ||||||
# This program is free software under the GNU General | ||||||
# Public License (>=v2). Read the file COPYING that | ||||||
# comes with GRASS for details. | ||||||
# | ||||||
############################################################################# | ||||||
|
||||||
# %module | ||||||
# % description: Vacuums (cleans) database from dropped (deleted) data | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
# % keyword: database | ||||||
# % keyword: attribute table | ||||||
# %end | ||||||
|
||||||
# %option | ||||||
# % key: operation | ||||||
# % type: string | ||||||
# % required: yes | ||||||
# % multiple: no | ||||||
# % options: vacuum,enable_auto_vacuum,disable_auto_vacuum,enable_incremental_vacuum,do_incremental_vacuum | ||||||
# % description: Operation to be performed | ||||||
# %end | ||||||
|
||||||
# %option G_OPT_DB_DRIVER | ||||||
# % label: Name of database driver | ||||||
# % description: If not given then default driver is used | ||||||
# % guisection: Connection | ||||||
# %end | ||||||
|
||||||
# %option G_OPT_DB_DATABASE | ||||||
# % label: Name of database | ||||||
# % description: If not given then default database is used | ||||||
# % guisection: Connection | ||||||
# %end | ||||||
|
||||||
import sys | ||||||
|
||||||
import grass.script as gs | ||||||
|
||||||
|
||||||
def database_vacuum(operation, database, driver): | ||||||
if operation == "vacuum": | ||||||
sql = "VACUUM;" | ||||||
elif operation == "enable_auto_vacuum" and driver == "sqlite": | ||||||
sql = "PRAGMA auto_vacuum = 'full'; VACUUM;" | ||||||
elif operation == "disable_auto_vacuum" and driver == "sqlite": | ||||||
sql = "PRAGMA auto_vacuum = 'none'; VACUUM;" | ||||||
elif operation == "enable_incremental_vacuum" and driver == "sqlite": | ||||||
sql = "PRAGMA auto_vacuum = 'incremental'; VACUUM;" | ||||||
elif operation == "do_incremental_vacuum" and driver == "sqlite": | ||||||
sql = "PRAGMA incremental_vacuum;" | ||||||
else: | ||||||
gs.fatal(_("Unsupported operation <{operation} for database driver <{driver}>").format(operation=operation, driver=driver)) | ||||||
gs.run_command("db.execute", input=f"{sql}", database=database, driver=driver, error="fatal") | ||||||
|
||||||
|
||||||
def main(): | ||||||
options, unused_flags = gs.parser() | ||||||
table = options["table"] | ||||||
|
||||||
if not options["driver"] or not options["database"]: | ||||||
# check if DB parameters are set, and if not set them. | ||||||
gs.run_command("db.connect", flags="c", quiet=True) | ||||||
|
||||||
kv = gs.db_connection() | ||||||
if options["database"]: | ||||||
database = options["database"] | ||||||
else: | ||||||
database = kv["database"] | ||||||
if options["driver"]: | ||||||
driver = options["driver"] | ||||||
else: | ||||||
driver = kv["driver"] | ||||||
# schema needed for PG? | ||||||
|
||||||
database_vacuum(operation=options["operation"], database, driver) | ||||||
Check failure on line 83 in scripts/db.vacuum/db.vacuum.py GitHub Actions / Python Code Quality Checks (ubuntu-22.04)Ruff
|
||||||
|
||||||
if __name__ == "__main__": | ||||||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ <h2>EXAMPLES</h2> | |
<h2>SEE ALSO</h2> | ||
|
||
<em> | ||
<a href="db.vacuum.html">db.vacuum</a>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add this to
|
||
<a href="db.droptable.html">db.droptable</a>, | ||
<a href="db.execute.html">db.execute</a>, | ||
<a href="v.db.addcolumn.html">v.db.addcolumn</a>, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.