Work continues

This commit is contained in:
Simon Rozman 2016-02-26 12:20:08 +01:00
parent 0e17c9d4dc
commit 866fceb081
8 changed files with 210 additions and 39 deletions

View File

@ -5,18 +5,10 @@
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{87A3ADEC-1BE4-42E4-92B8-B742F3D21BC4}</ProjectGuid>
@ -27,23 +19,14 @@
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<UseOfAtl>Dynamic</UseOfAtl>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfAtl>Dynamic</UseOfAtl>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@ -54,41 +37,32 @@
<Import Project="..\include\Debug.props" />
<Import Project="ZRColaCompile.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\include\x64.props" />
<Import Project="..\include\Debug.props" />
<Import Project="ZRColaCompile.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\include\Win32.props" />
<Import Project="..\include\Release.props" />
<Import Project="ZRColaCompile.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\include\x64.props" />
<Import Project="..\include\Release.props" />
<Import Project="ZRColaCompile.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemGroup>
<ClCompile Include="dbsource.cpp" />
<ClCompile Include="main.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="dbsource.h" />
<ClInclude Include="stdafx.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\lib\libZRCola\build\libZRCola.vcxproj">
<Project>{3c61929e-7289-4101-8d0a-da22d6e1aea8}</Project>
</ProjectReference>
<ProjectReference Include="..\lib\wxExtend\build\wxExtend.vcxproj">
<Project>{a3a36689-ac35-4026-93da-a3ba0c0e767c}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ZRColaCompile.rc" />

View File

@ -25,14 +25,20 @@
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="dbsource.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="stdafx.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="dbsource.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ZRCola.rc">
<ResourceCompile Include="ZRColaCompile.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#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();
}
}

57
ZRColaCompile/dbsource.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <wx/string.h>
#include <atlbase.h>
#include <adoint.h>
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<ADOConnection> m_db; ///< the database
};
};

View File

@ -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;
}

View File

@ -20,11 +20,17 @@
#pragma once
#include "../include/zrcola.h"
#include "dbsource.h"
#include <wx/app.h>
#include <wx/cmdline.h>
#include <wx/intl.h>
#include <wxex/common.h>
#include <wxex/comutils.h>
#include <initguid.h> // GUID helper to prevent LNK2001 errors (unresolved external symbol IID_IADO...)
#include <adoint.h>
#include <adoid.h>
#include <tchar.h>

View File

@ -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

@ -1 +1 @@
Subproject commit 6914baf5b2f0c9eaef036a0aaa347460652b96ea
Subproject commit 217d30fde9a39ede4a4cd8bccc547029ccf6b614