-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpgimport.cpp
59 lines (45 loc) · 1.22 KB
/
pgimport.cpp
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// (c) 2009, 2010 Stephan Hohe
#include "soimport.hpp"
#include "pgbuilder.hpp"
#include "soschema.hpp"
#include <iostream>
#include <cstring>
#if defined(__cpp_lib_filesystem)
#include <filesystem>
using std::filesystem::absolute;
#elif defined(__cpp_lib_experimental_filesystem)
#include <experimental/filesystem>
using std::experimental::filesystem::absolute;
#else
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdexcept>
std::string absolute(const std::string &relpath) {
char* abspath = realpath(relpath.c_str(), nullptr);
if (!abspath) {
throw std::runtime_error(relpath + ": cannot resolve absolute path name: " + strerror(errno));
}
std::string absstr(abspath);
free(abspath);
return absstr;
}
#endif // filesystem
// ---------------------------------------------------------------------------
// main
int main(int argc, const char *argv[]) {
parse_config(CS_PG, argc, argv);
pqxx::connection db(config.connect);
if (config.simple) {
pgbuilder builder(db);
import_tables(builder);
}
else {
// We need an absolute path for this to work.
std::string absdir = absolute(config.dir);
pgcopybuilder builder(db, absdir);
import_tables(builder);
}
return 0;
}