Bureaucrats, cc_docs_admin, cc_staff
2,318
edits
Line 13: | Line 13: | ||
This most common way of interacting with an SQLite (or other) database is programmatically, i.e. inside of a program written in one of various languages like [[R]] or [[Python]], using a series of function calls to open a connection to the database, execute queries that can read or update existing data in the database as well as inserting new data and finally close the connection to the SQLite database. | This most common way of interacting with an SQLite (or other) database is programmatically, i.e. inside of a program written in one of various languages like [[R]] or [[Python]], using a series of function calls to open a connection to the database, execute queries that can read or update existing data in the database as well as inserting new data and finally close the connection to the SQLite database. | ||
= | <tabs> | ||
<tab name="Python"> | |||
<source lang="python"> | |||
#!/usr/bin/env python3 | |||
For Python we can use the module | # For Python we can use the module sqlite3, installed in a virtual environment, | ||
# to access an SQLite database | |||
import sqlite3 | import sqlite3 | ||
Line 32: | Line 31: | ||
dbase.close() | dbase.close() | ||
</source> | |||
== | </tab> | ||
<tab name="R"> | |||
<source lang="r"> | |||
# Using R, the first step is to install the RSQLite package in your R environment, | |||
# after which you can use code like the following to interact with the SQLite database | |||
library(DBI) | |||
# Connect to the database... | # Connect to the database... | ||
dbase <- dbConnect(RSQLite::SQLite(),"foo.sqlite") | dbase <- dbConnect(RSQLite::SQLite(),"foo.sqlite") | ||
Line 56: | Line 54: | ||
# Close the database connection | # Close the database connection | ||
dbDisconnect(dbase) | dbDisconnect(dbase) | ||
</source> | </source> | ||
</tab> | </tab> |