-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQLite2mdb.cpp
More file actions
82 lines (64 loc) · 2.41 KB
/
SQLite2mdb.cpp
File metadata and controls
82 lines (64 loc) · 2.41 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "stdafx.h"
// AfxDaoTerm();
#include "afxdao.h"
#include "DBUtils/dsDatabase.h"
#include "sqlite2mdb_cmd_parser.h"
// std::wcout
#include <iostream>
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
static inline bool ExecuteCommandLineConv(int argc, wchar_t *argv[])
{
CCommandLineParser parser(argc, argv, sqlite2mdb_cmd_parser::GetDefaultCommands());
if (sqlite2mdb_cmd_parser::IsHelp(&parser)) {
std::wcout << L"SQLite database converter to MS DAO format database. HELP INFO:\n";
std::wcout << L"-s (--source) : source database (SQLite).\n";
std::wcout << L"-d (--destination): destination database (MS DAO). If destinations does not exist - mdb file will be created from source database schema.\n";
std::wcout << L"-l (--log) : log path (txt file).\n";
std::wcout << L"-h (--help) : help information.\n";
return true;
}
const std::wstring sSrcDBPath = sqlite2mdb_cmd_parser::GetSourcePath(&parser);
if (sSrcDBPath.empty()) {
std::wcout << L"No source database path defined. Use -s";
return false;
}
std::wstring sTargeDBPath = sqlite2mdb_cmd_parser::GetDestinationPath(&parser);
if (sTargeDBPath.empty()) {
std::wcout << L"No destination database path defined. Use -d";
return false;
}
const std::wstring sLogPath = sqlite2mdb_cmd_parser::GetLogPath(&parser);
if (!sLogPath.empty()) {
dsDatabase::SetLogPath(sLogPath.c_str());
}
dsDatabase dbSource;
if (!dbSource.OpenDB(sSrcDBPath.c_str())) {
std::wcout << L"Can not open source database: " << sSrcDBPath.c_str();
return false;
}
if (!dbSource.CloneTo(sTargeDBPath.c_str(), dsDBType::Dao)) {
std::wstring sMessage = L"Database clone operation failed:\n";
sMessage += L"Source: ";
sMessage += sSrcDBPath;
sMessage += L"\nTarget: ";
sMessage += sTargeDBPath;
dsDatabase::dbErrorHandler errorHandler = dbSource.GetErrorHandler();
if (errorHandler) {
errorHandler(sMessage.c_str());
}
std::wcout << sMessage.c_str();
return false;
}
return true;
}
int wmain(int argc, wchar_t* argv[])
{
const bool bRet = ::ExecuteCommandLineConv(argc, argv);
AfxDaoTerm();
if (!bRet) {
return 1;
}
return 0;
}