-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmariadb-3.R
34 lines (26 loc) · 1.05 KB
/
rmariadb-3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(RMariaDB)
# The connection method below uses a password stored in a settings file.
# R needs a full path to find the settings file.
rmariadb.settingsfile<-"C:\\ProgramData\\MySQL\\MySQL Server 8.0\\newspaper_search_results.cnf"
rmariadb.db<-"newspaper_search_results"
storiesDb<-dbConnect(RMariaDB::MariaDB(),default.file=rmariadb.settingsfile,group=rmariadb.db)
# Optional. List the table. This confirms we connected to the database.
dbListTables(storiesDb)
# Create the query statement.
query<-"INSERT INTO tbl_newspaper_search_results (
story_title,
story_date_published,
story_url,
search_term_used)
VALUES('THE LOST LUSITANIA.',
'1915-05-21',
LEFT(RTRIM('http://newspapers.library.wales/view/4121281/4121288/94/'),99),
'German+Submarine');"
# Optional. Prints out the query in case you need to troubleshoot it.
print(query)
# Execute the query on the storiesDb that we connected to above.
rsInsert <- dbSendQuery(storiesDb, query)
# Clear the result.
dbClearResult(rsInsert)
# Disconnect to clean up the connection to the database.
dbDisconnect(storiesDb)