SQLite: Difference between revisions

Jump to navigation Jump to search
196 bytes removed ,  4 years ago
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.  


===Python===
<tabs>
<tab name="Python">
<source lang="python">
#!/usr/bin/env python3


For Python we can use the module <tt>sqlite3</tt>, installed in a virtual environment, to access an SQLite database:
# For Python we can use the module sqlite3, installed in a virtual environment,  
{{File
# to access an SQLite database
  |name=sqlite.py
  |lang="python"
  |contents=
#!/usr/bin/env python3
import sqlite3
import sqlite3


Line 32: Line 31:


dbase.close()
dbase.close()
}}
</source>
===R===
</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)


Using R, the first step is to install the <tt>RSQLite</tt> package in your R environment, after which you can use code like the following to interact with the SQLite database,
{{File
  |name=sqlite.R
  |lang="r"
  |contents=
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)
}}
===Perl===
===C/C++===
<tabs>
<tab name="C">
<source lang="c">
#include <string.h>
#include <sqlite3.h>
int main(int argc,char** argv)
{
  return 0;
}
</source>
</source>
</tab>
</tab>
Bureaucrats, cc_docs_admin, cc_staff
2,318

edits

Navigation menu