Insert CSV into database

Thursday, 31 May 2018 · 4 messages · last reply 1 Jun 2018
BE
Ben Engbers31 May 2018 16:21 #
Hi, My goals is to use my R clientdriver to insert csv-files into a new databases. But before that, I'm experimenting with the GUI. From the documentation for the CSV-parser, I have taken this code:
for $file in
file:list("/home/bengbers/DataScience/RBaseX/Examples/Parse", false(),
"*.csv")
return db:add("CSV_test", $file, "", map {
  'parser': 'csv',
  'csvparser': map { 'header': 'yes', 'separator': ';' }
})
BaseX returns: Error: Stopped at /home/bengbers/DataScience/Eindopdracht/Data/file, 2/14: [FODC0002] Resource 'Test_Parse.csv' does not exist. I didn't enter this path. It was used yesterday when browsing to the datafiles that were inserted into another test-database.
let $file :=
file:list("/home/bengbers/DataScience/RBaseX/Examples/Parse", false(),
"*.csv")
return $file
BaseX returns: Test_Parse.csv Test_Parse (exemplaar).csv If I create a new database, it neatly adds the two csv-files. My questions are: - which query I have to use to insert csv-files? - obviously, BasexGUI uses the wrong path. How should I adjust this path? Cheers, Ben
CG
Christian Grün1 Jun 2018 12:38 #
Hi Ben, As file:list only returns relative file paths, you will have to prepend the root path later on:
  let $root := "/home/bengbers/DataScience/RBaseX/Examples/Parse/"
  for $file in file:list($root, false(), "*.csv")
  return db:add("CSV_test", $root || $file, "", map {
    'parser': 'csv',
    'csvparser': map { 'header': 'yes', 'separator': ';' }
  })
Another alternative is to use the file:children function:
  let $root := "/home/bengbers/DataScience/RBaseX/Examples/Parse/"
  for $path in file:children($root)[ends-with(., ".csv")]
  return db:add("CSV_test", $path, "", map { ... })
Cheers, Christian
Quoted text · Ben Engbers · 43 lines
On Thu, May 31, 2018 at 4:21 PM, Ben Engbers <Ben.Engbers at be-logical.nl> wrote: > Hi, > My goals is to use my R clientdriver to insert csv-files into a new > databases. But before that, I'm experimenting with the GUI. > > From the documentation for the CSV-parser, I have taken this code: > > ​​ > for $file in > file:list("/home/bengbers/DataScience/RBaseX/Examples/Parse", false(), > "*.csv") > return db:add("CSV_test", $file, "", map { > 'parser': 'csv', > 'csvparser': map { 'header': 'yes', 'separator': ';' } > }) > > BaseX returns: > Error: > Stopped at /home/bengbers/DataScience/Eindopdracht/Data/file, 2/14: > [FODC0002] Resource 'Test_Parse.csv' does not exist. > > I didn't enter this path. It was used yesterday when browsing to the > datafiles that were inserted into another test-database. > > let $file := > file:list("/home/bengbers/DataScience/RBaseX/Examples/Parse", false(), > "*.csv") > return $file > > BaseX returns: > Test_Parse.csv > Test_Parse (exemplaar).csv > > If I create a new database, it neatly adds the two csv-files. > > My questions are: > - which query I have to use to insert csv-files? > - obviously, BasexGUI uses the wrong path. How should I adjust this path? > > Cheers, > Ben >
BE
Ben Engbers1 Jun 2018 13:47 #
Hi Christian, The alternative worked so my first question is answered. But the second question still remains. Why does BaseX-GUI use an old path (/home/bengbers/DataScience/Eindopdracht/Data/file), a path I didn't even enter and does not use the path I entered in the query (/home/bengbers/DataScience/RBaseX/Examples/Parse/)? Cheers, Ben
Quoted text · Christian Grün · 21 lines
Op 01-06-18 om 12:38 schreef Christian Grün: > Hi Ben, > > As file:list only returns relative file paths, you will have to prepend > the root path later on: > > let $root := "/home/bengbers/DataScience/RBaseX/Examples/Parse/" > for $file in file:list($root, false(), "*.csv") > return db:add("CSV_test", $root || $file, "", map { > 'parser': 'csv', > 'csvparser': map { 'header': 'yes', 'separator': ';' } > }) > > Another alternative is to use the file:children function: > > let $root := "/home/bengbers/DataScience/RBaseX/Examples/Parse/" > for $path in file:children($root)[ends-with(., ".csv")] > return db:add("CSV_test", $path, "", map { ... }) > > Cheers, > Christian
CG
Christian Grün1 Jun 2018 13:50 #
Hi Ben, This may be the directory where you started the BaseX server from. If you use the client/server architecture, both the client and the server can have different working directories, so you should always specify full paths. Cheers, Christian
Quoted text · Ben Engbers · 36 lines
Ben Engbers <Ben.Engbers at be-logical.nl> schrieb am Fr., 1. Juni 2018, 13:47: > Hi Christian, > > The alternative worked so my first question is answered. But the second > question still remains. > > Why does BaseX-GUI use an old path > (/home/bengbers/DataScience/Eindopdracht/Data/file), a path I didn't > even enter and does not use the path I entered in the query > (/home/bengbers/DataScience/RBaseX/Examples/Parse/)? > > Cheers, > Ben > > Op 01-06-18 om 12:38 schreef Christian Grün: > > Hi Ben, > > > > As file:list only returns relative file paths, you will have to prepend > > the root path later on: > > > > let $root := "/home/bengbers/DataScience/RBaseX/Examples/Parse/" > > for $file in file:list($root, false(), "*.csv") > > return db:add("CSV_test", $root || $file, "", map { > > 'parser': 'csv', > > 'csvparser': map { 'header': 'yes', 'separator': ';' } > > }) > > > > Another alternative is to use the file:children function: > > > > let $root := "/home/bengbers/DataScience/RBaseX/Examples/Parse/" > > for $path in file:children($root)[ends-with(., ".csv")] > > return db:add("CSV_test", $path, "", map { ... }) > > > > Cheers, > > Christian >

⚡Generated with XQuery