Read a locked .db file from Photos App with R - sql

I want to analize my Photos App data using R. I know there is a photos.db file in my Library which, I'd guess, have all the metadata on my pictures. I tried opening the file but I am getting the Error in result_create(conn#ptr, statement) : database is locked
# To open any db file, you simply:
library(RSQLite)
filename <- "~Pictures/MyLibrary.photoslibrary/database/photos.db"
sqlite.driver <- dbDriver("SQLite")
db <- dbConnect(sqlite.driver, dbname = filename)
dbListTables(db)
Any idea of how can I analyze Photos App data or to open this file as a read-only db?
Thanks! :)

Related

Save the output as csv file from VScode programmatically

My Requirement: Save the SQL query output (received the data) in to the local drives in csv file format.
My OS: Windows 10 64 bit
VS Code 1.67.1:
I have installed the following extensions to connect with snowflake data warehouse:
SQL Tools
Snowflake driver for SQL Tools
I have successfully connected my snowflake (cloud) data warehouse and received the data at
the VS code.
What I want is to save (export) the output (received the data) to the local file (for example to D:\result\result.csv).
How can I achieve that?
image attached for your reference.
thank you all.
pmk
If you can run a bit of python, this does pretty much what you need
import snowflake.connector
import csv
conn = snowflake.connector.connect(
user='',
password='',
account='',
warehouse='',
database='',
schema='',
role=''
)
results = conn.cursor().execute("""MY QUERY""").fetchall()
csvfile = open(r"PATH TO FILE",'a', newline='')
output = csv.writer(csvfile)
output.writerows(results)
csvfile.close

In R disk.frame package ,how to read csv file using `csv_to_disk.frame()`?

There are csv files in "D:\dc" as image , when I run 'csv_to_disk.frame' to read them, it's failed . Anyone can help ? Thanks!
library(disk.frame)
library(tidyverse)
files <- file.path("D:\\dc\\*.csv")
mydisk_frame <- csv_to_disk.frame(
files,
outdir="C:\\mydisk_frame.df",
overwrite = T
)

R read a local .mdf file

I have a database file (a .mdf file from a microsoft SQL server) that I copied on my disk. It comes from a device, and I would like to read the data, preferably in R. I am totally new to SQL, and I don't understand how to deal with a local file.
I tried
library(RMySQL)
con <- dbConnect(RMySQL::MySQL(), dbname = "MGCDBase")
which gave me
Error in .local(drv, ...) :
Failed to connect to database: Error: Can't connect to MySQL server on 'localhost' (0)
I don't get if it is because there is a password, if I am doing it wrong, or if I should use something else than R or RMySQL.
Any help or advise would be welcome

writeOGR error: creation of output file failed

I'm an R rookie and attempting to create home ranges from fish telemetry data using kernel density estimates within the adehabitatHR package
kud <- kernelUD(muskydetectdata.P[,6], h="href", extent = 5)
class(kud)
image(kud)
kud[[1]]#h
muskykud.P95 <- getverticeshr(kud, percent = 95)
muskykud.P95
muskykud.P50 <- getverticeshr(kud, percent = 50)
muskykud.P50
when exporting to a shapefile
writeOGR(muskydetectdata.sp,"musky_kde1", "gps",
driver="ESRI Shapefile",
dataset_options= "FieldName= id")
an error message is displayed
##creation of output file failed
I have also attempted to use writeSpatialShape with similar results
I'm using R version 3.3.2 on windows 64 bit
I had the same problem and have solved it only when I added a full name of my directory and a name of a layer plus a shp suffix:
writeOGR(muskydetectdata.sp, dsn="d:/your directory here/musky_kde.shp", layer="musky_kde", driver="ESRI Shapefile")
I had that same error.
I resolved mine by correcting the directory it was saving to (making sure it existed)
e.g.
writeOGR(muskydetectdata.sp, dsn = save.dir, layer = filename.save, driver = 'ESRI Shapefile')
where save.dir is the directory you want saved as a string and filename.save is the filename you want it saved as (excluding extension)
I guess you are trying to write on an existing file and the writeOGR function don't allow that. I guess this is a known behavior of some drivers supported by OGR (as far as I remember in R as in python and in the C API).
You have to check if the file exists prior to your writing and removing it (or changing the path you want to use).
For example here the first write operation succeed but the attempt to overwrite the file fails with your error message :
> rgdal::writeOGR(spdf, 'b.shp', layer="brazil", driver='ESRI Shapefile')
> rgdal::writeOGR(spdf, 'b.shp', layer="brazil", driver='ESRI Shapefile')
Error in rgdal::writeOGR(spdf, "b.shp", layer = "brazil", driver = "ESRI Shapefile") :
Creation of output file failed

SQL - How to attach FileStream enabled db without log file

I'm trying to attach a FileStream enabled database without a log file. My SQL looks something like this:
USE master
CREATE DATABASE MyDB
ON PRIMARY(NAME = N'MyDB', FILENAME = 'C:\myDB.MDF' ),
FILEGROUP myFileGroup CONTAINS FILESTREAM ( NAME = myData, FILENAME = 'C:\myFileGroup')
For Attach
Here is the error I'm receiving:
Msg 5173, Level 16, State 3, Line 2
One or more files do not match the primary file of the database.
If you are attempting to attach a database, retry the operation with the correct files.
If this is an existing database, the file may be corrupted and should be restored from a backup.
Does anyone know if it's possible to attach a FileStream enabled database without the original log file?
Try this blog post:
http://blog.sqlauthority.com/2010/04/26/sql-server-attach-mdf-file-without-ldf-file-in-database/
I would personally go with this one:
CREATE DATABASE TestDb ON
(FILENAME = N'C:\Database\Test\TestDb.mdf')
FOR ATTACH_REBUILD_LOG
GO
And when you have your log rebuilt, you can enable filestream; or try to reattach with the filestream location.