-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "Access" | ||
uuid = "14e0eef2-daed-11e8-2af2-4b4a56e59020" | ||
authors = ["Lars Hellemo <[email protected]>"] | ||
version = "0.1.0" | ||
version = "0.2.0" | ||
|
||
[deps] | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
# Access | ||
|
||
WIP: Query MS Access files via [JDBC](https://github.com/JuliaDatabases/JDBC.jl) and [UCanAccess](http://ucanaccess.sourceforge.net). | ||
Query MS Access files via [JDBC](https://github.com/JuliaDatabases/JDBC.jl) and [UCanAccess](http://ucanaccess.sourceforge.net). | ||
|
||
## Example | ||
|
||
Read data from Access database | ||
|
||
``` | ||
using Access | ||
fn = "C:\\temp\\TestDatabase.accdb" | ||
df = Access.querydb(fn,"SELECT * FROM Person WHERE BirthYear > 1980") | ||
df = Access.query(fn,"SELECT * FROM Person WHERE BirthYear > 1980") | ||
``` | ||
|
||
Modify data in Access database | ||
|
||
``` | ||
# Read table content to DataFrame | ||
StoredValues = Access.query(fn,"SELECT * FROM StoredValues;"); | ||
# Delete everything in table | ||
Access.query!(fn,"DELETE * FROM StoredValues;") | ||
# Re-insert data from DataFrame (inserting into table with same name as DataFrame) | ||
Access.@insertdf(fn,StoredValues) | ||
# Alternatively, specify table explicitly: | ||
Access.insertdf(fn,StoredValues,"StoredValues") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,49 @@ | ||
using Test | ||
using Access | ||
|
||
fn = cp(joinpath(@__DIR__,"TestDatabase.accdb"),joinpath(mktempdir(;cleanup=false),"Test.accdb")) | ||
|
||
@testset "Read data from db" begin | ||
|
||
fn = joinpath(@__DIR__,"TestDatabase.accdb") | ||
df = Access.querydb(fn,"SELECT * FROM Person WHERE BirthYear > 1980") | ||
# fn = joinpath(@__DIR__,"TestDatabase.accdb") | ||
@test isfile(fn) | ||
df = Access.query(fn,"SELECT * FROM Person WHERE BirthYear > 1980") | ||
|
||
@test size(df,1) == 1 # One Row | ||
@test df.FirstName[1] == "Slim" | ||
@test df.LastName[1] == "Shady" | ||
@test df.ID[1] == 3 | ||
end | ||
end | ||
|
||
|
||
|
||
@testset "Modify db data" begin | ||
|
||
# Read table content to DataFrame | ||
StoredValues = Access.query(fn,"SELECT * FROM StoredValues;"); | ||
|
||
# Delete everything in table | ||
Access.query!(fn,"DELETE * FROM StoredValues;") | ||
|
||
# Check table empty? | ||
shouldbeemtpy = Access.query(fn,"SELECT * FROM StoredValues;"); | ||
@test size(shouldbeemtpy,1) == 0 | ||
|
||
# Re-insert data from DataFrame | ||
Access.@insertdf(fn,StoredValues) | ||
shouldnotbeemtpy = Access.query(fn,"SELECT * FROM StoredValues;"); | ||
@test size(shouldnotbeemtpy,1) > 0 | ||
|
||
# Check table content | ||
@test shouldnotbeemtpy[6,4] == "Mashall Mathers" | ||
@test shouldnotbeemtpy[2,3] ≈ 3.3 | ||
|
||
# Alternatively, specify table explicitly: | ||
Access.query!(fn,"DELETE * FROM StoredValues;") | ||
Access.insertdf(fn,StoredValues,"StoredValues") | ||
shouldnotbeemtpy = Access.query(fn,"SELECT * FROM StoredValues;"); | ||
@test shouldnotbeemtpy[2,3] ≈ 3.3 | ||
end | ||
|
||
# TODO: Figure out why this (and cleanup) fails | ||
# rm(dirname(fn);recursive=true) |