Bureaucrats, cc_docs_admin, cc_staff
2,318
edits
Line 13: | Line 13: | ||
==Accessing SQLite from software== | ==Accessing SQLite from software== | ||
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]] | 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]], [[C++]] and [[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 so that the changes (if any) are flushed to the SQLite file. In the simple example below, we suppose that the database has already been created with a table called <tt>employee</tt> that has two columns, the string <tt>name</tt> and <tt>age</tt>, an integer. | ||
<tabs> | <tabs> | ||
Line 42: | Line 42: | ||
age <- 34 | age <- 34 | ||
# Connect to the database... | # Connect to the database... | ||
Line 48: | Line 47: | ||
# A parameterized query | # A parameterized query | ||
paste(c("INSERT INTO employee(name,age) VALUES(\"John Smith\",",toString(age),");" | query <- paste(c("INSERT INTO employee(name,age) VALUES(\"John Smith\",",toString(age),");"),collapse='') | ||
dbExecute(dbase,query) | dbExecute(dbase,query) | ||