Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added command line support. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ To build the project yourself you have to build wxWidgets for your appropriate t
3) Build your target configuration DLL Debug/DLL Release.
4) Generate mdb2sqlite project using CMake selecting the required toolset.

## Command line
> mdb2sqlite.exe <SourcePath> <TargetPath>

## Additional notes
Does not work if database is password protected

Expand Down
1 change: 1 addition & 0 deletions src/FieldStatements.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ struct CDaoTableDefInfo;
struct CDaoFieldInfo;

#include "OnAction.h"
#include <string>

#ifndef __DB_FIELD_H__
#include "DBField.h"
Expand Down
1 change: 1 addition & 0 deletions src/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <vector>
#include <string>

namespace file_utils
{
Expand Down
4 changes: 2 additions & 2 deletions src/OnAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void CSettingsReader::Dumping(std::vector<CString> &statements, std::vector<CStr
dumpfile.close();
}

bool CSettingsReader::Control(const char *Path, const char *dPath, CUIObs *pObs, bool bConvert)
bool CSettingsReader::Control(const char *Path, const char *dPath, CUIObs *pObs, bool bConvert, bool bCmd)
{
AfxDaoInit();
std::vector<CString> statements, InsertStatements, RelationFields, IndexStatements, UniqueFields, CollateIndexFields,
Expand Down Expand Up @@ -156,7 +156,7 @@ bool CSettingsReader::Control(const char *Path, const char *dPath, CUIObs *pObs,
}
}

if( bConvert )
if( bConvert && !bCmd)
{
CStructPreviewDlg dlg(nullptr, structure);
bool bOK = dlg.ShowModal() == wxID_OK;
Expand Down
2 changes: 1 addition & 1 deletion src/OnAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CSettingsReader
{
public:
static void ReadFromCSimpleIni(CSettings &settings);
static bool Control(const char *Path, const char *dPath, CUIObs *pObs, bool bConvert);
static bool Control(const char *Path, const char *dPath, CUIObs *pObs, bool bConvert, bool bCmd);
private:
static void Dumping(std::vector<CString> &statements, std::vector<CString> &InsertStatements, std::vector<CString> &RelationFields, std::vector<CString> &IndexStatements,
const char *&dPath);
Expand Down
39 changes: 37 additions & 2 deletions src/mdb2sqlite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,45 @@ namespace internal
wxMessageDialog dlg(pParent, sMsg, sTitle);
dlg.ShowModal();
}

class CUIObsCmdImpl : public CUIObs
{
public:
virtual void CreateAdditionalItems() override { };
virtual void SetDefaultStyle(const wxTextAttr &atr) override { };
virtual void WriteText(std::wstring sMsg) override { };
virtual void SetRange(int nRange) override { };
virtual void SetValue(int nValue) override { };
};

static bool UseCommandLine(int argc, const wxCmdLineArgsArray &argv)
{
if (3 == argc) {
const wxString sSource = argv[1];
const wxString sTarget = argv[2];

if (sSource.empty() || sTarget.empty()) {
return false;
}

CUIObsCmdImpl obsImpl;

const bool bRet = CSettingsReader::Control(sSource.mb_str(), sTarget.mb_str(), &obsImpl, true, true);
if (bRet) {
return true;
}
}

return false;
}
};

bool MyApp::OnInit()
{
if (internal::UseCommandLine(argc, argv)) {
return false;
}

int nPosX, nPosY, nSizeX;
file_utils::GetWindowInformation(nPosX, nPosY, nSizeX);

Expand Down Expand Up @@ -151,7 +186,7 @@ void CMainDlg::OnDump( wxCommandEvent &WXUNUSED(event) )
const char *pSrcPath = sSrcPath.mb_str();
const char *pDstPath = sDstPath.mb_str();

CSettingsReader::Control(pSrcPath, pDstPath, this, false);
CSettingsReader::Control(pSrcPath, pDstPath, this, false, false);
internal::ShowMessageDlg(this, wxT("Succesfully dumped."), wxT("Dump information"));
}

Expand All @@ -174,7 +209,7 @@ void CMainDlg::OnConvert(wxCommandEvent &WXUNUSED(event) )
const char *pSrcPath = sPathMDB.mb_str();
const char *pDPath = sPathSQLite.mb_str();

bool bRet = CSettingsReader::Control(pSrcPath, pDPath, this, true);
bool bRet = CSettingsReader::Control(pSrcPath, pDPath, this, true, false);
if( bRet )
internal::ShowMessageDlg(this, wxString::Format(wxT("Succesfully exported %s to SQLite"), sFilename), wxT("Succesfully exported to SQLite"));
}
Expand Down
1 change: 1 addition & 0 deletions src/sqlitestatementexecution.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <vector>
#include <string>

class CUIObs;
struct sqlite3;
Expand Down