diff --git a/ZRColaCompile/ZRColaCompile.vcxproj b/ZRColaCompile/ZRColaCompile.vcxproj
index f2e2af3..5b5d1e3 100644
--- a/ZRColaCompile/ZRColaCompile.vcxproj
+++ b/ZRColaCompile/ZRColaCompile.vcxproj
@@ -5,18 +5,10 @@
Debug
Win32
-
- Debug
- x64
-
Release
Win32
-
- Release
- x64
-
{87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}
@@ -27,23 +19,14 @@
Application
true
Unicode
-
-
- Application
- true
- Unicode
+ Dynamic
Application
false
true
Unicode
-
-
- Application
- false
- true
- Unicode
+ Dynamic
@@ -54,41 +37,32 @@
-
-
-
-
-
-
-
-
-
-
-
-
+
Create
Create
- Create
- Create
+
{3c61929e-7289-4101-8d0a-da22d6e1aea8}
+
+ {a3a36689-ac35-4026-93da-a3ba0c0e767c}
+
diff --git a/ZRColaCompile/ZRColaCompile.vcxproj.filters b/ZRColaCompile/ZRColaCompile.vcxproj.filters
index 0ed9f35..cd879ff 100644
--- a/ZRColaCompile/ZRColaCompile.vcxproj.filters
+++ b/ZRColaCompile/ZRColaCompile.vcxproj.filters
@@ -25,14 +25,20 @@
Source Files
+
+ Source Files
+
Header Files
+
+ Header Files
+
-
+
Resource Files
diff --git a/ZRColaCompile/dbsource.cpp b/ZRColaCompile/dbsource.cpp
new file mode 100644
index 0000000..4dd43ee
--- /dev/null
+++ b/ZRColaCompile/dbsource.cpp
@@ -0,0 +1,98 @@
+/*
+ Copyright 2015-2016 Amebis
+
+ This file is part of ZRCola.
+
+ ZRCola is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ ZRCola is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ZRCola. If not, see .
+*/
+
+#include "stdafx.h"
+
+
+ZRCola::DBSource::DBSource()
+{
+}
+
+
+ZRCola::DBSource::~DBSource()
+{
+}
+
+
+bool ZRCola::DBSource::Open(const wxString& filename)
+{
+ wxASSERT_MSG(!m_db, wxT("database already open"));
+
+ HRESULT hr;
+
+ // Create COM object.
+ hr = ::CoCreateInstance(CLSID_CADOConnection, NULL, CLSCTX_ALL, IID_IADOConnection, (LPVOID*)&m_db);
+ if (SUCCEEDED(hr)) {
+ // Open the database.
+ std::wstring cn;
+//#ifdef __WIN64__
+// cn = L"jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};";
+//#else
+ cn = L"Driver={Microsoft Access Driver (*.mdb)};";
+//#endif
+ cn += L"Dbq=";
+ cn += filename.c_str();
+ cn += L";Uid=;Pwd=;";
+ hr = m_db->Open(ATL::CComBSTR(cn.c_str()));
+ if (SUCCEEDED(hr)) {
+ return true;
+
+ m_db->Close();
+ } else
+ LogErrors();
+ wxLogMessage(_("Could not open database %s (%x)."), filename.c_str(), hr);
+ m_db.Release();
+ } else
+ wxLogMessage(_("Creating ADOConnection object failed (%x)."), hr);
+
+ return false;
+}
+
+
+void ZRCola::DBSource::LogErrors() const
+{
+ wxASSERT_MSG(m_db, wxT("database does not exist"));
+
+ // Get array of errors.
+ ADOErrors *errors = NULL;
+ if (SUCCEEDED(m_db->get_Errors(&errors))) {
+ // Get number of errors.
+ long n = 0;
+ errors->get_Count(&n);
+
+ // Iterate the errors.
+ for (long i = 0; i < n; i++) {
+ ADOError *err = NULL;
+ if (SUCCEEDED(errors->get_Item(ATL::CComVariant(i), &err))) {
+ // Write error number and description to the log.
+ long num = 0;
+ err->get_Number(&num);
+
+ ATL::CComBSTR desc;
+ err->get_Description(&desc);
+
+ wxLogMessage(_("ADO Error 0x%x: %ls"), num, (BSTR)desc);
+
+ err->Release();
+ }
+ }
+
+ errors->Release();
+ }
+}
diff --git a/ZRColaCompile/dbsource.h b/ZRColaCompile/dbsource.h
new file mode 100644
index 0000000..c2e4c96
--- /dev/null
+++ b/ZRColaCompile/dbsource.h
@@ -0,0 +1,57 @@
+/*
+ Copyright 2015-2016 Amebis
+
+ This file is part of ZRCola.
+
+ ZRCola is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ ZRCola is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with ZRCola. If not, see .
+*/
+
+#pragma once
+
+#include
+
+#include
+
+#include
+
+
+namespace ZRCola {
+ ///
+ /// Source database
+ ///
+ class DBSource {
+ public:
+ DBSource();
+ virtual ~DBSource();
+
+ ///
+ /// Opens the database
+ ///
+ /// \param[in] filename File name of the MDB database.
+ ///
+ /// \returns
+ /// - true when open succeeds
+ /// - false otherwise
+ ///
+ bool Open(const wxString& filename);
+
+ ///
+ /// Logs errors in database connections
+ ///
+ void LogErrors() const;
+
+ protected:
+ ATL::CComPtr m_db; ///< the database
+ };
+};
diff --git a/ZRColaCompile/main.cpp b/ZRColaCompile/main.cpp
index f14b43d..83d50af 100644
--- a/ZRColaCompile/main.cpp
+++ b/ZRColaCompile/main.cpp
@@ -20,16 +20,22 @@
#include "stdafx.h"
+///
+/// Main function
+///
int _tmain(int argc, _TCHAR *argv[])
{
wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
+ // Inizialize wxWidgets.
wxInitializer initializer;
if (!initializer) {
_ftprintf(stderr, wxT("Failed to initialize the wxWidgets library, aborting.\n"));
return -1;
}
+ // Set desired locale.
+ // TODO: Check user language setting and select the language accordingly.
wxLocale locale;
if (wxLocale::IsAvailable(wxLANGUAGE_SLOVENIAN)) {
wxString sPath(wxPathOnly(argv[0]));
@@ -39,6 +45,7 @@ int _tmain(int argc, _TCHAR *argv[])
wxVERIFY(locale.AddCatalog(wxT("ZRColaCompile")));
}
+ // Parse command line.
static const wxCmdLineEntryDesc cmdLineDesc[] =
{
{ wxCMD_LINE_SWITCH, "h" , "help", _("Show this help message"), wxCMD_LINE_VAL_NONE , wxCMD_LINE_OPTION_HELP },
@@ -62,5 +69,19 @@ int _tmain(int argc, _TCHAR *argv[])
return -1;
}
+ // Initialize COM (CoInitialize).
+ wxCoInitializer initializerOLE(COINIT_MULTITHREADED | COINIT_SPEED_OVER_MEMORY);
+ if (!initializerOLE) {
+ _ftprintf(stderr, _("Error initializing OLE.\n"));
+ return -1;
+ }
+
+ ZRCola::DBSource src;
+ const wxString& filenameIn = parser.GetParam(0);
+ if (!src.Open(filenameIn)) {
+ _ftprintf(stderr, _("Error opening %s input file.\n"), filenameIn.fn_str());
+ return 1;
+ }
+
return 0;
}
diff --git a/ZRColaCompile/stdafx.h b/ZRColaCompile/stdafx.h
index 7efcf36..6245f78 100644
--- a/ZRColaCompile/stdafx.h
+++ b/ZRColaCompile/stdafx.h
@@ -20,11 +20,17 @@
#pragma once
#include "../include/zrcola.h"
+#include "dbsource.h"
#include
#include
#include
#include
+#include
+
+#include // GUID helper to prevent LNK2001 errors (unresolved external symbol IID_IADO...)
+#include
+#include
#include
diff --git a/ZRColaUtils.sln b/ZRColaUtils.sln
index 22195c8..501447c 100644
--- a/ZRColaUtils.sln
+++ b/ZRColaUtils.sln
@@ -12,6 +12,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZRColaCompile", "ZRColaCompile\ZRColaCompile.vcxproj", "{87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxExtend", "lib\wxExtend\build\wxExtend.vcxproj", "{A3A36689-AC35-4026-93DA-A3BA0C0E767C}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -30,17 +32,24 @@ Global
{3C61929E-7289-4101-8D0A-DA22D6E1AEA8}.Release|x64.Build.0 = Release|x64
{87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Debug|Win32.ActiveCfg = Debug|Win32
{87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Debug|Win32.Build.0 = Debug|Win32
- {87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Debug|x64.ActiveCfg = Debug|x64
- {87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Debug|x64.Build.0 = Debug|x64
+ {87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Debug|x64.ActiveCfg = Debug|Win32
{87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Release|Win32.ActiveCfg = Release|Win32
{87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Release|Win32.Build.0 = Release|Win32
- {87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Release|x64.ActiveCfg = Release|x64
- {87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Release|x64.Build.0 = Release|x64
+ {87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}.Release|x64.ActiveCfg = Release|Win32
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C}.Debug|Win32.ActiveCfg = Debug|Win32
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C}.Debug|Win32.Build.0 = Debug|Win32
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C}.Debug|x64.ActiveCfg = Debug|x64
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C}.Debug|x64.Build.0 = Debug|x64
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C}.Release|Win32.ActiveCfg = Release|Win32
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C}.Release|Win32.Build.0 = Release|Win32
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C}.Release|x64.ActiveCfg = Release|x64
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{3C61929E-7289-4101-8D0A-DA22D6E1AEA8} = {A7D28E0C-BB96-444D-AAB0-F22A6483FE5F}
+ {A3A36689-AC35-4026-93DA-A3BA0C0E767C} = {A7D28E0C-BB96-444D-AAB0-F22A6483FE5F}
EndGlobalSection
EndGlobal
diff --git a/lib/wxExtend b/lib/wxExtend
index 6914baf..217d30f 160000
--- a/lib/wxExtend
+++ b/lib/wxExtend
@@ -1 +1 @@
-Subproject commit 6914baf5b2f0c9eaef036a0aaa347460652b96ea
+Subproject commit 217d30fde9a39ede4a4cd8bccc547029ccf6b614