mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-20 14:24:35 +01:00
committed Data
This commit is contained in:
parent
cf80f255be
commit
01bcb63000
30
Data/Data_VS71.sln
Normal file
30
Data/Data_VS71.sln
Normal file
@ -0,0 +1,30 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Data", "Data_VS71.vcproj", "{240E83C3-368D-11DB-9FBC-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS71.vcproj", "{24134877-368D-11DB-9FBC-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5} = {240E83C3-368D-11DB-9FBC-00123FC423B5}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
debug_shared = debug_shared
|
||||
release_shared = release_shared
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5}.debug_shared.ActiveCfg = debug_shared|Win32
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5}.debug_shared.Build.0 = debug_shared|Win32
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5}.release_shared.ActiveCfg = release_shared|Win32
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5}.release_shared.Build.0 = release_shared|Win32
|
||||
{24134877-368D-11DB-9FBC-00123FC423B5}.debug_shared.ActiveCfg = debug_shared|Win32
|
||||
{24134877-368D-11DB-9FBC-00123FC423B5}.debug_shared.Build.0 = debug_shared|Win32
|
||||
{24134877-368D-11DB-9FBC-00123FC423B5}.release_shared.ActiveCfg = release_shared|Win32
|
||||
{24134877-368D-11DB-9FBC-00123FC423B5}.release_shared.Build.0 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
337
Data/Data_VS71.vcproj
Normal file
337
Data/Data_VS71.vcproj
Normal file
@ -0,0 +1,337 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="Data"
|
||||
ProjectGUID="{240e83c3-368d-11db-9fbc-00123fc423b5}"
|
||||
RootNamespace="Data"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\Foundation\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;Data_EXPORTS"
|
||||
StringPooling="TRUE"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib"
|
||||
OutputFile="..\bin\PocoDatad.dll"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="..\bin\PocoDatad.pdb"
|
||||
SubSystem="1"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\lib\PocoDatad.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="3"
|
||||
AdditionalIncludeDirectories=".\include;..\Foundation\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;Data_EXPORTS"
|
||||
GeneratePreprocessedFile="0"
|
||||
KeepComments="FALSE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="0"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib"
|
||||
OutputFile="..\bin\PocoData.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\lib\PocoData.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="DataCore"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractBinder.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractBinding.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractExtraction.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractExtractor.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractPreparation.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractPrepare.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractSessionImpl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Binder.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Binding.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\BLOB.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BLOBStream.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Column.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Common.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Data.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\DataException.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Extraction.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Limit.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\MetaColumn.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Prepare.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Range.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\RecordSet.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Session.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SessionFactory.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SessionImpl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SessionInstantiator.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Statement.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\StatementCreator.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\StatementImpl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\TypeHandler.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\AbstractBinder.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractBinding.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractExtraction.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractExtractor.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractPreparation.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractPrepare.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BLOB.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\BLOBStream.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DataException.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Limit.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\MetaColumn.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Range.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RecordSet.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Session.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionFactory.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionImpl.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionInstantiator.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Statement.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\StatementCreator.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\StatementImpl.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="SessionPooling"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\PooledSessionHolder.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\PooledSessionImpl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SessionPool.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\PooledSessionHolder.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\PooledSessionImpl.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionPool.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
28
Data/Data_VS80.sln
Normal file
28
Data/Data_VS80.sln
Normal file
@ -0,0 +1,28 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Data", "Data_VS80.vcproj", "{240E83C3-368D-11DB-9FBC-00123FC423B5}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS80.vcproj", "{24134877-368D-11DB-9FBC-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5} = {240E83C3-368D-11DB-9FBC-00123FC423B5}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
debug_shared|Win32 = debug_shared|Win32
|
||||
release_shared|Win32 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{240E83C3-368D-11DB-9FBC-00123FC423B5}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
{24134877-368D-11DB-9FBC-00123FC423B5}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
|
||||
{24134877-368D-11DB-9FBC-00123FC423B5}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{24134877-368D-11DB-9FBC-00123FC423B5}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{24134877-368D-11DB-9FBC-00123FC423B5}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
449
Data/Data_VS80.vcproj
Normal file
449
Data/Data_VS80.vcproj
Normal file
@ -0,0 +1,449 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="Data"
|
||||
ProjectGUID="{240E83C3-368D-11DB-9FBC-00123FC423B5}"
|
||||
RootNamespace="Data"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;..\Foundation\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;Data_EXPORTS"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib"
|
||||
OutputFile="..\bin\PocoDatad.dll"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="..\bin\PocoDatad.pdb"
|
||||
SubSystem="1"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\lib\PocoDatad.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories=".\include;..\Foundation\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;Data_EXPORTS"
|
||||
GeneratePreprocessedFile="0"
|
||||
KeepComments="false"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib"
|
||||
OutputFile="..\bin\PocoData.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\lib\PocoData.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="DataCore"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractBinder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractBinding.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractExtraction.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractExtractor.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractPreparation.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractPrepare.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\AbstractSessionImpl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Binding.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\BLOB.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\BLOBStream.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Column.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Common.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Data.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\DataException.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Extraction.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Limit.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\MetaColumn.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Prepare.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Range.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\RecordSet.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Session.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SessionFactory.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SessionImpl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SessionInstantiator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Statement.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\StatementCreator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\StatementImpl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\TypeHandler.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\AbstractBinder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractBinding.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractExtraction.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractExtractor.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractPreparation.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\AbstractPrepare.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BLOB.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BLOBStream.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DataException.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Limit.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\MetaColumn.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Range.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\RecordSet.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Session.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionFactory.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionInstantiator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Statement.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\StatementCreator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\StatementImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="SessionPooling"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\PooledSessionHolder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\PooledSessionImpl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SessionPool.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\PooledSessionHolder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\PooledSessionImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionPool.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
22
Data/Makefile
Normal file
22
Data/Makefile
Normal file
@ -0,0 +1,22 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/Main/Data/Makefile#10 $
|
||||
#
|
||||
# Makefile for Poco Data
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = AbstractBinder AbstractBinding AbstractExtraction \
|
||||
AbstractExtractor AbstractPreparation AbstractPrepare \
|
||||
BLOB BLOBStream DataException Limit MetaColumn \
|
||||
PooledSessionHolder PooledSessionImpl \
|
||||
Range RecordSet Session SessionFactory SessionImpl \
|
||||
SessionInstantiator SessionPool Statement StatementCreator StatementImpl
|
||||
|
||||
target = PocoData
|
||||
target_version = $(LIBVERSION)
|
||||
target_libs = PocoFoundation
|
||||
|
||||
include $(POCO_BASE)/build/rules/lib
|
25
Data/ODBC/Makefile
Normal file
25
Data/ODBC/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/Main/DataConnectors/ODBC/Makefile#2 $
|
||||
#
|
||||
# Makefile for Poco ODBC
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
ifeq ($(OSNAME),Darwin)
|
||||
SYSLIBS += -liodbc -liodbcinst
|
||||
else
|
||||
SYSLIBS += -lodbc -lodbcinst
|
||||
endif
|
||||
|
||||
objects = Binder ConnectionHandle DataTypes EnvironmentHandle \
|
||||
Extractor ODBCColumn ODBCException ODBCStatementImpl Parameter Preparation \
|
||||
SessionImpl SessionInstantiator Utility
|
||||
|
||||
target = PocoODBC
|
||||
target_version = $(LIBVERSION)
|
||||
target_libs = PocoData PocoFoundation
|
||||
|
||||
include $(POCO_BASE)/build/rules/lib
|
30
Data/ODBC/ODBC_VS71.sln
Normal file
30
Data/ODBC/ODBC_VS71.sln
Normal file
@ -0,0 +1,30 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS71.vcproj", "{1B30A91B-375F-11DB-837B-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5} = {1B29820D-375F-11DB-837B-00123FC423B5}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ODBC", "ODBC_VS71.vcproj", "{1B29820D-375F-11DB-837B-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
debug_shared = debug_shared
|
||||
release_shared = release_shared
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.debug_shared.ActiveCfg = debug_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.debug_shared.Build.0 = debug_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.release_shared.ActiveCfg = release_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.release_shared.Build.0 = release_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.debug_shared.ActiveCfg = debug_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.debug_shared.Build.0 = debug_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.release_shared.ActiveCfg = release_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.release_shared.Build.0 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
250
Data/ODBC/ODBC_VS71.vcproj
Normal file
250
Data/ODBC/ODBC_VS71.vcproj
Normal file
@ -0,0 +1,250 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="ODBC"
|
||||
ProjectGUID="{1B29820D-375F-11DB-837B-00123FC423B5}"
|
||||
RootNamespace="SQLite"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;.\src;..\..\Foundation\include;..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;ODBC_EXPORTS;NO_TCL;THREADSAFE"
|
||||
StringPooling="TRUE"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoDatad.lib"
|
||||
OutputFile="..\..\bin\PocoODBCd.dll"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="..\..\bin\PocoODBCd.pdb"
|
||||
SubSystem="1"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\..\lib\PocoODBCd.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="3"
|
||||
AdditionalIncludeDirectories=".\include;.\src;..\..\Foundation\include;..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;ODBC_EXPORTS;NO_TCL;THREADSAFE"
|
||||
GeneratePreprocessedFile="0"
|
||||
KeepComments="FALSE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="0"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoData.lib"
|
||||
OutputFile="..\..\bin\PocoODBC.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\..\lib\PocoODBC.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="ODBC"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Binder.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\ConnectionHandle.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\DataTypes.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Diagnostics.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\EnvironmentHandle.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Error.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Extractor.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Handle.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\ODBC.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\ODBCColumn.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\ODBCException.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\ODBCStatementImpl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Parameter.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Preparation.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\SessionImpl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\SessionInstantiator.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\Odbc\Utility.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\Binder.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ConnectionHandle.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DataTypes.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\EnvironmentHandle.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Extractor.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCColumn.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCException.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCStatementImpl.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Parameter.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Preparation.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionImpl.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionInstantiator.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Utility.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
28
Data/ODBC/ODBC_VS80.sln
Normal file
28
Data/ODBC/ODBC_VS80.sln
Normal file
@ -0,0 +1,28 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS80.vcproj", "{1B30A91B-375F-11DB-837B-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5} = {1B29820D-375F-11DB-837B-00123FC423B5}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ODBC", "ODBC_VS80.vcproj", "{1B29820D-375F-11DB-837B-00123FC423B5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
debug_shared|Win32 = debug_shared|Win32
|
||||
release_shared|Win32 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
341
Data/ODBC/ODBC_VS80.vcproj
Normal file
341
Data/ODBC/ODBC_VS80.vcproj
Normal file
@ -0,0 +1,341 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="ODBC"
|
||||
ProjectGUID="{1B29820D-375F-11DB-837B-00123FC423B5}"
|
||||
RootNamespace="SQLite"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;.\src;..\..\Foundation\include;..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;ODBC_EXPORTS;NO_TCL;THREADSAFE"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoDatad.lib"
|
||||
OutputFile="..\..\bin\PocoODBCd.dll"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="..\..\bin\PocoODBCd.pdb"
|
||||
SubSystem="1"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\..\lib\PocoODBCd.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories=".\include;.\src;..\..\Foundation\include;..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;ODBC_EXPORTS;NO_TCL;THREADSAFE"
|
||||
GeneratePreprocessedFile="0"
|
||||
KeepComments="false"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="0"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoData.lib"
|
||||
OutputFile="..\..\bin\PocoODBC.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\..\lib\PocoODBC.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="ODBC"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Binder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\ConnectionHandle.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\DataTypes.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Diagnostics.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\EnvironmentHandle.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Error.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Extractor.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Handle.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\ODBC.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\ODBCColumn.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\ODBCException.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\ODBCStatementImpl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Parameter.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Preparation.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\SessionImpl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\SessionInstantiator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\ODBC\Utility.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Binder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ConnectionHandle.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\DataTypes.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\EnvironmentHandle.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Extractor.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCColumn.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCException.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCStatementImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Parameter.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Preparation.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionInstantiator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Utility.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
280
Data/ODBC/include/Poco/Data/ODBC/Binder.h
Normal file
280
Data/ODBC/include/Poco/Data/ODBC/Binder.h
Normal file
@ -0,0 +1,280 @@
|
||||
//
|
||||
// Binder.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Binder.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Binder
|
||||
//
|
||||
// Definition of the Binder class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_ODBC_Binder_INCLUDED
|
||||
#define DataConnectors_ODBC_Binder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/AbstractBinder.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/ODBC/Handle.h"
|
||||
#include "Poco/Data/ODBC/Parameter.h"
|
||||
#include "Poco/Data/ODBC/ODBCColumn.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Exception.h"
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqlext.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API Binder: public Poco::Data::AbstractBinder
|
||||
/// Binds placeholders in the sql query to the provided values. Performs data types mapping.
|
||||
{
|
||||
public:
|
||||
enum ParameterBinding
|
||||
{
|
||||
PB_IMMEDIATE,
|
||||
PB_AT_EXEC
|
||||
};
|
||||
|
||||
Binder(const StatementHandle& rStmt,
|
||||
ParameterBinding dataBinding = PB_IMMEDIATE);
|
||||
/// Creates the Binder.
|
||||
|
||||
~Binder();
|
||||
/// Destroys the Binder.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int8& val);
|
||||
/// Binds an Int8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt8& val);
|
||||
/// Binds an UInt8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int16& val);
|
||||
/// Binds an Int16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt16& val);
|
||||
/// Binds an UInt16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int32& val);
|
||||
/// Binds an Int32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt32& val);
|
||||
/// Binds an UInt32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int64& val);
|
||||
/// Binds an Int64.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt64& val);
|
||||
/// Binds an UInt64.
|
||||
|
||||
void bind(std::size_t pos, const bool& val);
|
||||
/// Binds a boolean.
|
||||
|
||||
void bind(std::size_t pos, const float& val);
|
||||
/// Binds a float.
|
||||
|
||||
void bind(std::size_t pos, const double& val);
|
||||
/// Binds a double.
|
||||
|
||||
void bind(std::size_t pos, const char& val);
|
||||
/// Binds a single character.
|
||||
|
||||
void bind(std::size_t pos, const std::string& val);
|
||||
/// Binds a string.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Data::BLOB& val);
|
||||
/// Binds a BLOB.
|
||||
|
||||
void setDataBinding(ParameterBinding binding);
|
||||
/// Set data binding type.
|
||||
|
||||
ParameterBinding getDataBinding() const;
|
||||
/// Return data binding type.
|
||||
|
||||
std::size_t dataSize(SQLPOINTER pAddr) const;
|
||||
/// Returns bound data size for parameter at specified position.
|
||||
|
||||
private:
|
||||
typedef std::map<SQLPOINTER, SQLLEN> SizeMap;
|
||||
|
||||
void bind(std::size_t pos, const char* const &pVal);
|
||||
/// Binds a const char ptr.
|
||||
/// This is a private no-op in this implementation
|
||||
/// due to security risk.
|
||||
|
||||
template <typename T>
|
||||
void bindImpl(std::size_t pos, T& val, SQLSMALLINT cDataType)
|
||||
{
|
||||
_lengthIndicator.push_back(0);
|
||||
_dataSize.insert(SizeMap::value_type((SQLPOINTER) &val, sizeof(T)));
|
||||
|
||||
int sqlDataType = Utility::sqlDataType(cDataType);
|
||||
|
||||
SQLUINTEGER columnSize = 0;
|
||||
SQLSMALLINT decimalDigits = 0;
|
||||
|
||||
// somewhat funky flow control, but not all
|
||||
// ODBC drivers will cooperate here
|
||||
try
|
||||
{
|
||||
Parameter p(_rStmt, pos);
|
||||
columnSize = (SQLUINTEGER) p.columnSize();
|
||||
decimalDigits = (SQLSMALLINT) p.decimalDigits();
|
||||
}
|
||||
catch (StatementException&)
|
||||
{
|
||||
try
|
||||
{
|
||||
ODBCColumn c(_rStmt, pos);
|
||||
columnSize = (SQLUINTEGER) c.length();
|
||||
decimalDigits = (SQLSMALLINT) c.precision();
|
||||
}
|
||||
catch (StatementException&) { }
|
||||
}
|
||||
|
||||
if (Utility::isError(SQLBindParameter(_rStmt,
|
||||
(SQLUSMALLINT) pos,
|
||||
SQL_PARAM_INPUT,
|
||||
cDataType,
|
||||
sqlDataType,
|
||||
columnSize,
|
||||
decimalDigits,
|
||||
(SQLPOINTER) &val,
|
||||
0,
|
||||
_lengthIndicator.back())))
|
||||
{
|
||||
throw StatementException(_rStmt, "SQLBindParameter()");
|
||||
}
|
||||
}
|
||||
|
||||
const StatementHandle& _rStmt;
|
||||
std::vector<SQLLEN*> _lengthIndicator;
|
||||
SizeMap _dataSize;
|
||||
ParameterBinding _paramBinding;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int8& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_STINYINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt8& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_UTINYINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int16& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_SSHORT);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt16& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_USHORT);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt32& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_ULONG);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int32& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_SLONG);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt64& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_UBIGINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int64& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_SBIGINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const float& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_FLOAT);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const double& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_DOUBLE);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const bool& val)
|
||||
{
|
||||
bindImpl(pos, val, Utility::boolDataType);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const char& val)
|
||||
{
|
||||
bindImpl(pos, val, SQL_C_STINYINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::setDataBinding(Binder::ParameterBinding binding)
|
||||
{
|
||||
_paramBinding = binding;
|
||||
}
|
||||
|
||||
|
||||
inline Binder::ParameterBinding Binder::getDataBinding() const
|
||||
{
|
||||
return _paramBinding;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif // DataConnectors_ODBC_Binder_INCLUDED
|
118
Data/ODBC/include/Poco/Data/ODBC/ConnectionHandle.h
Normal file
118
Data/ODBC/include/Poco/Data/ODBC/ConnectionHandle.h
Normal file
@ -0,0 +1,118 @@
|
||||
//
|
||||
// ConnectionHandle.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/ConnectionHandle.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ConnectionHandle
|
||||
//
|
||||
// Definition of ConnectionHandle.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_ConnectionHandle_INCLUDED
|
||||
#define ODBC_ConnectionHandle_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/EnvironmentHandle.h"
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqltypes.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API ConnectionHandle
|
||||
/// ODBC connection handle class
|
||||
{
|
||||
public:
|
||||
ConnectionHandle(EnvironmentHandle* pEnvironment = 0);
|
||||
/// Creates the ConnectionHandle.
|
||||
|
||||
~ConnectionHandle();
|
||||
/// Creates the ConnectionHandle.
|
||||
|
||||
operator const SQLHDBC& () const;
|
||||
/// Const conversion operator into reference to native type.
|
||||
|
||||
const SQLHDBC& handle() const;
|
||||
/// Returns const reference to handle;
|
||||
|
||||
private:
|
||||
operator SQLHDBC& ();
|
||||
/// Conversion operator into reference to native type.
|
||||
|
||||
SQLHDBC& handle();
|
||||
/// Returns reference to handle;
|
||||
|
||||
ConnectionHandle(const ConnectionHandle&);
|
||||
const ConnectionHandle& operator=(const ConnectionHandle&);
|
||||
|
||||
const EnvironmentHandle* _pEnvironment;
|
||||
SQLHDBC _hdbc;
|
||||
bool _ownsEnvironment;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline ConnectionHandle::operator const SQLHDBC& () const
|
||||
{
|
||||
return handle();
|
||||
}
|
||||
|
||||
|
||||
inline const SQLHDBC& ConnectionHandle::handle() const
|
||||
{
|
||||
return _hdbc;
|
||||
}
|
||||
|
||||
|
||||
inline ConnectionHandle::operator SQLHDBC& ()
|
||||
{
|
||||
return handle();
|
||||
}
|
||||
|
||||
|
||||
inline SQLHDBC& ConnectionHandle::handle()
|
||||
{
|
||||
return _hdbc;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
84
Data/ODBC/include/Poco/Data/ODBC/DataTypes.h
Normal file
84
Data/ODBC/include/Poco/Data/ODBC/DataTypes.h
Normal file
@ -0,0 +1,84 @@
|
||||
//
|
||||
// DataTypes.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/DataTypes.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: DataTypes
|
||||
//
|
||||
// Definition of DataTypes.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_DataTypes_INCLUDED
|
||||
#define ODBC_DataTypes_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include <map>
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqlext.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API DataTypes
|
||||
/// C <==> SQL datatypes mapping utility class.
|
||||
{
|
||||
public:
|
||||
typedef std::map<int, int> DataTypeMap;
|
||||
typedef DataTypeMap::value_type ValueType;
|
||||
|
||||
DataTypes();
|
||||
/// Creates the DataTypes.
|
||||
|
||||
~DataTypes();
|
||||
/// Destroys the DataTypes.
|
||||
|
||||
int cDataType(int sqlDataType) const;
|
||||
/// Returns C data type corresponding to supplied SQL data type.
|
||||
|
||||
int sqlDataType(int cDataType) const;
|
||||
/// Returns SQL data type corresponding to supplied C data type.
|
||||
|
||||
private:
|
||||
DataTypeMap _cDataTypes;
|
||||
DataTypeMap _sqlDataTypes;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
249
Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h
Normal file
249
Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h
Normal file
@ -0,0 +1,249 @@
|
||||
//
|
||||
// Diagnostics.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Diagnostics.h#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Diagnostics
|
||||
//
|
||||
// Definition of Diagnostics.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_Diagnostics_INCLUDED
|
||||
#define ODBC_Diagnostics_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include <vector>
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqlext.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
template <typename H, SQLSMALLINT handleType>
|
||||
class Diagnostics
|
||||
/// Utility class providing functionality for retrieving ODBC diagnostic
|
||||
/// records. Diagnostics object must be created with corresponding handle
|
||||
/// as constructor argument. During construction, diagnostic records with corresponding
|
||||
/// fields are populated and the object is ready for querying on various diagnostic fields.
|
||||
{
|
||||
public:
|
||||
|
||||
static const unsigned int SQL_STATE_SIZE = SQL_SQLSTATE_SIZE + 1;
|
||||
static const unsigned int SQL_MESSAGE_LENGTH = SQL_MAX_MESSAGE_LENGTH + 1;
|
||||
static const unsigned int SQL_NAME_LENGTH = 128;
|
||||
static const std::string DATA_TRUNCATED;
|
||||
|
||||
struct DiagnosticFields
|
||||
{
|
||||
/// SQLGetDiagRec fields
|
||||
POCO_SQLCHAR _sqlState[SQL_STATE_SIZE];
|
||||
POCO_SQLCHAR _message[SQL_MESSAGE_LENGTH];
|
||||
SQLINTEGER _nativeError;
|
||||
};
|
||||
|
||||
typedef std::vector<DiagnosticFields> FieldVec;
|
||||
typedef typename FieldVec::const_iterator Iterator;
|
||||
|
||||
explicit Diagnostics(H& rHandle): _rHandle(rHandle)
|
||||
/// Creates and initializes the Diagnostics.
|
||||
{
|
||||
memset(_connectionName, 0, sizeof(_connectionName));
|
||||
memset(_serverName, 0, sizeof(_serverName));
|
||||
diagnostics();
|
||||
}
|
||||
|
||||
~Diagnostics()
|
||||
/// Destroys the Diagnostics.
|
||||
{
|
||||
}
|
||||
|
||||
std::string sqlState(int index) const
|
||||
/// Returns SQL state.
|
||||
{
|
||||
poco_assert (index < count());
|
||||
return std::string((char*) _fields[index]._sqlState);
|
||||
}
|
||||
|
||||
std::string message(int index) const
|
||||
/// Returns error message.
|
||||
{
|
||||
poco_assert (index < count());
|
||||
return std::string((char*) _fields[index]._message);
|
||||
}
|
||||
|
||||
long nativeError(int index) const
|
||||
/// Returns native error code.
|
||||
{
|
||||
poco_assert (index < count());
|
||||
return _fields[index]._nativeError;
|
||||
}
|
||||
|
||||
std::string connectionName() const
|
||||
/// Returns the connection name.
|
||||
/// If there is no active connection, connection name defaults to NONE.
|
||||
/// If connection name is not applicable for query context (such as when querying environment handle),
|
||||
/// connection name defaults to NOT_APPLICABLE.
|
||||
{
|
||||
return std::string((char*) _connectionName);
|
||||
}
|
||||
|
||||
std::string serverName() const
|
||||
/// Returns the server name.
|
||||
/// If the connection has not been established, server name defaults to NONE.
|
||||
/// If server name is not applicable for query context (such as when querying environment handle),
|
||||
/// connection name defaults to NOT_APPLICABLE.
|
||||
{
|
||||
return std::string((char*) _serverName);
|
||||
}
|
||||
|
||||
int count() const
|
||||
/// Returns the number of contained diagnostic records.
|
||||
{
|
||||
return (int) _fields.size();
|
||||
}
|
||||
|
||||
void reset()
|
||||
/// Resets the diagnostic fields container.
|
||||
{
|
||||
_fields.clear();
|
||||
}
|
||||
|
||||
const FieldVec& fields() const
|
||||
{
|
||||
return _fields;
|
||||
}
|
||||
|
||||
const Iterator begin() const
|
||||
{
|
||||
return _fields.begin();
|
||||
}
|
||||
|
||||
const Iterator end() const
|
||||
{
|
||||
return _fields.end();
|
||||
}
|
||||
|
||||
const Diagnostics& diagnostics()
|
||||
{
|
||||
DiagnosticFields df;
|
||||
SQLSMALLINT count = 1;
|
||||
SQLSMALLINT messageLength = 0;
|
||||
static const std::string& none = "None";
|
||||
static const std::string& na = "Not applicable";
|
||||
|
||||
reset();
|
||||
|
||||
while (!Utility::isError(SQLGetDiagRec(handleType,
|
||||
_rHandle,
|
||||
count,
|
||||
df._sqlState,
|
||||
&df._nativeError,
|
||||
df._message,
|
||||
SQL_MESSAGE_LENGTH,
|
||||
&messageLength)))
|
||||
{
|
||||
if (1 == count)
|
||||
{
|
||||
poco_assert (sizeof(_connectionName) > none.length());
|
||||
poco_assert (sizeof(_connectionName) > na.length());
|
||||
poco_assert (sizeof(_serverName) > none.length());
|
||||
poco_assert (sizeof(_serverName) > na.length());
|
||||
|
||||
// success of the following two calls is optional
|
||||
// (they fail if connection has not been established yet
|
||||
// or return empty string if not applicable for the context)
|
||||
if (Utility::isError(SQLGetDiagField(handleType,
|
||||
_rHandle,
|
||||
count,
|
||||
SQL_DIAG_CONNECTION_NAME,
|
||||
_connectionName,
|
||||
SQL_NAME_LENGTH,
|
||||
&messageLength)))
|
||||
memcpy(_connectionName, none.c_str(), none.length());
|
||||
else if (0 == _connectionName[0])
|
||||
memcpy(_connectionName, na.c_str(), na.length());
|
||||
|
||||
if (Utility::isError(SQLGetDiagField(handleType,
|
||||
_rHandle,
|
||||
count,
|
||||
SQL_DIAG_SERVER_NAME,
|
||||
_serverName,
|
||||
SQL_NAME_LENGTH,
|
||||
&messageLength)))
|
||||
memcpy(_serverName, none.c_str(), none.length());
|
||||
else if (0 == _serverName[0])
|
||||
memcpy(_serverName, na.c_str(), na.length());
|
||||
}
|
||||
|
||||
_fields.push_back(df);
|
||||
|
||||
memset(df._sqlState, 0, SQL_STATE_SIZE);
|
||||
memset(df._message, 0, SQL_MESSAGE_LENGTH);
|
||||
df._nativeError = 0;
|
||||
|
||||
++count;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Diagnostics();
|
||||
|
||||
/// SQLGetDiagField fields
|
||||
POCO_SQLCHAR _connectionName[SQL_NAME_LENGTH];
|
||||
POCO_SQLCHAR _serverName[SQL_NAME_LENGTH];
|
||||
|
||||
/// Diagnostics container
|
||||
FieldVec _fields;
|
||||
|
||||
/// Context handle
|
||||
H& _rHandle;
|
||||
};
|
||||
|
||||
|
||||
typedef Diagnostics<SQLHENV, SQL_HANDLE_ENV> EnvironmentDiagnostics;
|
||||
typedef Diagnostics<SQLHDBC, SQL_HANDLE_DBC> ConnectionDiagnostics;
|
||||
typedef Diagnostics<SQLHSTMT, SQL_HANDLE_STMT> StatementDiagnostics;
|
||||
typedef Diagnostics<SQLHDESC, SQL_HANDLE_DESC> DescriptorDiagnostics;
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
116
Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h
Normal file
116
Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h
Normal file
@ -0,0 +1,116 @@
|
||||
//
|
||||
// EnvironmentHandle.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/EnvironmentHandle.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: EnvironmentHandle
|
||||
//
|
||||
// Definition of EnvironmentHandle.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_EnvironmentHandle_INCLUDED
|
||||
#define ODBC_EnvironmentHandle_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqltypes.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API EnvironmentHandle
|
||||
/// ODBC environment handle class
|
||||
{
|
||||
public:
|
||||
EnvironmentHandle();
|
||||
/// Creates the EnvironmentHandle.
|
||||
|
||||
~EnvironmentHandle();
|
||||
/// Destroys the EnvironmentHandle.
|
||||
|
||||
operator const SQLHENV& () const;
|
||||
/// Const conversion operator into reference to native type.
|
||||
|
||||
const SQLHENV& handle() const;
|
||||
/// Returns const reference to handle.
|
||||
|
||||
private:
|
||||
operator SQLHENV& ();
|
||||
/// Conversion operator into reference to native type.
|
||||
|
||||
SQLHENV& handle();
|
||||
/// Returns reference to handle.
|
||||
|
||||
EnvironmentHandle(const EnvironmentHandle&);
|
||||
const EnvironmentHandle& operator=(const EnvironmentHandle&);
|
||||
|
||||
SQLHENV _henv;
|
||||
bool _isOwner;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline EnvironmentHandle::operator const SQLHENV& () const
|
||||
{
|
||||
return handle();
|
||||
}
|
||||
|
||||
|
||||
inline const SQLHENV& EnvironmentHandle::handle() const
|
||||
{
|
||||
return _henv;
|
||||
}
|
||||
|
||||
|
||||
inline EnvironmentHandle::operator SQLHENV& ()
|
||||
{
|
||||
return handle();
|
||||
}
|
||||
|
||||
|
||||
inline SQLHENV& EnvironmentHandle::handle()
|
||||
{
|
||||
return _henv;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
146
Data/ODBC/include/Poco/Data/ODBC/Error.h
Normal file
146
Data/ODBC/include/Poco/Data/ODBC/Error.h
Normal file
@ -0,0 +1,146 @@
|
||||
//
|
||||
// Error.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Error.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Error
|
||||
//
|
||||
// Definition of Error.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_Error_INCLUDED
|
||||
#define ODBC_Error_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Format.h"
|
||||
#include <vector>
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqlext.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
template <typename H, SQLSMALLINT handleType>
|
||||
class Error
|
||||
/// Class encapsulating ODBC diagnostic record collection. Collection is generated
|
||||
/// during construction. Class provides access and string generation for the collection
|
||||
/// as well as individual diagnostic records.
|
||||
{
|
||||
public:
|
||||
explicit Error(H handle) : _diagnostics(handle)
|
||||
/// Creates the Error.
|
||||
{
|
||||
}
|
||||
|
||||
~Error()
|
||||
/// Destroys the Error.
|
||||
{
|
||||
}
|
||||
|
||||
const Diagnostics<H, handleType>& diagnostics()
|
||||
/// Returns the associated diagnostics.
|
||||
{
|
||||
return _diagnostics;
|
||||
}
|
||||
|
||||
int count() const
|
||||
/// Returns the count of diagnostic records.
|
||||
{
|
||||
return (int) _diagnostics.count();
|
||||
}
|
||||
|
||||
std::string& toString(int index, std::string& str) const
|
||||
/// Generates the string for the diagnostic record.
|
||||
{
|
||||
if ((index < 0) || (index > (count() - 1)))
|
||||
return str;
|
||||
|
||||
std::string s;
|
||||
format(s,
|
||||
"===========================\n"
|
||||
"ODBC Diagnostic record #%d:\n"
|
||||
"===========================\n"
|
||||
"SQLSTATE = %s\nNative Error Code = %ld\n%s\n\n",
|
||||
index + 1,
|
||||
_diagnostics.sqlState(index),
|
||||
_diagnostics.nativeError(index),
|
||||
_diagnostics.message(index));
|
||||
|
||||
str.append(s);
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
std::string toString() const
|
||||
/// Generates the string for the diagnostic record collection.
|
||||
{
|
||||
std::string str;
|
||||
|
||||
format(str,
|
||||
"Connection:%s\nServer:%s\n",
|
||||
_diagnostics.connectionName(),
|
||||
_diagnostics.serverName());
|
||||
|
||||
std::string s;
|
||||
for (int i = 0; i < count(); ++i)
|
||||
{
|
||||
s.clear();
|
||||
str.append(toString(i, s));
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
private:
|
||||
Error();
|
||||
|
||||
Diagnostics<H, handleType> _diagnostics;
|
||||
};
|
||||
|
||||
|
||||
typedef Error<SQLHENV, SQL_HANDLE_ENV> EnvironmentError;
|
||||
typedef Error<SQLHDBC, SQL_HANDLE_DBC> ConnectionError;
|
||||
typedef Error<SQLHSTMT, SQL_HANDLE_STMT> StatementError;
|
||||
typedef Error<SQLHSTMT, SQL_HANDLE_DESC> DescriptorError;
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
201
Data/ODBC/include/Poco/Data/ODBC/Extractor.h
Normal file
201
Data/ODBC/include/Poco/Data/ODBC/Extractor.h
Normal file
@ -0,0 +1,201 @@
|
||||
//
|
||||
// Extractor.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Extractor.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Extractor
|
||||
//
|
||||
// Definition of the Extractor class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_ODBC_Extractor_INCLUDED
|
||||
#define DataConnectors_ODBC_Extractor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/AbstractExtractor.h"
|
||||
#include "Poco/Data/ODBC/Preparation.h"
|
||||
#include "Poco/Data/ODBC/ODBCColumn.h"
|
||||
#include "Poco/Data/ODBC/Error.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <map>
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqltypes.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API Extractor: public Poco::Data::AbstractExtractor
|
||||
/// Extracts and converts data values from the result row returned by ODBC.
|
||||
/// If NULL is received, the incoming val value is not changed and false is returned
|
||||
{
|
||||
public:
|
||||
Extractor(const StatementHandle& rStmt,
|
||||
Preparation& rPreparation);
|
||||
/// Creates the Extractor.
|
||||
|
||||
~Extractor();
|
||||
/// Destroys the Extractor.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int8& val);
|
||||
/// Extracts an Int8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt8& val);
|
||||
/// Extracts an UInt8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int16& val);
|
||||
/// Extracts an Int16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt16& val);
|
||||
/// Extracts an UInt16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int32& val);
|
||||
/// Extracts an Int32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt32& val);
|
||||
/// Extracts an UInt32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int64& val);
|
||||
/// Extracts an Int64.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt64& val);
|
||||
/// Extracts an UInt64.
|
||||
|
||||
bool extract(std::size_t pos, bool& val);
|
||||
/// Extracts a boolean.
|
||||
|
||||
bool extract(std::size_t pos, float& val);
|
||||
/// Extracts a float.
|
||||
|
||||
bool extract(std::size_t pos, double& val);
|
||||
/// Extracts a double.
|
||||
|
||||
bool extract(std::size_t pos, char& val);
|
||||
/// Extracts a single character.
|
||||
|
||||
bool extract(std::size_t pos, std::string& val);
|
||||
/// Extracts a string.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Data::BLOB& val);
|
||||
/// Extracts a BLOB.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Any& val);
|
||||
/// Extracts an Any.
|
||||
|
||||
void setDataExtraction(Preparation::DataExtraction ext);
|
||||
/// Set data extraction mode.
|
||||
|
||||
Preparation::DataExtraction getDataExtraction() const;
|
||||
/// Returns data extraction mode.
|
||||
|
||||
private:
|
||||
static const int CHUNK_SIZE = 1024;
|
||||
/// Amount of data retrieved in one SQLGetData() request when doing manual extract.
|
||||
|
||||
static const std::string FLD_SIZE_EXCEEDED_FMT;
|
||||
/// String format for the exception message when the field size is exceeded.
|
||||
|
||||
void checkDataSize(std::size_t size);
|
||||
/// This check is only performed for bound data
|
||||
/// retrieval from variable length columns.
|
||||
/// The reason for this check is to ensure we can
|
||||
/// accept the value ODBC driver is supplying
|
||||
/// (i.e. the bound buffer is large enough to receive
|
||||
/// the returned value)
|
||||
|
||||
template<typename T>
|
||||
bool extractBoundImpl(std::size_t pos, T& val)
|
||||
{
|
||||
poco_assert (typeid(T) == _rPreparation[pos].type());
|
||||
val = *AnyCast<T>(&_rPreparation[pos]);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool extractManualImpl(std::size_t pos, T& val, SQLSMALLINT cType)
|
||||
{
|
||||
SQLRETURN rc = 0;
|
||||
SQLLEN len = 0;
|
||||
T value = (T) 0;
|
||||
|
||||
rc = SQLGetData(_rStmt,
|
||||
(SQLUSMALLINT) pos,
|
||||
cType, //C data type
|
||||
&value, //returned value
|
||||
0, //buffer length (ignored)
|
||||
&len); //length indicator
|
||||
|
||||
//for fixed-length data, buffer must be large enough
|
||||
//otherwise, driver may write past the end
|
||||
poco_assert_dbg (len <= sizeof(T));
|
||||
|
||||
if (Utility::isError(rc))
|
||||
throw StatementException(_rStmt, "SQLGetData()");
|
||||
|
||||
if (SQL_NULL_DATA == len) val = (T) 0;
|
||||
else val = value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const StatementHandle& _rStmt;
|
||||
Preparation& _rPreparation;
|
||||
Preparation::DataExtraction _dataExtraction;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
|
||||
|
||||
inline void Extractor::setDataExtraction(Preparation::DataExtraction ext)
|
||||
{
|
||||
_rPreparation.setDataExtraction(_dataExtraction = ext);
|
||||
}
|
||||
|
||||
|
||||
inline Preparation::DataExtraction Extractor::getDataExtraction() const
|
||||
{
|
||||
return _dataExtraction;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif // DataConnectors_ODBC_Extractor_INCLUDED
|
126
Data/ODBC/include/Poco/Data/ODBC/Handle.h
Normal file
126
Data/ODBC/include/Poco/Data/ODBC/Handle.h
Normal file
@ -0,0 +1,126 @@
|
||||
//
|
||||
// Handle.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Handle.h#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Handle
|
||||
//
|
||||
// Definition of Handle.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_Handle_INCLUDED
|
||||
#define ODBC_Handle_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/EnvironmentHandle.h"
|
||||
#include "Poco/Data/ODBC/ConnectionHandle.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqltypes.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
template <typename H, SQLSMALLINT handleType>
|
||||
class Handle
|
||||
/// ODBC handle class template
|
||||
{
|
||||
public:
|
||||
Handle(const ConnectionHandle& rConnection):
|
||||
_rConnection(rConnection),
|
||||
_handle(0)
|
||||
/// Creates the Handle.
|
||||
{
|
||||
if (Utility::isError(SQLAllocHandle(handleType,
|
||||
_rConnection,
|
||||
&_handle)))
|
||||
{
|
||||
throw ODBCException("Could not allocate statement handle.");
|
||||
}
|
||||
}
|
||||
|
||||
~Handle()
|
||||
/// Destroys the Handle.
|
||||
{
|
||||
SQLRETURN rc = SQLFreeHandle(handleType, _handle);
|
||||
poco_assert (!Utility::isError(rc));
|
||||
}
|
||||
|
||||
operator const H& () const
|
||||
/// Const conversion operator into reference to native type.
|
||||
{
|
||||
return handle();
|
||||
}
|
||||
|
||||
const H& handle() const
|
||||
/// Returns const reference to native type.
|
||||
{
|
||||
return _handle;
|
||||
}
|
||||
|
||||
private:
|
||||
Handle(const Handle&);
|
||||
const Handle& operator=(const Handle&);
|
||||
|
||||
operator H& ()
|
||||
/// Conversion operator into reference to native type.
|
||||
{
|
||||
return handle();
|
||||
}
|
||||
|
||||
H& handle()
|
||||
/// Returns reference to native type.
|
||||
{
|
||||
return _handle;
|
||||
}
|
||||
|
||||
const ConnectionHandle& _rConnection;
|
||||
H _handle;
|
||||
|
||||
friend class ODBCStatementImpl;
|
||||
};
|
||||
|
||||
|
||||
typedef Handle<SQLHSTMT, SQL_HANDLE_STMT> StatementHandle;
|
||||
typedef Handle<SQLHDESC, SQL_HANDLE_DESC> DescriptorHandle;
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
95
Data/ODBC/include/Poco/Data/ODBC/ODBC.h
Normal file
95
Data/ODBC/include/Poco/Data/ODBC/ODBC.h
Normal file
@ -0,0 +1,95 @@
|
||||
//
|
||||
// ODBC.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/ODBC.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ODBC
|
||||
//
|
||||
// Basic definitions for the Poco ODBC library.
|
||||
// This file must be the first file included by every other ODBC
|
||||
// header file.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_ODBC_INCLUDED
|
||||
#define ODBC_ODBC_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the ODBC_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// ODBC_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(ODBC_EXPORTS)
|
||||
#define ODBC_API __declspec(dllexport)
|
||||
#else
|
||||
#define ODBC_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(ODBC_API)
|
||||
#define ODBC_API
|
||||
#endif
|
||||
|
||||
|
||||
#define POCO_SQLCHAR SQLCHAR
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Data library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(ODBC_EXPORTS)
|
||||
#if defined(POCO_DLL)
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoODBCd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoODBC.lib")
|
||||
#endif
|
||||
#else
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoODBCmtd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoODBCmt.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // ODBC_ODBC_INCLUDED
|
111
Data/ODBC/include/Poco/Data/ODBC/ODBCColumn.h
Normal file
111
Data/ODBC/include/Poco/Data/ODBC/ODBCColumn.h
Normal file
@ -0,0 +1,111 @@
|
||||
//
|
||||
// ODBCColumn.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/ODBCColumn.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ODBCColumn
|
||||
//
|
||||
// Definition of ODBCColumn.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_ODBCColumn_INCLUDED
|
||||
#define ODBC_ODBCColumn_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/Error.h"
|
||||
#include "Poco/Data/ODBC/Handle.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqlext.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API ODBCColumn: public MetaColumn
|
||||
{
|
||||
public:
|
||||
explicit ODBCColumn(const StatementHandle& rStmt, std::size_t position);
|
||||
/// Creates the ODBCColumn.
|
||||
|
||||
~ODBCColumn();
|
||||
/// Destroys the ODBCColumn.
|
||||
|
||||
std::size_t dataLength() const;
|
||||
/// A numeric value that is either the maximum or actual character length of a character
|
||||
/// string or binary data type. It is the maximum character length for a fixed-length data type,
|
||||
/// or the actual character length for a variable-length data type. Its value always excludes the
|
||||
/// null-termination byte that ends the character string.
|
||||
/// This information is returned from the SQL_DESC_LENGTH record field of the IRD.
|
||||
|
||||
private:
|
||||
ODBCColumn();
|
||||
|
||||
static const int NAME_BUFFER_LENGTH = 2048;
|
||||
|
||||
struct ColumnDescription
|
||||
{
|
||||
POCO_SQLCHAR name[NAME_BUFFER_LENGTH];
|
||||
SQLSMALLINT nameBufferLength;
|
||||
SQLSMALLINT dataType;
|
||||
SQLULEN size;
|
||||
SQLSMALLINT decimalDigits;
|
||||
SQLSMALLINT isNullable;
|
||||
};
|
||||
|
||||
void init();
|
||||
void getDescription();
|
||||
|
||||
Poco::Int32 _dataLength;
|
||||
const StatementHandle& _rStmt;
|
||||
ColumnDescription _columnDesc;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline std::size_t ODBCColumn::dataLength() const
|
||||
{
|
||||
return _dataLength;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
152
Data/ODBC/include/Poco/Data/ODBC/ODBCException.h
Normal file
152
Data/ODBC/include/Poco/Data/ODBC/ODBCException.h
Normal file
@ -0,0 +1,152 @@
|
||||
//
|
||||
// ODBCException.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/ODBCException.h#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ODBCException
|
||||
//
|
||||
// Definition of ODBCException.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_ODBCException_INCLUDED
|
||||
#define ODBC_ODBCException_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Data/ODBC/Error.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(ODBC_API, ODBCException, Poco::Data::DataException)
|
||||
POCO_DECLARE_EXCEPTION(ODBC_API, InsufficientStorageException, ODBCException)
|
||||
POCO_DECLARE_EXCEPTION(ODBC_API, UnknownDataLengthException, ODBCException)
|
||||
POCO_DECLARE_EXCEPTION(ODBC_API, DataTruncatedException, ODBCException)
|
||||
|
||||
|
||||
template <class H, SQLSMALLINT handleType>
|
||||
class HandleException: public ODBCException
|
||||
{
|
||||
public:
|
||||
HandleException(const H& handle): _error(handle)
|
||||
{
|
||||
}
|
||||
|
||||
HandleException(const H& handle, const std::string& msg):
|
||||
ODBCException(msg),
|
||||
_error(handle)
|
||||
{
|
||||
}
|
||||
|
||||
HandleException(const H& handle, const std::string& msg, const std::string& arg):
|
||||
ODBCException(msg, arg),
|
||||
_error(handle)
|
||||
{
|
||||
}
|
||||
|
||||
HandleException(const H& handle, const std::string& msg, const Poco::Exception& exc):
|
||||
ODBCException(msg, exc),
|
||||
_error(handle)
|
||||
{
|
||||
}
|
||||
|
||||
HandleException(const HandleException& exc):
|
||||
ODBCException(exc),
|
||||
_error(exc._error)
|
||||
{
|
||||
}
|
||||
|
||||
~HandleException() throw()
|
||||
{
|
||||
}
|
||||
|
||||
HandleException& operator = (const HandleException& exc)
|
||||
{
|
||||
HandleException::operator = (exc);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const char* name() const throw()
|
||||
{
|
||||
|
||||
return "ODBC handle exception";
|
||||
}
|
||||
|
||||
const char* className() const throw()
|
||||
{
|
||||
return typeid(*this).name();
|
||||
}
|
||||
|
||||
Poco::Exception* clone() const
|
||||
{
|
||||
return new HandleException(*this);
|
||||
}
|
||||
|
||||
void rethrow() const
|
||||
{
|
||||
throw *this;
|
||||
}
|
||||
|
||||
const Diagnostics<H, handleType>& diagnostics()
|
||||
{
|
||||
return _error.diagnostics();
|
||||
}
|
||||
|
||||
std::string toString() const
|
||||
{
|
||||
std::stringstream os;
|
||||
os << "ODBC Error: " << what() << std::endl
|
||||
<< "===================" << std::endl
|
||||
<< _error.toString() << std::endl ;
|
||||
return os.str();
|
||||
}
|
||||
|
||||
private:
|
||||
Error<H, handleType> _error;
|
||||
};
|
||||
|
||||
|
||||
typedef HandleException<SQLHENV, SQL_HANDLE_ENV> EnvironmentException;
|
||||
typedef HandleException<SQLHDBC, SQL_HANDLE_DBC> ConnectionException;
|
||||
typedef HandleException<SQLHSTMT, SQL_HANDLE_STMT> StatementException;
|
||||
typedef HandleException<SQLHDESC, SQL_HANDLE_DESC> DescriptorException;
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
191
Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h
Normal file
191
Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h
Normal file
@ -0,0 +1,191 @@
|
||||
//
|
||||
// ODBCStatementImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/ODBCStatementImpl.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ODBCStatementImpl
|
||||
//
|
||||
// Definition of the ODBCStatementImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_ODBC_ODBCStatementImpl_INCLUDED
|
||||
#define DataConnectors_ODBC_ODBCStatementImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/SessionImpl.h"
|
||||
#include "Poco/Data/ODBC/Binder.h"
|
||||
#include "Poco/Data/ODBC/Extractor.h"
|
||||
#include "Poco/Data/ODBC/Preparation.h"
|
||||
#include "Poco/Data/ODBC/ODBCColumn.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/Column.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "Poco/Format.h"
|
||||
#include <sstream>
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqltypes.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API ODBCStatementImpl: public Poco::Data::StatementImpl
|
||||
/// Implements statement functionality needed for ODBC
|
||||
{
|
||||
public:
|
||||
typedef std::vector<ODBCColumn*> ColumnPtrVec;
|
||||
|
||||
ODBCStatementImpl(SessionImpl& rSession);
|
||||
/// Creates the ODBCStatementImpl.
|
||||
|
||||
~ODBCStatementImpl();
|
||||
/// Destroys the ODBCStatementImpl.
|
||||
|
||||
protected:
|
||||
Poco::UInt32 columnsReturned() const;
|
||||
/// Returns number of columns returned by query.
|
||||
|
||||
const MetaColumn& metaColumn(Poco::UInt32 pos) const;
|
||||
/// Returns column meta data.
|
||||
|
||||
bool hasNext();
|
||||
/// Returns true if a call to next() will return data.
|
||||
|
||||
void next();
|
||||
/// Retrieves the next row from the resultset.
|
||||
/// Will throw, if the resultset is empty.
|
||||
|
||||
bool canBind() const;
|
||||
/// Returns true if a valid statement is set and we can bind.
|
||||
|
||||
void compileImpl();
|
||||
/// Compiles the statement, doesn't bind yet
|
||||
|
||||
void bindImpl();
|
||||
/// Binds parameters
|
||||
|
||||
AbstractExtractor& extractor();
|
||||
/// Returns the concrete extractor used by the statement.
|
||||
|
||||
AbstractBinder& binder();
|
||||
/// Returns the concrete binder used by the statement.
|
||||
|
||||
std::string nativeSQL();
|
||||
/// Returns the SQL string as modified by the driver.
|
||||
|
||||
private:
|
||||
typedef Poco::Data::AbstractBindingVec Bindings;
|
||||
typedef Poco::Data::AbstractExtractionVec Extractions;
|
||||
|
||||
static const std::string INVALID_CURSOR_STATE;
|
||||
|
||||
void clear();
|
||||
/// Closes the cursor and resets indicator variables.
|
||||
|
||||
bool hasData() const;
|
||||
/// Returns true if statement returns data.
|
||||
|
||||
bool nextRowReady() const;
|
||||
/// Returns true if there is a row fetched but not yet extracted.
|
||||
|
||||
void putData();
|
||||
/// Called whenever SQLExecute returns SQL_NEED_DATA. This is expected
|
||||
/// behavior for PB_AT_EXEC binding mode.
|
||||
|
||||
void fillColumns();
|
||||
void checkError(SQLRETURN rc, const std::string& msg="");
|
||||
|
||||
SessionImpl& _rSession;
|
||||
const StatementHandle _stmt;
|
||||
Poco::SharedPtr<Preparation> _pPreparation;
|
||||
Poco::SharedPtr<Binder> _pBinder;
|
||||
Poco::SharedPtr<Extractor> _pExtractor;
|
||||
bool _stepCalled;
|
||||
int _nextResponse;
|
||||
ColumnPtrVec _columnPtrs;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AbstractExtractor& ODBCStatementImpl::extractor()
|
||||
{
|
||||
poco_assert_dbg (_pExtractor);
|
||||
return *_pExtractor;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBinder& ODBCStatementImpl::binder()
|
||||
{
|
||||
poco_assert_dbg (_pBinder);
|
||||
return *_pBinder;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 ODBCStatementImpl::columnsReturned() const
|
||||
{
|
||||
poco_assert_dbg (_pPreparation);
|
||||
return (Poco::UInt32) _pPreparation->columns();
|
||||
}
|
||||
|
||||
|
||||
inline bool ODBCStatementImpl::hasData() const
|
||||
{
|
||||
poco_assert_dbg (_pPreparation);
|
||||
return (_pPreparation->columns() > 0);
|
||||
}
|
||||
|
||||
|
||||
inline bool ODBCStatementImpl::nextRowReady() const
|
||||
{
|
||||
return (!Utility::isError(_nextResponse));
|
||||
}
|
||||
|
||||
|
||||
inline const MetaColumn& ODBCStatementImpl::metaColumn(Poco::UInt32 pos) const
|
||||
{
|
||||
if (pos > _columnPtrs.size())
|
||||
throw InvalidAccessException(format("Invalid column number: %u", pos));
|
||||
|
||||
return *_columnPtrs[pos-1];
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif // DataConnectors_ODBC_ODBCStatementImpl_INCLUDED
|
135
Data/ODBC/include/Poco/Data/ODBC/Parameter.h
Normal file
135
Data/ODBC/include/Poco/Data/ODBC/Parameter.h
Normal file
@ -0,0 +1,135 @@
|
||||
//
|
||||
// Parameter.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Parameter.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Parameter
|
||||
//
|
||||
// Definition of Parameter.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_Parameter_INCLUDED
|
||||
#define ODBC_Parameter_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/Handle.h"
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqlext.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API Parameter
|
||||
{
|
||||
public:
|
||||
explicit Parameter(const StatementHandle& rStmt, std::size_t colNum);
|
||||
/// Creates the Parameter.
|
||||
|
||||
~Parameter();
|
||||
/// Destroys the Parameter.
|
||||
|
||||
std::size_t number() const;
|
||||
/// Returns the column number.
|
||||
|
||||
std::size_t dataType() const;
|
||||
/// Returns the SQL data type.
|
||||
|
||||
std::size_t columnSize() const;
|
||||
/// Returns the the size of the column or expression of the corresponding
|
||||
/// parameter marker as defined by the data source.
|
||||
|
||||
std::size_t decimalDigits() const;
|
||||
/// Returns the number of decimal digits of the column or expression
|
||||
/// of the corresponding parameter as defined by the data source.
|
||||
|
||||
bool isNullable() const;
|
||||
/// Returns true if column allows null values, false otherwise.
|
||||
|
||||
private:
|
||||
Parameter();
|
||||
|
||||
static const int BUFFER_LENGTH = 2048;
|
||||
|
||||
void init();
|
||||
|
||||
SQLSMALLINT _dataType;
|
||||
SQLULEN _columnSize;
|
||||
SQLSMALLINT _decimalDigits;
|
||||
SQLSMALLINT _isNullable;
|
||||
|
||||
const StatementHandle& _rStmt;
|
||||
std::size_t _number;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline std::size_t Parameter::number() const
|
||||
{
|
||||
return _number;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Parameter::dataType() const
|
||||
{
|
||||
return _dataType;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Parameter::columnSize() const
|
||||
{
|
||||
return _columnSize;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Parameter::decimalDigits() const
|
||||
{
|
||||
return _decimalDigits;
|
||||
}
|
||||
|
||||
|
||||
inline bool Parameter::isNullable() const
|
||||
{
|
||||
return SQL_NULLABLE == _isNullable;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
363
Data/ODBC/include/Poco/Data/ODBC/Preparation.h
Normal file
363
Data/ODBC/include/Poco/Data/ODBC/Preparation.h
Normal file
@ -0,0 +1,363 @@
|
||||
//
|
||||
// Preparation.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Preparation.h#3 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: DataCore
|
||||
// Module: Preparation
|
||||
//
|
||||
// Definition of the Preparation class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_ODBC_Preparation_INCLUDED
|
||||
#define DataConnectors_ODBC_Preparation_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/Handle.h"
|
||||
#include "Poco/Data/ODBC/ODBCColumn.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/AbstractPreparation.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include <vector>
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqlext.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class BLOB;
|
||||
|
||||
|
||||
class ODBC_API Preparation : public AbstractPreparation
|
||||
/// Class used for database preparation where we first have to register all data types
|
||||
/// with respective memory output locations before extracting data.
|
||||
/// Extraction works in two-phases: first prepare is called once, then extract n-times.
|
||||
/// In ODBC, SQLBindCol/SQLFetch is the preferred method of data retrieval (SQLGetData is available,
|
||||
/// however with numerous driver implementation dependent limitations). In order to fit this functionality
|
||||
/// into Poco DataConnectors framework, every ODBC SQL statement instantiates its own Preparation object.
|
||||
/// This is done once per statement execution (from StatementImpl::bindImpl()).
|
||||
///
|
||||
/// Preparation object is used to :
|
||||
///
|
||||
/// 1) Prepare SQL statement.
|
||||
/// 2) Provide and contain the memory locations where retrieved values are placed during recordset iteration.
|
||||
/// 3) Keep count of returned number of columns with their respective datatypes and sizes.
|
||||
///
|
||||
/// Notes:
|
||||
///
|
||||
/// - Value datatypes in this interface prepare() calls serve only for the purpose of type distinction.
|
||||
/// - Preparation keeps its own std::vector<Any> buffer for fetched data to be later retrieved by Extractor.
|
||||
/// - prepare() methods should not be called when extraction mode is DE_MANUAL
|
||||
///
|
||||
{
|
||||
public:
|
||||
enum DataExtraction
|
||||
{
|
||||
DE_MANUAL,
|
||||
DE_BOUND
|
||||
};
|
||||
|
||||
Preparation(const StatementHandle& rStmt,
|
||||
const std::string& statement,
|
||||
std::size_t maxFieldSize,
|
||||
DataExtraction dataExtraction = DE_BOUND);
|
||||
/// Creates the Preparation.
|
||||
|
||||
~Preparation();
|
||||
/// Destroys the Preparation.
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int8);
|
||||
/// Prepares an Int8.
|
||||
|
||||
void prepare(std::size_t pos, Poco::UInt8);
|
||||
/// Prepares an UInt8.
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int16);
|
||||
/// Prepares an Int16.
|
||||
|
||||
void prepare(std::size_t pos, Poco::UInt16);
|
||||
/// Prepares an UInt16.
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int32);
|
||||
/// Prepares an Int32.
|
||||
|
||||
void prepare(std::size_t pos, Poco::UInt32);
|
||||
/// Prepares an UInt32.
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int64);
|
||||
/// Prepares an Int64.
|
||||
|
||||
void prepare(std::size_t pos, Poco::UInt64);
|
||||
/// Prepares an UInt64.
|
||||
|
||||
void prepare(std::size_t pos, bool);
|
||||
/// Prepares a boolean.
|
||||
|
||||
void prepare(std::size_t pos, float);
|
||||
/// Prepares a float.
|
||||
|
||||
void prepare(std::size_t pos, double);
|
||||
/// Prepares a double.
|
||||
|
||||
void prepare(std::size_t pos, char);
|
||||
/// Prepares a single character.
|
||||
|
||||
void prepare(std::size_t pos, const std::string&);
|
||||
/// Prepares a string.
|
||||
|
||||
void prepare(std::size_t pos, const Poco::Data::BLOB&);
|
||||
/// Prepares a BLOB.
|
||||
|
||||
void prepare(std::size_t pos, const Poco::Any&);
|
||||
/// Prepares an Any.
|
||||
|
||||
std::size_t columns() const;
|
||||
/// Returns the number of columns.
|
||||
|
||||
Poco::Any& operator [] (std::size_t pos);
|
||||
/// Returns reference to column data.
|
||||
|
||||
void setMaxFieldSize(std::size_t size);
|
||||
/// Sets maximum supported field size.
|
||||
|
||||
std::size_t getMaxFieldSize() const;
|
||||
// Returns maximum supported field size.
|
||||
|
||||
std::size_t maxDataSize(std::size_t pos) const;
|
||||
/// Returns max supported size for column at position pos.
|
||||
/// Returned length for variable length fields is the one
|
||||
/// supported by this implementation, not the underlying DB.
|
||||
|
||||
std::size_t actualDataSize(std::size_t pos) const;
|
||||
/// Returns the returned length. This is usually
|
||||
/// equal to the column size, except for variable length fields
|
||||
/// (BLOB and variable length strings).
|
||||
|
||||
void setDataExtraction(DataExtraction ext);
|
||||
/// Set data extraction mode.
|
||||
|
||||
DataExtraction getDataExtraction() const;
|
||||
/// Returns data extraction mode.
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
void preparePOD(std::size_t pos, SQLSMALLINT valueType)
|
||||
{
|
||||
poco_assert (DE_BOUND == _dataExtraction);
|
||||
poco_assert (pos > 0 && pos <= _pValues.size());
|
||||
|
||||
std::size_t dataSize = sizeof(T);
|
||||
|
||||
_pValues[pos-1] = new Poco::Any(T());
|
||||
_pLengths[pos-1] = new SQLLEN;
|
||||
*_pLengths[pos-1] = 0;
|
||||
|
||||
T* pVal = AnyCast<T>(_pValues[pos-1]);
|
||||
|
||||
poco_assert_dbg (pVal);
|
||||
|
||||
if (Utility::isError(SQLBindCol(_rStmt,
|
||||
(SQLUSMALLINT) pos,
|
||||
valueType,
|
||||
(SQLPOINTER) pVal,
|
||||
(SQLINTEGER) dataSize,
|
||||
_pLengths[pos-1])))
|
||||
{
|
||||
throw StatementException(_rStmt, "SQLBindCol()");
|
||||
}
|
||||
}
|
||||
|
||||
void prepareRaw(std::size_t pos, SQLSMALLINT valueType, std::size_t size);
|
||||
|
||||
const StatementHandle& _rStmt;
|
||||
std::vector<Poco::Any*> _pValues;
|
||||
std::vector<SQLLEN*> _pLengths;
|
||||
std::size_t _maxFieldSize;
|
||||
DataExtraction _dataExtraction;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void Preparation::prepare(std::size_t pos, Poco::Int8)
|
||||
{
|
||||
preparePOD<Poco::Int8>(pos, SQL_C_STINYINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, Poco::UInt8)
|
||||
{
|
||||
preparePOD<Poco::UInt8>(pos, SQL_C_UTINYINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, Poco::Int16)
|
||||
{
|
||||
preparePOD<Poco::Int16>(pos, SQL_C_SSHORT);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, Poco::UInt16)
|
||||
{
|
||||
preparePOD<Poco::UInt16>(pos, SQL_C_USHORT);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, Poco::Int32)
|
||||
{
|
||||
preparePOD<Poco::Int32>(pos, SQL_C_SLONG);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, Poco::UInt32)
|
||||
{
|
||||
preparePOD<Poco::UInt32>(pos, SQL_C_ULONG);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, Poco::Int64)
|
||||
{
|
||||
preparePOD<Poco::Int64>(pos, SQL_C_SBIGINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, Poco::UInt64)
|
||||
{
|
||||
preparePOD<Poco::UInt64>(pos, SQL_C_UBIGINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, bool)
|
||||
{
|
||||
preparePOD<bool>(pos, Utility::boolDataType);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, float)
|
||||
{
|
||||
preparePOD<float>(pos, SQL_C_FLOAT);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, double)
|
||||
{
|
||||
preparePOD<double>(pos, SQL_C_DOUBLE);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, char)
|
||||
{
|
||||
preparePOD<char>(pos, SQL_C_STINYINT);
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, const std::string&)
|
||||
{
|
||||
prepareRaw(pos, SQL_C_CHAR, maxDataSize(pos));
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::prepare(std::size_t pos, const Poco::Data::BLOB&)
|
||||
{
|
||||
prepareRaw(pos, SQL_C_BINARY, maxDataSize(pos));
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Preparation::columns() const
|
||||
{
|
||||
return _pValues.size();
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Preparation::maxDataSize(std::size_t pos) const
|
||||
{
|
||||
poco_assert (pos > 0 && pos <= _pValues.size());
|
||||
|
||||
std::size_t sz = 0;
|
||||
std::size_t maxsz = getMaxFieldSize();
|
||||
|
||||
try
|
||||
{
|
||||
sz = ODBCColumn(_rStmt, pos).length();
|
||||
}
|
||||
catch (StatementException&)
|
||||
{
|
||||
}
|
||||
if (!sz || sz > maxsz) sz = maxsz;
|
||||
return sz;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Preparation::actualDataSize(std::size_t pos) const
|
||||
{
|
||||
poco_assert (pos > 0 && pos <= _pValues.size());
|
||||
poco_assert (_pLengths[pos-1]);
|
||||
|
||||
return *_pLengths[pos-1];
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::setMaxFieldSize(std::size_t size)
|
||||
{
|
||||
_maxFieldSize = size;
|
||||
}
|
||||
|
||||
|
||||
inline std::size_t Preparation::getMaxFieldSize() const
|
||||
{
|
||||
return _maxFieldSize;
|
||||
}
|
||||
|
||||
|
||||
inline void Preparation::setDataExtraction(Preparation::DataExtraction ext)
|
||||
{
|
||||
_dataExtraction = ext;
|
||||
}
|
||||
|
||||
|
||||
inline Preparation::DataExtraction Preparation::getDataExtraction() const
|
||||
{
|
||||
return _dataExtraction;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif // DataConnectors_ODBC_Preparation_INCLUDED
|
204
Data/ODBC/include/Poco/Data/ODBC/SessionImpl.h
Normal file
204
Data/ODBC/include/Poco/Data/ODBC/SessionImpl.h
Normal file
@ -0,0 +1,204 @@
|
||||
//
|
||||
// SessionImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/SessionImpl.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: SessionImpl
|
||||
//
|
||||
// Definition of the SessionImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_ODBC_SessionImpl_INCLUDED
|
||||
#define DataConnectors_ODBC_SessionImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/Binder.h"
|
||||
#include "Poco/Data/ODBC/Handle.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/AbstractSessionImpl.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqltypes.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API SessionImpl: public Poco::Data::AbstractSessionImpl<SessionImpl>
|
||||
/// Implements SessionImpl interface
|
||||
{
|
||||
public:
|
||||
SessionImpl(const std::string& fileName,
|
||||
Poco::Any maxFieldSize = std::size_t(1024),
|
||||
bool enforceCapability=false,
|
||||
bool autoBind=false,
|
||||
bool autoExtract=false);
|
||||
/// Creates the SessionImpl. Opens a connection to the database
|
||||
|
||||
~SessionImpl();
|
||||
/// Destroys the SessionImpl.
|
||||
|
||||
Poco::Data::StatementImpl* createStatementImpl();
|
||||
/// Returns an ODBC StatementImpl
|
||||
|
||||
void begin();
|
||||
/// Starts a transaction
|
||||
|
||||
void commit();
|
||||
/// Commits and ends a transaction
|
||||
|
||||
void rollback();
|
||||
/// Aborts a transaction
|
||||
|
||||
void close();
|
||||
/// Closes the connection
|
||||
|
||||
bool isConnected();
|
||||
/// Returns true if session is connected
|
||||
|
||||
void setEnforceCapability(const std::string&, bool val);
|
||||
/// Configures session to enforce driver capability check
|
||||
/// after connection.
|
||||
/// If capability check is enforced and driver is not capable,
|
||||
/// connection is terminated.
|
||||
/// Since some drivers do not cooperate, the default behavior
|
||||
/// is not checking capability.
|
||||
|
||||
bool getEnforceCapability(const std::string& name="");
|
||||
/// Returns the driver capability check configuration value.
|
||||
|
||||
bool canTransact();
|
||||
/// Returns true if connection is transaction-capable.
|
||||
|
||||
void autoCommit(const std::string&, bool val);
|
||||
/// Sets autocommit property for the session.
|
||||
|
||||
bool isAutoCommit(const std::string& name="");
|
||||
/// Returns autocommit property value.
|
||||
|
||||
void autoBind(const std::string&, bool val);
|
||||
/// Sets automatic binding for the session.
|
||||
|
||||
bool isAutoBind(const std::string& name="");
|
||||
/// Returns true if binding is automatic for this session.
|
||||
|
||||
void autoExtract(const std::string&, bool val);
|
||||
/// Sets automatic extraction for the session.
|
||||
|
||||
bool isAutoExtract(const std::string& name="");
|
||||
/// Returns true if extraction is automatic for this session.
|
||||
|
||||
void setMaxFieldSize(const std::string& rName, const Poco::Any& rValue);
|
||||
/// Sets the max field size (the default used when column size is unknown).
|
||||
|
||||
Poco::Any getMaxFieldSize(const std::string& rName="");
|
||||
/// Returns the max field size (the default used when column size is unknown).
|
||||
|
||||
int maxStatementLength();
|
||||
/// Returns maximum length of SQL statement allowed by driver.
|
||||
|
||||
const ConnectionHandle& dbc() const;
|
||||
/// Returns the connection handle.
|
||||
|
||||
private:
|
||||
static const int FUNCTIONS = SQL_API_ODBC3_ALL_FUNCTIONS_SIZE;
|
||||
|
||||
void open();
|
||||
/// Opens a connection to the Database
|
||||
|
||||
bool isCapable();
|
||||
/// Returns true if driver supports all required functions.
|
||||
/// Called upon succesful connection if _enforceCapability is true.
|
||||
/// This function code should be updated whenever a new
|
||||
/// ODBC API call is introduced anywhere in ODBC data connector.
|
||||
|
||||
void checkError(SQLRETURN rc, const std::string& msg="");
|
||||
|
||||
std::string _connect;
|
||||
const ConnectionHandle _db;
|
||||
Poco::Any _maxFieldSize;
|
||||
bool _enforceCapability;
|
||||
bool _autoBind;
|
||||
bool _autoExtract;
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline void SessionImpl::checkError(SQLRETURN rc, const std::string& msg)
|
||||
{
|
||||
if (Utility::isError(rc))
|
||||
throw ConnectionException(_db, msg);
|
||||
}
|
||||
|
||||
|
||||
inline const ConnectionHandle& SessionImpl::dbc() const
|
||||
{
|
||||
return _db;
|
||||
}
|
||||
|
||||
|
||||
inline void SessionImpl::commit()
|
||||
{
|
||||
if (!isAutoCommit())
|
||||
checkError(SQLEndTran(SQL_HANDLE_DBC, _db, SQL_COMMIT));
|
||||
}
|
||||
|
||||
|
||||
inline void SessionImpl::rollback()
|
||||
{
|
||||
if (!isAutoCommit())
|
||||
checkError(SQLEndTran(SQL_HANDLE_DBC, _db, SQL_ROLLBACK));
|
||||
}
|
||||
|
||||
|
||||
inline void SessionImpl::setMaxFieldSize(const std::string& rName, const Poco::Any& rValue)
|
||||
{
|
||||
_maxFieldSize = rValue;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::Any SessionImpl::getMaxFieldSize(const std::string& rName)
|
||||
{
|
||||
return _maxFieldSize;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif // DataConnectors_ODBC_SessionImpl_INCLUDED
|
79
Data/ODBC/include/Poco/Data/ODBC/SessionInstantiator.h
Normal file
79
Data/ODBC/include/Poco/Data/ODBC/SessionInstantiator.h
Normal file
@ -0,0 +1,79 @@
|
||||
//
|
||||
// SessionInstantiator.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/SessionInstantiator.h#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: SessionInstantiator
|
||||
//
|
||||
// Definition of the SessionInstantiator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_ODBC_SessionInstantiator_INCLUDED
|
||||
#define DataConnectors_ODBC_SessionInstantiator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/SessionInstantiator.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API SessionInstantiator: public Poco::Data::SessionInstantiator
|
||||
/// SessionInstantiator instantiates SqLite SessionImpl objects.
|
||||
{
|
||||
public:
|
||||
static const std::string KEY;
|
||||
/// Keyword for creating ODBC sessions
|
||||
|
||||
SessionInstantiator();
|
||||
/// Creates the SessionInstantiator.
|
||||
|
||||
~SessionInstantiator();
|
||||
/// Destroys the SessionInstantiator.
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> create(const std::string& initString);
|
||||
/// Creates a ODBC SessionImpl object and initializes it with the given initString.
|
||||
|
||||
static void addToFactory();
|
||||
/// Registers the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory
|
||||
|
||||
static void removeFromFactory();
|
||||
/// Unregisters the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif // DataConnectors_ODBC_SessionInstantiator_INCLUDED
|
129
Data/ODBC/include/Poco/Data/ODBC/Utility.h
Normal file
129
Data/ODBC/include/Poco/Data/ODBC/Utility.h
Normal file
@ -0,0 +1,129 @@
|
||||
//
|
||||
// Utility.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/include/Poco/Data/ODBC/Utility.h#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Utility
|
||||
//
|
||||
// Definition of Utility.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBC_Utility_INCLUDED
|
||||
#define ODBC_Utility_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/ODBC/DataTypes.h"
|
||||
#include <sstream>
|
||||
#ifdef POCO_OS_FAMILY_WINDOWS
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <sqltypes.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
class ODBC_API Utility
|
||||
/// Various utility functions
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, std::string> DSNMap;
|
||||
typedef DSNMap DriverMap;
|
||||
|
||||
static bool isError(SQLRETURN rc);
|
||||
/// Returns true if return code is error
|
||||
|
||||
static DriverMap& drivers(DriverMap& driverMap);
|
||||
/// Returns driver-attributes map of available ODBC drivers.
|
||||
|
||||
static DSNMap& dataSources(DSNMap& dsnMap);
|
||||
/// Returns DSN-description map of available ODBC data sources.
|
||||
|
||||
template<typename MapType, typename KeyArgType, typename ValueArgType>
|
||||
static typename MapType::iterator mapInsert(MapType& m, const KeyArgType& k, const ValueArgType& v)
|
||||
/// Utility map "insert or replace" function (from S. Meyers: Effective STL, Item 24)
|
||||
{
|
||||
typename MapType::iterator lb = m.lower_bound(k);
|
||||
if (lb != m.end() && !(m.key_comp()(k, lb->first)))
|
||||
{
|
||||
lb->second = v;
|
||||
return lb;
|
||||
}
|
||||
else
|
||||
{
|
||||
typedef typename MapType::value_type MVT;
|
||||
return m.insert(lb, MVT(k,v));
|
||||
}
|
||||
}
|
||||
|
||||
static int cDataType(int sqlDataType);
|
||||
/// Returns C data type corresponding to supplied SQL data type.
|
||||
|
||||
static int sqlDataType(int cDataType);
|
||||
/// Returns SQL data type corresponding to supplied C data type.
|
||||
|
||||
static const SQLSMALLINT boolDataType;
|
||||
/// ODBC size for bool data type.
|
||||
|
||||
private:
|
||||
static const DataTypes _dataTypes;
|
||||
/// C <==> SQL data type mapping
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
/// inlines
|
||||
///
|
||||
inline bool Utility::isError(SQLRETURN rc)
|
||||
{
|
||||
return (0 != (rc & (~1)));
|
||||
}
|
||||
|
||||
|
||||
inline int Utility::cDataType(int sqlDataType)
|
||||
{
|
||||
return _dataTypes.cDataType(sqlDataType);
|
||||
}
|
||||
|
||||
|
||||
inline int Utility::sqlDataType(int cDataType)
|
||||
{
|
||||
return _dataTypes.sqlDataType(cDataType);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
||||
|
||||
|
||||
#endif
|
138
Data/ODBC/src/Binder.cpp
Normal file
138
Data/ODBC/src/Binder.cpp
Normal file
@ -0,0 +1,138 @@
|
||||
//
|
||||
// Binder.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/Binder.cpp#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Binder
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/Binder.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <sql.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
Binder::Binder(const StatementHandle& rStmt, Binder::ParameterBinding dataBinding):
|
||||
_rStmt(rStmt),
|
||||
_paramBinding(dataBinding)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Binder::~Binder()
|
||||
{
|
||||
std::vector<SQLLEN*>::iterator it = _lengthIndicator.begin();
|
||||
std::vector<SQLLEN*>::iterator itEnd = _lengthIndicator.end();
|
||||
for(; it != itEnd; ++it) delete *it;
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const std::string& val)
|
||||
{
|
||||
SQLINTEGER size = (SQLINTEGER) val.size();
|
||||
SQLLEN* pLenIn = new SQLLEN;
|
||||
*pLenIn = SQL_NTS;
|
||||
|
||||
if (PB_AT_EXEC == _paramBinding)
|
||||
*pLenIn = SQL_LEN_DATA_AT_EXEC(size);
|
||||
|
||||
_lengthIndicator.push_back(pLenIn);
|
||||
_dataSize.insert(SizeMap::value_type((SQLPOINTER) val.c_str(), size));
|
||||
|
||||
if (Utility::isError(SQLBindParameter(_rStmt,
|
||||
(SQLUSMALLINT) pos,
|
||||
SQL_PARAM_INPUT,
|
||||
SQL_C_CHAR,
|
||||
SQL_LONGVARCHAR,
|
||||
(SQLUINTEGER) size,
|
||||
0,
|
||||
(SQLPOINTER) val.c_str(),
|
||||
(SQLINTEGER) size,
|
||||
_lengthIndicator.back())))
|
||||
{
|
||||
throw StatementException(_rStmt,
|
||||
"SQLBindParameter()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val)
|
||||
{
|
||||
SQLINTEGER size = (SQLINTEGER) val.size();
|
||||
SQLLEN* pLenIn = new SQLLEN;
|
||||
*pLenIn = size;
|
||||
|
||||
if (PB_AT_EXEC == _paramBinding)
|
||||
*pLenIn = SQL_LEN_DATA_AT_EXEC(size);
|
||||
|
||||
_lengthIndicator.push_back(pLenIn);
|
||||
_dataSize.insert(SizeMap::value_type((SQLPOINTER) val.rawContent(), size));
|
||||
|
||||
if (Utility::isError(SQLBindParameter(_rStmt,
|
||||
(SQLUSMALLINT) pos,
|
||||
SQL_PARAM_INPUT,
|
||||
SQL_C_BINARY,
|
||||
SQL_LONGVARBINARY,
|
||||
(SQLUINTEGER) size,
|
||||
0,
|
||||
(SQLPOINTER) val.rawContent(),
|
||||
(SQLINTEGER) size,
|
||||
_lengthIndicator.back())))
|
||||
{
|
||||
throw StatementException(_rStmt,
|
||||
"SQLBindParameter()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::size_t Binder::dataSize(SQLPOINTER pAddr) const
|
||||
{
|
||||
SizeMap::const_iterator it = _dataSize.find(pAddr);
|
||||
if (it != _dataSize.end()) return it->second;
|
||||
|
||||
throw NotFoundException("Requested data size not found.");
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const char* const &pVal)
|
||||
{
|
||||
//no-op
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
72
Data/ODBC/src/ConnectionHandle.cpp
Normal file
72
Data/ODBC/src/ConnectionHandle.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
//
|
||||
// ConnectionHandle.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/ConnectionHandle.cpp#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ConnectionHandle
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ConnectionHandle.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
ConnectionHandle::ConnectionHandle(EnvironmentHandle* pEnvironment):
|
||||
_pEnvironment(pEnvironment ? pEnvironment : new EnvironmentHandle),
|
||||
_hdbc(SQL_NULL_HDBC),
|
||||
_ownsEnvironment(pEnvironment ? false : true)
|
||||
{
|
||||
if (Utility::isError(SQLAllocHandle(SQL_HANDLE_DBC,
|
||||
_pEnvironment->handle(),
|
||||
&_hdbc)))
|
||||
{
|
||||
throw ODBCException("Could not allocate connection handle.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ConnectionHandle::~ConnectionHandle()
|
||||
{
|
||||
SQLDisconnect(_hdbc);
|
||||
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_DBC, _hdbc);
|
||||
|
||||
if (_ownsEnvironment) delete _pEnvironment;
|
||||
|
||||
poco_assert (!Utility::isError(rc));
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
118
Data/ODBC/src/DataTypes.cpp
Normal file
118
Data/ODBC/src/DataTypes.cpp
Normal file
@ -0,0 +1,118 @@
|
||||
//
|
||||
// DataTypes.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/DataTypes.cpp#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: DataTypes
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/DataTypes.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
DataTypes::DataTypes()
|
||||
{
|
||||
_cDataTypes.insert(ValueType(SQL_CHAR, SQL_C_CHAR));
|
||||
_cDataTypes.insert(ValueType(SQL_VARCHAR, SQL_C_CHAR));
|
||||
_cDataTypes.insert(ValueType(SQL_LONGVARCHAR, SQL_C_CHAR));
|
||||
_cDataTypes.insert(ValueType(SQL_DECIMAL, SQL_C_SLONG));
|
||||
_cDataTypes.insert(ValueType(SQL_NUMERIC, SQL_C_DOUBLE));
|
||||
_cDataTypes.insert(ValueType(SQL_BIT, SQL_C_BIT));
|
||||
_cDataTypes.insert(ValueType(SQL_TINYINT, SQL_C_STINYINT));
|
||||
_cDataTypes.insert(ValueType(SQL_SMALLINT, SQL_C_SSHORT));
|
||||
_cDataTypes.insert(ValueType(SQL_INTEGER, SQL_C_SLONG));
|
||||
_cDataTypes.insert(ValueType(SQL_BIGINT, SQL_C_SBIGINT));
|
||||
_cDataTypes.insert(ValueType(SQL_REAL, SQL_C_FLOAT));
|
||||
_cDataTypes.insert(ValueType(SQL_FLOAT, SQL_C_DOUBLE));
|
||||
_cDataTypes.insert(ValueType(SQL_DOUBLE, SQL_C_DOUBLE));
|
||||
_cDataTypes.insert(ValueType(SQL_BINARY, SQL_C_BINARY));
|
||||
_cDataTypes.insert(ValueType(SQL_VARBINARY, SQL_C_BINARY));
|
||||
_cDataTypes.insert(ValueType(SQL_LONGVARBINARY, SQL_C_BINARY));
|
||||
_cDataTypes.insert(ValueType(SQL_TYPE_DATE, SQL_C_TYPE_DATE));
|
||||
_cDataTypes.insert(ValueType(SQL_TYPE_TIME, SQL_C_TYPE_TIME));
|
||||
_cDataTypes.insert(ValueType(SQL_TYPE_TIMESTAMP, SQL_C_TYPE_TIMESTAMP));
|
||||
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_CHAR, SQL_LONGVARCHAR));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_BIT, SQL_BIT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_TINYINT, SQL_TINYINT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_STINYINT, SQL_TINYINT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_UTINYINT, SQL_TINYINT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_SHORT, SQL_SMALLINT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_SSHORT, SQL_SMALLINT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_USHORT, SQL_SMALLINT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_LONG, SQL_INTEGER));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_SLONG, SQL_INTEGER));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_ULONG, SQL_INTEGER));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_SBIGINT, SQL_BIGINT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_UBIGINT, SQL_BIGINT));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_FLOAT, SQL_REAL));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_DOUBLE, SQL_DOUBLE));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_BINARY, SQL_LONGVARBINARY));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_TYPE_DATE, SQL_TYPE_DATE));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_TYPE_TIME, SQL_TYPE_TIME));
|
||||
_sqlDataTypes.insert(ValueType(SQL_C_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP));
|
||||
}
|
||||
|
||||
|
||||
DataTypes::~DataTypes()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int DataTypes::cDataType(int sqlDataType) const
|
||||
{
|
||||
DataTypeMap::const_iterator it = _cDataTypes.find(sqlDataType);
|
||||
|
||||
if (_cDataTypes.end() == it)
|
||||
throw NotFoundException(format("C data type not found for SQL data type: %d", sqlDataType));
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
int DataTypes::sqlDataType(int cDataType) const
|
||||
{
|
||||
DataTypeMap::const_iterator it = _sqlDataTypes.find(cDataType);
|
||||
|
||||
if (_sqlDataTypes.end() == it)
|
||||
throw NotFoundException(format("SQL data type not found for C data type: %d", cDataType));
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
69
Data/ODBC/src/EnvironmentHandle.cpp
Normal file
69
Data/ODBC/src/EnvironmentHandle.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
//
|
||||
// EnvironmentHandle.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/EnvironmentHandle.cpp#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: EnvironmentHandle
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/EnvironmentHandle.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
EnvironmentHandle::EnvironmentHandle(): _henv(SQL_NULL_HENV)
|
||||
{
|
||||
if (Utility::isError(SQLAllocHandle(SQL_HANDLE_ENV,
|
||||
SQL_NULL_HANDLE,
|
||||
&_henv)) ||
|
||||
Utility::isError(SQLSetEnvAttr(_henv,
|
||||
SQL_ATTR_ODBC_VERSION,
|
||||
(SQLPOINTER) SQL_OV_ODBC3,
|
||||
0)))
|
||||
{
|
||||
throw ODBCException("Could not initialize environment.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EnvironmentHandle::~EnvironmentHandle()
|
||||
{
|
||||
SQLRETURN rc = SQLFreeHandle(SQL_HANDLE_ENV, _henv);
|
||||
poco_assert (!Utility::isError(rc));
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
381
Data/ODBC/src/Extractor.cpp
Normal file
381
Data/ODBC/src/Extractor.cpp
Normal file
@ -0,0 +1,381 @@
|
||||
//
|
||||
// Extractor.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/Extractor.cpp#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Extractor
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/Extractor.h"
|
||||
#include "Poco/Data/ODBC/ODBCColumn.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
const std::string Extractor::FLD_SIZE_EXCEEDED_FMT = "Specified data size (%z bytes) "
|
||||
"exceeds maximum value (%z).\n"
|
||||
"Use Session.setProperty(\"maxFieldSize\", value) "
|
||||
"to increase the maximum allowed data size\n";
|
||||
|
||||
|
||||
Extractor::Extractor(const StatementHandle& rStmt,
|
||||
Preparation& rPreparation):
|
||||
_rStmt(rStmt),
|
||||
_rPreparation(rPreparation),
|
||||
_dataExtraction(rPreparation.getDataExtraction())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Extractor::~Extractor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
bool Extractor::extractBoundImpl<std::string>(std::size_t pos, std::string& val)
|
||||
{
|
||||
std::size_t dataSize = _rPreparation.actualDataSize(pos);
|
||||
SharedPtr<char>& sp = RefAnyCast<SharedPtr<char> >(_rPreparation[pos]);
|
||||
std::size_t len = strlen(sp);
|
||||
if (len < dataSize) dataSize = len;
|
||||
checkDataSize(dataSize);
|
||||
val.assign(sp, dataSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
bool Extractor::extractBoundImpl<Poco::Data::BLOB>(std::size_t pos, Poco::Data::BLOB& val)
|
||||
{
|
||||
std::size_t dataSize = _rPreparation.actualDataSize(pos);
|
||||
checkDataSize(dataSize);
|
||||
SharedPtr<char>& sp = RefAnyCast<SharedPtr<char> >(_rPreparation[pos]);
|
||||
val.assignRaw(sp, dataSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
bool Extractor::extractManualImpl<std::string>(std::size_t pos, std::string& val, SQLSMALLINT cType)
|
||||
{
|
||||
std::size_t maxSize = _rPreparation.getMaxFieldSize();
|
||||
std::size_t fetchedSize = 0;
|
||||
std::size_t totalSize = 0;
|
||||
|
||||
SQLLEN len;
|
||||
std::auto_ptr<char> apChar(new char[CHUNK_SIZE]);
|
||||
char* pChar = apChar.get();
|
||||
SQLRETURN rc = 0;
|
||||
val.clear();
|
||||
|
||||
do
|
||||
{
|
||||
memset(pChar, 0, CHUNK_SIZE);
|
||||
len = 0;
|
||||
rc = SQLGetData(_rStmt,
|
||||
(SQLUSMALLINT) pos,
|
||||
cType, //C data type
|
||||
pChar, //returned value
|
||||
CHUNK_SIZE, //buffer length
|
||||
&len); //length indicator
|
||||
|
||||
if (SQL_NO_DATA != rc && Utility::isError(rc))
|
||||
throw StatementException(_rStmt, "SQLGetData()");
|
||||
|
||||
if (SQL_NO_TOTAL == len)//unknown length, throw
|
||||
throw UnknownDataLengthException("Could not determine returned data length.");
|
||||
|
||||
if (SQL_NO_DATA == rc || SQL_NULL_DATA == len || !len)
|
||||
break;
|
||||
|
||||
fetchedSize = len > CHUNK_SIZE ? CHUNK_SIZE : len;
|
||||
totalSize += fetchedSize;
|
||||
if (totalSize <= maxSize) val.append(pChar, fetchedSize);
|
||||
else throw DataException(format(FLD_SIZE_EXCEEDED_FMT,
|
||||
fetchedSize,
|
||||
maxSize));
|
||||
|
||||
}while (true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
bool Extractor::extractManualImpl<Poco::Data::BLOB>(std::size_t pos,
|
||||
Poco::Data::BLOB& val,
|
||||
SQLSMALLINT cType)
|
||||
{
|
||||
std::size_t maxSize = _rPreparation.getMaxFieldSize();
|
||||
std::size_t fetchedSize = 0;
|
||||
std::size_t totalSize = 0;
|
||||
|
||||
SQLLEN len;
|
||||
std::auto_ptr<char> apChar(new char[CHUNK_SIZE]);
|
||||
char* pChar = apChar.get();
|
||||
SQLRETURN rc = 0;
|
||||
val.clear();
|
||||
|
||||
do
|
||||
{
|
||||
memset(pChar, 0, CHUNK_SIZE);
|
||||
len = 0;
|
||||
rc = SQLGetData(_rStmt,
|
||||
(SQLUSMALLINT) pos,
|
||||
cType, //C data type
|
||||
pChar, //returned value
|
||||
CHUNK_SIZE, //buffer length
|
||||
&len); //length indicator
|
||||
|
||||
if (SQL_NO_DATA != rc && Utility::isError(rc))
|
||||
throw StatementException(_rStmt, "SQLGetData()");
|
||||
|
||||
if (SQL_NO_TOTAL == len)//unknown length, throw
|
||||
throw UnknownDataLengthException("Could not determine returned data length.");
|
||||
|
||||
if (SQL_NO_DATA == rc || SQL_NULL_DATA == len || !len)
|
||||
break;
|
||||
|
||||
fetchedSize = len > CHUNK_SIZE ? CHUNK_SIZE : len;
|
||||
totalSize += fetchedSize;
|
||||
if (totalSize <= maxSize) val.appendRaw(pChar, fetchedSize);
|
||||
else throw DataException(format(FLD_SIZE_EXCEEDED_FMT,
|
||||
fetchedSize,
|
||||
maxSize));
|
||||
|
||||
}while (true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_SLONG);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_SBIGINT);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, double& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_DOUBLE);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, std::string& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_CHAR);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_BINARY);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_STINYINT);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_UTINYINT);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_SSHORT);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_USHORT);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_ULONG);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_SBIGINT);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, bool& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, Utility::boolDataType);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, float& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_FLOAT);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, char& val)
|
||||
{
|
||||
if (Preparation::DE_MANUAL == _dataExtraction)
|
||||
return extractManualImpl(pos, val, SQL_C_STINYINT);
|
||||
else
|
||||
return extractBoundImpl(pos, val);
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Any& val)
|
||||
{
|
||||
ODBCColumn column(_rStmt, pos);
|
||||
|
||||
switch (column.type())
|
||||
{
|
||||
case MetaColumn::FDT_INT8:
|
||||
{ Poco::Int8 i = 0; extract(pos, i); val = i; return true; }
|
||||
|
||||
case MetaColumn::FDT_UINT8:
|
||||
{ Poco::UInt8 i = 0; extract(pos, i); val = i; return true; }
|
||||
|
||||
case MetaColumn::FDT_INT16:
|
||||
{ Poco::Int16 i = 0; extract(pos, i); val = i; return true; }
|
||||
|
||||
case MetaColumn::FDT_UINT16:
|
||||
{ Poco::UInt16 i = 0; extract(pos, i); val = i; return true; }
|
||||
|
||||
case MetaColumn::FDT_INT32:
|
||||
{ Poco::Int32 i = 0; extract(pos, i); val = i; return true; }
|
||||
|
||||
case MetaColumn::FDT_UINT32:
|
||||
{ Poco::UInt32 i = 0; extract(pos, i); val = i; return true; }
|
||||
|
||||
case MetaColumn::FDT_INT64:
|
||||
{ Poco::Int64 i = 0; extract(pos, i); val = i; return true; }
|
||||
|
||||
case MetaColumn::FDT_UINT64:
|
||||
{ Poco::UInt64 i = 0; extract(pos, i); val = i; return true; }
|
||||
|
||||
case MetaColumn::FDT_BOOL:
|
||||
{ bool b; extract(pos, b); val = b; return true; }
|
||||
|
||||
case MetaColumn::FDT_FLOAT:
|
||||
{ float f; extract(pos, f); val = f; return true; }
|
||||
|
||||
case MetaColumn::FDT_DOUBLE:
|
||||
{ double d; extract(pos, d); val = d; return true; }
|
||||
|
||||
case MetaColumn::FDT_STRING:
|
||||
{ std::string s; extract(pos, s); val = s; return true; }
|
||||
|
||||
case MetaColumn::FDT_BLOB:
|
||||
{ Poco::Data::BLOB b; extract(pos, b); val = b; return true; }
|
||||
|
||||
default:
|
||||
throw DataFormatException("Unsupported data type.");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void Extractor::checkDataSize(std::size_t size)
|
||||
{
|
||||
std::size_t maxSize = _rPreparation.getMaxFieldSize();
|
||||
if (size > maxSize)
|
||||
{
|
||||
throw DataException(format(FLD_SIZE_EXCEEDED_FMT,
|
||||
size,
|
||||
maxSize));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
134
Data/ODBC/src/ODBCColumn.cpp
Normal file
134
Data/ODBC/src/ODBCColumn.cpp
Normal file
@ -0,0 +1,134 @@
|
||||
//
|
||||
// ODBCColumn.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/ODBCColumn.cpp#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ODBCColumn
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBCColumn.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
ODBCColumn::ODBCColumn(const StatementHandle& rStmt, std::size_t position) :
|
||||
MetaColumn(position),
|
||||
_rStmt(rStmt)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
ODBCColumn::~ODBCColumn()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ODBCColumn::getDescription()
|
||||
{
|
||||
memset(_columnDesc.name, 0, NAME_BUFFER_LENGTH);
|
||||
_columnDesc.nameBufferLength = 0;
|
||||
_columnDesc.dataType = 0;
|
||||
_columnDesc.size = 0;
|
||||
_columnDesc.decimalDigits = 0;
|
||||
_columnDesc.isNullable = 0;
|
||||
|
||||
if (Utility::isError(SQLDescribeCol(_rStmt,
|
||||
(SQLUSMALLINT) position(),
|
||||
_columnDesc.name,
|
||||
NAME_BUFFER_LENGTH,
|
||||
&_columnDesc.nameBufferLength,
|
||||
&_columnDesc.dataType,
|
||||
&_columnDesc.size,
|
||||
&_columnDesc.decimalDigits,
|
||||
&_columnDesc.isNullable)))
|
||||
{
|
||||
throw StatementException(_rStmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCColumn::init()
|
||||
{
|
||||
getDescription();
|
||||
|
||||
if (Utility::isError(SQLColAttribute(_rStmt,
|
||||
(SQLUSMALLINT) position(),
|
||||
SQL_DESC_LENGTH,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
reinterpret_cast<long int*>(&_dataLength))))
|
||||
{
|
||||
throw StatementException(_rStmt);
|
||||
}
|
||||
|
||||
setName(std::string((char*) _columnDesc.name));
|
||||
setLength(_columnDesc.size);
|
||||
setPrecision(_columnDesc.decimalDigits);
|
||||
setNullable(SQL_NULLABLE == _columnDesc.isNullable);
|
||||
switch(_columnDesc.dataType)
|
||||
{
|
||||
case SQL_CHAR:
|
||||
case SQL_VARCHAR:
|
||||
case SQL_LONGVARCHAR:
|
||||
setType(MetaColumn::FDT_STRING); break;
|
||||
case SQL_TINYINT:
|
||||
setType(MetaColumn::FDT_INT8); break;
|
||||
case SQL_SMALLINT:
|
||||
setType(MetaColumn::FDT_INT16); break;
|
||||
case SQL_INTEGER:
|
||||
case SQL_DECIMAL:
|
||||
setType(MetaColumn::FDT_INT32); break;
|
||||
case SQL_BIGINT:
|
||||
setType(MetaColumn::FDT_INT64); break;
|
||||
case SQL_NUMERIC:
|
||||
case SQL_DOUBLE:
|
||||
case SQL_FLOAT:
|
||||
setType(MetaColumn::FDT_DOUBLE); break;
|
||||
case SQL_REAL:
|
||||
setType(MetaColumn::FDT_FLOAT); break;
|
||||
case SQL_BINARY:
|
||||
case SQL_VARBINARY:
|
||||
case SQL_LONGVARBINARY:
|
||||
case -98:// IBM DB2 non-standard type
|
||||
setType(MetaColumn::FDT_BLOB); break;
|
||||
default:
|
||||
throw DataFormatException("Unsupported data type.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
52
Data/ODBC/src/ODBCException.cpp
Normal file
52
Data/ODBC/src/ODBCException.cpp
Normal file
@ -0,0 +1,52 @@
|
||||
//
|
||||
// ODBCException.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/ODBCException.cpp#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ODBCException
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
POCO_IMPLEMENT_EXCEPTION(ODBCException, Poco::Data::DataException, "Generic ODBC error")
|
||||
POCO_IMPLEMENT_EXCEPTION(InsufficientStorageException, ODBCException, "Insufficient storage error")
|
||||
POCO_IMPLEMENT_EXCEPTION(UnknownDataLengthException, ODBCException, "Unknown length of remaining data error")
|
||||
POCO_IMPLEMENT_EXCEPTION(DataTruncatedException, ODBCException, "Variable length character or binary data truncated")
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
323
Data/ODBC/src/ODBCStatementImpl.cpp
Normal file
323
Data/ODBC/src/ODBCStatementImpl.cpp
Normal file
@ -0,0 +1,323 @@
|
||||
//
|
||||
// ODBCStatementImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/ODBCStatementImpl.cpp#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: ODBCStatementImpl
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include "Poco/Data/ODBC/Handle.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/AbstractPrepare.h"
|
||||
#include <sql.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
const std::string ODBCStatementImpl::INVALID_CURSOR_STATE = "24000";
|
||||
|
||||
|
||||
ODBCStatementImpl::ODBCStatementImpl(SessionImpl& rSession):
|
||||
_rSession(rSession),
|
||||
_stmt(_rSession.dbc()),
|
||||
_stepCalled(false),
|
||||
_nextResponse(0)
|
||||
{
|
||||
checkError(SQLSetStmtAttr(_stmt,
|
||||
SQL_CURSOR_TYPE,
|
||||
(SQLPOINTER) SQL_CURSOR_FORWARD_ONLY,
|
||||
0),
|
||||
"SQLSetStmtAttr(SQL_CURSOR_TYPE, SQL_CURSOR_FORWARD_ONLY)");
|
||||
|
||||
if (_rSession.getFeature("autoBind"))
|
||||
{
|
||||
SQLSetStmtAttr(_stmt,
|
||||
SQL_ATTR_PARAM_BIND_TYPE,
|
||||
(SQLPOINTER) SQL_PARAM_BIND_BY_COLUMN,
|
||||
0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SQLSetStmtAttr(_stmt,
|
||||
SQL_ATTR_ROW_ARRAY_SIZE,
|
||||
(SQLPOINTER) 1,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ODBCStatementImpl::~ODBCStatementImpl()
|
||||
{
|
||||
ColumnPtrVec::iterator it = _columnPtrs.begin();
|
||||
ColumnPtrVec::iterator itEnd = _columnPtrs.end();
|
||||
for(; it != itEnd; ++it) delete *it;
|
||||
}
|
||||
|
||||
|
||||
void ODBCStatementImpl::compileImpl()
|
||||
{
|
||||
_stepCalled = false;
|
||||
_nextResponse = 0;
|
||||
|
||||
std::string statement(toString());
|
||||
if (statement.empty())
|
||||
throw ODBCException("Empty statements are illegal");
|
||||
|
||||
Preparation::DataExtraction ext = _rSession.getFeature("autoExtract") ?
|
||||
Preparation::DE_BOUND : Preparation::DE_MANUAL;
|
||||
|
||||
std::size_t maxFieldSize = AnyCast<std::size_t>(_rSession.getProperty("maxFieldSize"));
|
||||
_pPreparation = new Preparation(_stmt,
|
||||
statement,
|
||||
maxFieldSize,
|
||||
ext);
|
||||
|
||||
Binder::ParameterBinding bind = _rSession.getFeature("autoBind") ?
|
||||
Binder::PB_IMMEDIATE : Binder::PB_AT_EXEC;
|
||||
|
||||
_pBinder = new Binder(_stmt, bind);
|
||||
_pExtractor = new Extractor(_stmt, *_pPreparation);
|
||||
|
||||
bool dataAvailable = hasData();
|
||||
if (dataAvailable && !extractions().size())
|
||||
{
|
||||
fillColumns();
|
||||
makeExtractors(columnsReturned());
|
||||
}
|
||||
|
||||
if (Preparation::DE_BOUND == ext && dataAvailable)
|
||||
{
|
||||
std::size_t pos = 1;
|
||||
Extractions& extracts = extractions();
|
||||
Extractions::iterator it = extracts.begin();
|
||||
Extractions::iterator itEnd = extracts.end();
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
AbstractPrepare* pAP = (*it)->createPrepareObject(_pPreparation, pos);
|
||||
pAP->prepare();
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
delete pAP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ODBCStatementImpl::canBind() const
|
||||
{
|
||||
if (!bindings().empty())
|
||||
return (*bindings().begin())->canBind();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ODBCStatementImpl::bindImpl()
|
||||
{
|
||||
clear();
|
||||
Bindings& binds = bindings();
|
||||
if (!binds.empty())
|
||||
{
|
||||
std::size_t pos = 1;
|
||||
|
||||
Bindings::iterator it = binds.begin();
|
||||
Bindings::iterator itEnd = binds.end();
|
||||
for (; it != itEnd && (*it)->canBind(); ++it)
|
||||
{
|
||||
(*it)->bind(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
}
|
||||
|
||||
SQLRETURN rc = SQLExecute(_stmt);
|
||||
|
||||
if (SQL_NEED_DATA == rc) putData();
|
||||
else checkError(rc, "SQLExecute()");
|
||||
}
|
||||
|
||||
|
||||
void ODBCStatementImpl::putData()
|
||||
{
|
||||
SQLPOINTER pParam = 0;
|
||||
SQLRETURN rc = SQLParamData(_stmt, &pParam);
|
||||
|
||||
do
|
||||
{
|
||||
poco_assert_dbg (pParam);
|
||||
|
||||
SQLINTEGER dataSize = (SQLINTEGER) _pBinder->dataSize(pParam);
|
||||
|
||||
if (Utility::isError(SQLPutData(_stmt, pParam, dataSize)))
|
||||
throw StatementException(_stmt, "SQLPutData()");
|
||||
}while (SQL_NEED_DATA == (rc = SQLParamData(_stmt, &pParam)));
|
||||
|
||||
checkError(rc, "SQLParamData()");
|
||||
}
|
||||
|
||||
|
||||
void ODBCStatementImpl::clear()
|
||||
{
|
||||
SQLRETURN rc = SQLCloseCursor(_stmt);
|
||||
if (Utility::isError(rc))
|
||||
{
|
||||
StatementError err(_stmt);
|
||||
bool ignoreError = false;
|
||||
|
||||
const StatementDiagnostics& diagnostics = err.diagnostics();
|
||||
//ignore "Invalid cursor state" error
|
||||
//(returned by 3.x drivers when cursor is not opened)
|
||||
for (int i = 0; i < diagnostics.count(); ++i)
|
||||
{
|
||||
if (ignoreError =
|
||||
(INVALID_CURSOR_STATE == std::string(diagnostics.sqlState(i))))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreError)
|
||||
throw StatementException(_stmt, "SQLCloseCursor()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool ODBCStatementImpl::hasNext()
|
||||
{
|
||||
if (hasData())
|
||||
{
|
||||
if (_stepCalled)
|
||||
return _stepCalled = nextRowReady();
|
||||
|
||||
_stepCalled = true;
|
||||
_nextResponse = SQLFetch(_stmt);
|
||||
|
||||
if (!nextRowReady())
|
||||
return false;
|
||||
else
|
||||
if (Utility::isError(_nextResponse))
|
||||
checkError(_nextResponse, "SQLFetch()");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ODBCStatementImpl::next()
|
||||
{
|
||||
if (nextRowReady())
|
||||
{
|
||||
poco_assert (columnsExtracted() == _pPreparation->columns());
|
||||
|
||||
Extractions& extracts = extractions();
|
||||
Extractions::iterator it = extracts.begin();
|
||||
Extractions::iterator itEnd = extracts.end();
|
||||
std::size_t pos = 1;
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
_stepCalled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw StatementException(_stmt,
|
||||
std::string("Iterator Error: trying to access the next value"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string ODBCStatementImpl::nativeSQL()
|
||||
{
|
||||
std::string statement = toString();
|
||||
|
||||
//Hopefully, double the original statement length is enough.
|
||||
//If it is not, the total available length is indicated in the retlen parameter,
|
||||
//which is in turn used to resize the buffer and request the native SQL again.
|
||||
SQLINTEGER length = (SQLINTEGER) statement.size() * 2;
|
||||
|
||||
char* pNative = 0;
|
||||
SQLINTEGER retlen = length;
|
||||
do
|
||||
{
|
||||
delete [] pNative;
|
||||
pNative = new char[retlen];
|
||||
memset(pNative, 0, retlen);
|
||||
length = retlen;
|
||||
if (Utility::isError(SQLNativeSql(_rSession.dbc(),
|
||||
(POCO_SQLCHAR*) statement.c_str(),
|
||||
(SQLINTEGER) statement.size(),
|
||||
(POCO_SQLCHAR*) pNative,
|
||||
length,
|
||||
&retlen)))
|
||||
{
|
||||
delete [] pNative;
|
||||
throw ConnectionException(_rSession.dbc(), "SQLNativeSql()");
|
||||
}
|
||||
++retlen;//accomodate for terminating '\0'
|
||||
}while (retlen > length);
|
||||
|
||||
std::string sql(pNative);
|
||||
delete [] pNative;
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
||||
void ODBCStatementImpl::checkError(SQLRETURN rc, const std::string& msg)
|
||||
{
|
||||
if (Utility::isError(rc))
|
||||
{
|
||||
std::ostringstream os;
|
||||
os << std::endl << "Requested SQL statement: " << toString() << std::endl;
|
||||
os << "Native SQL statement: " << nativeSQL() << std::endl;
|
||||
std::string str(msg); str += os.str();
|
||||
|
||||
throw StatementException(_stmt, str);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCStatementImpl::fillColumns()
|
||||
{
|
||||
Poco::UInt32 colCount = columnsReturned();
|
||||
|
||||
for (int i = 1; i <= colCount; ++i)
|
||||
_columnPtrs.push_back(new ODBCColumn(_stmt, i));
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
75
Data/ODBC/src/Parameter.cpp
Normal file
75
Data/ODBC/src/Parameter.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
//
|
||||
// Parameter.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/Parameter.cpp#3 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Parameter
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/Parameter.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Error.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
Parameter::Parameter(const StatementHandle& rStmt, std::size_t colNum) :
|
||||
_rStmt(rStmt),
|
||||
_number(colNum)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
Parameter::~Parameter()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Parameter::init()
|
||||
{
|
||||
if (Utility::isError(SQLDescribeParam(_rStmt,
|
||||
(SQLUSMALLINT) _number,
|
||||
&_dataType,
|
||||
&_columnSize,
|
||||
&_decimalDigits,
|
||||
&_isNullable)))
|
||||
{
|
||||
throw StatementException(_rStmt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
169
Data/ODBC/src/Preparation.cpp
Normal file
169
Data/ODBC/src/Preparation.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
//
|
||||
// Preparation.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/Preparation.cpp#3 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: DataCore
|
||||
// Module: Preparation
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/Preparation.h"
|
||||
#include "Poco/Data/ODBC/ODBCColumn.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
Preparation::Preparation(const StatementHandle& rStmt,
|
||||
const std::string& statement,
|
||||
std::size_t maxFieldSize,
|
||||
DataExtraction dataExtraction):
|
||||
_rStmt(rStmt),
|
||||
_maxFieldSize(maxFieldSize),
|
||||
_dataExtraction(dataExtraction)
|
||||
{
|
||||
POCO_SQLCHAR* pStr = (POCO_SQLCHAR*) statement.c_str();
|
||||
if (Utility::isError(SQLPrepare(_rStmt, pStr, (SQLINTEGER) statement.length())))
|
||||
throw StatementException(_rStmt);
|
||||
|
||||
SQLSMALLINT nCol;
|
||||
if (Utility::isError(SQLNumResultCols(_rStmt, &nCol)))
|
||||
throw StatementException(_rStmt);
|
||||
|
||||
if (nCol)
|
||||
{
|
||||
_pValues.resize(nCol, 0);
|
||||
_pLengths.resize(nCol, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Preparation::~Preparation()
|
||||
{
|
||||
std::vector<SQLLEN*>::iterator itLen = _pLengths.begin();
|
||||
std::vector<SQLLEN*>::iterator itLenEnd = _pLengths.end();
|
||||
for (; itLen != itLenEnd; ++itLen) delete *itLen;
|
||||
|
||||
std::vector<Poco::Any*>::iterator itVal = _pValues.begin();
|
||||
std::vector<Poco::Any*>::iterator itValEnd = _pValues.end();
|
||||
for (; itVal != itValEnd; ++itVal) delete *itVal;
|
||||
}
|
||||
|
||||
|
||||
Poco::Any& Preparation::operator [] (std::size_t pos)
|
||||
{
|
||||
poco_assert (pos > 0 && pos <= _pValues.size());
|
||||
|
||||
return *_pValues[pos-1];
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepareRaw(std::size_t pos, SQLSMALLINT valueType, std::size_t size)
|
||||
{
|
||||
poco_assert (DE_BOUND == _dataExtraction);
|
||||
poco_assert (pos > 0 && pos <= _pValues.size());
|
||||
|
||||
char* pChr = new char[size];
|
||||
poco_assert_dbg (pChr);
|
||||
memset(pChr, 0, size);
|
||||
|
||||
SharedPtr<char> sp = pChr;
|
||||
_pValues[pos-1] = new Any(sp);
|
||||
_pLengths[pos-1] = new SQLLEN;
|
||||
*_pLengths[pos-1] = (SQLLEN) size;
|
||||
|
||||
if (Utility::isError(SQLBindCol(_rStmt,
|
||||
(SQLUSMALLINT) pos,
|
||||
valueType,
|
||||
(SQLPOINTER) pChr,
|
||||
(SQLINTEGER) size,
|
||||
_pLengths[pos-1])))
|
||||
{
|
||||
throw StatementException(_rStmt, "SQLBindCol()");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Preparation::prepare(std::size_t pos, const Poco::Any&)
|
||||
{
|
||||
ODBCColumn col(_rStmt, pos);
|
||||
|
||||
switch (col.type())
|
||||
{
|
||||
case MetaColumn::FDT_INT8:
|
||||
return preparePOD<Poco::Int8>(pos, SQL_C_STINYINT);
|
||||
|
||||
case MetaColumn::FDT_UINT8:
|
||||
return preparePOD<Poco::UInt8>(pos, SQL_C_UTINYINT);
|
||||
|
||||
case MetaColumn::FDT_INT16:
|
||||
return preparePOD<Poco::Int16>(pos, SQL_C_SSHORT);
|
||||
|
||||
case MetaColumn::FDT_UINT16:
|
||||
return preparePOD<Poco::UInt16>(pos, SQL_C_USHORT);
|
||||
|
||||
case MetaColumn::FDT_INT32:
|
||||
return preparePOD<Poco::Int32>(pos, SQL_C_SLONG);
|
||||
|
||||
case MetaColumn::FDT_UINT32:
|
||||
return preparePOD<Poco::UInt32>(pos, SQL_C_ULONG);
|
||||
|
||||
case MetaColumn::FDT_INT64:
|
||||
return preparePOD<Poco::Int64>(pos, SQL_C_SBIGINT);
|
||||
|
||||
case MetaColumn::FDT_UINT64:
|
||||
return preparePOD<Poco::UInt64>(pos, SQL_C_UBIGINT);
|
||||
|
||||
case MetaColumn::FDT_BOOL:
|
||||
return preparePOD<bool>(pos, Utility::boolDataType);
|
||||
|
||||
case MetaColumn::FDT_FLOAT:
|
||||
return preparePOD<float>(pos, SQL_C_FLOAT);
|
||||
|
||||
case MetaColumn::FDT_DOUBLE:
|
||||
return preparePOD<float>(pos, SQL_C_DOUBLE);
|
||||
|
||||
case MetaColumn::FDT_STRING:
|
||||
return prepareRaw(pos, SQL_C_CHAR, maxDataSize(pos));
|
||||
|
||||
case MetaColumn::FDT_BLOB:
|
||||
return prepareRaw(pos, SQL_C_BINARY, maxDataSize(pos));
|
||||
|
||||
default:
|
||||
throw DataFormatException("Unsupported data type.");
|
||||
}
|
||||
|
||||
prepareRaw(pos, SQL_C_BINARY, maxDataSize(pos));
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
283
Data/ODBC/src/SessionImpl.cpp
Normal file
283
Data/ODBC/src/SessionImpl.cpp
Normal file
@ -0,0 +1,283 @@
|
||||
//
|
||||
// SessionImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/SessionImpl.cpp#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: SessionImpl
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/SessionImpl.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include "Poco/Data/ODBC/Error.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include <sqlext.h>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
SessionImpl::SessionImpl(const std::string& connect,
|
||||
Poco::Any maxFieldSize,
|
||||
bool enforceCapability,
|
||||
bool autoBind,
|
||||
bool autoExtract):
|
||||
_connect(connect),
|
||||
_maxFieldSize(maxFieldSize),
|
||||
_enforceCapability(enforceCapability),
|
||||
_autoBind(autoBind),
|
||||
_autoExtract(autoExtract)
|
||||
{
|
||||
open();
|
||||
}
|
||||
|
||||
|
||||
SessionImpl::~SessionImpl()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
Poco::Data::StatementImpl* SessionImpl::createStatementImpl()
|
||||
{
|
||||
return new ODBCStatementImpl(*this);
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::begin()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::open()
|
||||
{
|
||||
POCO_SQLCHAR connectOutput[512] = {0};
|
||||
SQLSMALLINT result;
|
||||
|
||||
if (Utility::isError(SQLDriverConnect(_db
|
||||
, NULL
|
||||
,(POCO_SQLCHAR*) _connect.c_str()
|
||||
,(SQLSMALLINT) SQL_NTS
|
||||
, connectOutput
|
||||
, sizeof(connectOutput)
|
||||
, &result
|
||||
, SQL_DRIVER_NOPROMPT)))
|
||||
{
|
||||
ConnectionException exc(_db);
|
||||
close();
|
||||
throw exc;
|
||||
}
|
||||
|
||||
addFeature("enforceCapability",
|
||||
&SessionImpl::setEnforceCapability,
|
||||
&SessionImpl::getEnforceCapability);
|
||||
|
||||
addFeature("autoCommit",
|
||||
&SessionImpl::autoCommit,
|
||||
&SessionImpl::isAutoCommit);
|
||||
|
||||
addFeature("autoBind",
|
||||
&SessionImpl::autoBind,
|
||||
&SessionImpl::isAutoBind);
|
||||
|
||||
addFeature("autoExtract",
|
||||
&SessionImpl::autoExtract,
|
||||
&SessionImpl::isAutoExtract);
|
||||
|
||||
addProperty("maxFieldSize",
|
||||
&SessionImpl::setMaxFieldSize,
|
||||
&SessionImpl::getMaxFieldSize);
|
||||
|
||||
if (_enforceCapability && !isCapable())
|
||||
{
|
||||
close();
|
||||
throw ODBCException("Connection closed "
|
||||
"(capability enforcement required but not all required functions supported).");
|
||||
}
|
||||
|
||||
SQLSetConnectAttr(_db, SQL_ATTR_QUIET_MODE, 0, 0);
|
||||
|
||||
if (!canTransact()) autoCommit("", true);
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::canTransact()
|
||||
{
|
||||
SQLUSMALLINT ret;
|
||||
checkError(SQLGetInfo(_db, SQL_TXN_CAPABLE, &ret, 0, 0),
|
||||
"Failed to obtain transaction capability info.");
|
||||
|
||||
return (SQL_TC_NONE != ret);
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::autoCommit(const std::string&, bool val)
|
||||
{
|
||||
checkError(SQLSetConnectAttr(_db,
|
||||
SQL_ATTR_AUTOCOMMIT,
|
||||
val ? (SQLPOINTER) SQL_AUTOCOMMIT_ON :
|
||||
(SQLPOINTER) SQL_AUTOCOMMIT_OFF,
|
||||
0), "Failed to set automatic commit.");
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isAutoCommit(const std::string&)
|
||||
{
|
||||
Poco::UInt32 value = 0;
|
||||
|
||||
checkError(SQLGetConnectAttr(_db,
|
||||
SQL_ATTR_AUTOCOMMIT,
|
||||
&value,
|
||||
0,
|
||||
0));
|
||||
|
||||
return (0 != value);
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isConnected()
|
||||
{
|
||||
Poco::UInt32 value = 0;
|
||||
|
||||
if (Utility::isError(SQLGetConnectAttr(_db,
|
||||
SQL_ATTR_CONNECTION_DEAD,
|
||||
&value,
|
||||
0,
|
||||
0)))
|
||||
return false;
|
||||
|
||||
return (0 == value);
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::close()
|
||||
{
|
||||
if (!isConnected()) return;
|
||||
|
||||
commit();
|
||||
checkError(SQLDisconnect(_db));
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isCapable()
|
||||
{
|
||||
SQLUSMALLINT exists[FUNCTIONS] = {0};
|
||||
|
||||
if (Utility::isError(SQLGetFunctions(_db, SQL_API_ODBC3_ALL_FUNCTIONS, exists)))
|
||||
{
|
||||
throw ConnectionException(_db,
|
||||
"SQLGetFunctions(SQL_API_ODBC3_ALL_FUNCTIONS)");
|
||||
}
|
||||
|
||||
return
|
||||
exists[SQL_API_SQLBINDPARAMETER] &&
|
||||
exists[SQL_API_SQLBINDCOL] &&
|
||||
exists[SQL_API_SQLGETDATA] &&
|
||||
exists[SQL_API_SQLPUTDATA] &&
|
||||
exists[SQL_API_SQLPARAMDATA] &&
|
||||
exists[SQL_API_SQLDESCRIBECOL] &&
|
||||
exists[SQL_API_SQLDESCRIBEPARAM] &&
|
||||
exists[SQL_API_SQLGETINFO] &&
|
||||
exists[SQL_API_SQLGETDIAGREC] &&
|
||||
exists[SQL_API_SQLGETDIAGFIELD] &&
|
||||
exists[SQL_API_SQLPREPARE] &&
|
||||
exists[SQL_API_SQLEXECUTE] &&
|
||||
exists[SQL_API_SQLEXECDIRECT] &&
|
||||
exists[SQL_API_SQLFETCH] &&
|
||||
exists[SQL_API_SQLNUMRESULTCOLS] &&
|
||||
exists[SQL_API_SQLALLOCHANDLE] &&
|
||||
exists[SQL_API_SQLFREEHANDLE] &&
|
||||
exists[SQL_API_SQLCLOSECURSOR] &&
|
||||
exists[SQL_API_SQLSETCONNECTATTR] &&
|
||||
exists[SQL_API_SQLSETSTMTATTR] &&
|
||||
exists[SQL_API_SQLENDTRAN] &&
|
||||
exists[SQL_API_SQLNATIVESQL] &&
|
||||
exists[SQL_API_SQLCOLATTRIBUTE];
|
||||
}
|
||||
|
||||
|
||||
int SessionImpl::maxStatementLength()
|
||||
{
|
||||
SQLUINTEGER info;
|
||||
SQLRETURN rc = 0;
|
||||
if (Utility::isError(rc = SQLGetInfo(_db,
|
||||
SQL_MAXIMUM_STATEMENT_LENGTH,
|
||||
(SQLPOINTER) &info,
|
||||
0,
|
||||
0)))
|
||||
{
|
||||
throw ConnectionException(_db,
|
||||
"SQLGetInfo(SQL_MAXIMUM_STATEMENT_LENGTH)");
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::setEnforceCapability(const std::string&, bool val)
|
||||
{
|
||||
_enforceCapability = val;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::getEnforceCapability(const std::string&)
|
||||
{
|
||||
return _enforceCapability;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::autoBind(const std::string&, bool val)
|
||||
{
|
||||
_autoBind = val;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isAutoBind(const std::string& name)
|
||||
{
|
||||
return _autoBind;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::autoExtract(const std::string&, bool val)
|
||||
{
|
||||
_autoExtract = val;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isAutoExtract(const std::string& name)
|
||||
{
|
||||
return _autoExtract;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
78
Data/ODBC/src/SessionInstantiator.cpp
Normal file
78
Data/ODBC/src/SessionInstantiator.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// SessionInstantiator.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/SessionInstantiator.cpp#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: SessionInstantiator
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/SessionInstantiator.h"
|
||||
#include "Poco/Data/ODBC/SessionImpl.h"
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
const std::string SessionInstantiator::KEY("ODBC");
|
||||
|
||||
|
||||
SessionInstantiator::SessionInstantiator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SessionInstantiator::~SessionInstantiator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> SessionInstantiator::create(const std::string& initString)
|
||||
{
|
||||
return Poco::AutoPtr<Poco::Data::SessionImpl>(new SessionImpl(initString));
|
||||
}
|
||||
|
||||
|
||||
void SessionInstantiator::addToFactory()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().add(KEY, new SessionInstantiator());
|
||||
}
|
||||
|
||||
|
||||
void SessionInstantiator::removeFromFactory()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().remove(KEY);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
125
Data/ODBC/src/Utility.cpp
Normal file
125
Data/ODBC/src/Utility.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
//
|
||||
// Utility.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/src/Utility.cpp#2 $
|
||||
//
|
||||
// Library: ODBC
|
||||
// Package: ODBC
|
||||
// Module: Utility
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Handle.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace ODBC {
|
||||
|
||||
|
||||
const DataTypes Utility::_dataTypes;
|
||||
const SQLSMALLINT Utility::boolDataType = (sizeof(bool) <= sizeof(char)) ? SQL_C_TINYINT :
|
||||
(sizeof(bool) == sizeof(short)) ? SQL_C_SHORT : SQL_C_LONG;
|
||||
|
||||
|
||||
Utility::DriverMap& Utility::drivers(Utility::DriverMap& driverMap)
|
||||
{
|
||||
static const EnvironmentHandle henv;
|
||||
const int length = sizeof(POCO_SQLCHAR) * 512;
|
||||
|
||||
POCO_SQLCHAR desc[length];
|
||||
memset(desc, 0, length);
|
||||
SQLSMALLINT len1 = length;
|
||||
POCO_SQLCHAR attr[length];
|
||||
memset(attr, 0, length);
|
||||
SQLSMALLINT len2 = length;
|
||||
RETCODE rc = 0;
|
||||
|
||||
while (!Utility::isError(rc = SQLDrivers(henv,
|
||||
SQL_FETCH_NEXT,
|
||||
desc,
|
||||
length,
|
||||
&len1,
|
||||
attr,
|
||||
len2,
|
||||
&len2)))
|
||||
{
|
||||
driverMap.insert(DSNMap::value_type(std::string((char *) desc),
|
||||
std::string((char *) attr)));
|
||||
memset(desc, 0, length);
|
||||
memset(attr, 0, length);
|
||||
len2 = length;
|
||||
}
|
||||
|
||||
if (SQL_NO_DATA != rc)
|
||||
throw EnvironmentError(henv);
|
||||
|
||||
return driverMap;
|
||||
}
|
||||
|
||||
|
||||
Utility::DSNMap& Utility::dataSources(Utility::DSNMap& dsnMap)
|
||||
{
|
||||
static const EnvironmentHandle henv;
|
||||
const int length = sizeof(POCO_SQLCHAR) * 512;
|
||||
const int dsnLength = sizeof(POCO_SQLCHAR) * (SQL_MAX_DSN_LENGTH + 1);
|
||||
|
||||
POCO_SQLCHAR dsn[dsnLength];
|
||||
memset(dsn, 0, dsnLength);
|
||||
SQLSMALLINT len1 = sizeof(POCO_SQLCHAR) * SQL_MAX_DSN_LENGTH;
|
||||
POCO_SQLCHAR desc[length];
|
||||
memset(desc, 0, length);
|
||||
SQLSMALLINT len2 = length;
|
||||
RETCODE rc = 0;
|
||||
|
||||
while (!Utility::isError(rc = SQLDataSources(henv,
|
||||
SQL_FETCH_NEXT,
|
||||
dsn,
|
||||
SQL_MAX_DSN_LENGTH,
|
||||
&len1,
|
||||
desc,
|
||||
len2,
|
||||
&len2)))
|
||||
{
|
||||
dsnMap.insert(DSNMap::value_type(std::string((char *) dsn), std::string((char *) desc)));
|
||||
memset(dsn, 0, dsnLength);
|
||||
memset(desc, 0, length);
|
||||
len2 = length;
|
||||
}
|
||||
|
||||
if (SQL_NO_DATA != rc)
|
||||
throw EnvironmentError(henv);
|
||||
|
||||
return dsnMap;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::ODBC
|
25
Data/ODBC/testsuite/Makefile
Normal file
25
Data/ODBC/testsuite/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/Main/Data/ODBC/testsuite/Makefile#1 $
|
||||
#
|
||||
# Makefile for Poco SQLite testsuite
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
ifeq ($(OSNAME),Darwin)
|
||||
SYSLIBS += -liodbc -liodbcinst
|
||||
else
|
||||
SYSLIBS += -lodbc -lodbcinst
|
||||
endif
|
||||
|
||||
objects = ODBCTestSuite Driver \
|
||||
ODBCDB2Test ODBCMySQLTest ODBCOracleTest \
|
||||
ODBCPostgreSQLTest ODBCSQLiteTest SQLExecutor
|
||||
|
||||
target = testrunner
|
||||
target_version = 1
|
||||
target_libs = PocoODBC PocoData PocoFoundation CppUnit
|
||||
|
||||
include $(POCO_BASE)/build/rules/exec
|
227
Data/ODBC/testsuite/TestSuite_VS71.vcproj
Normal file
227
Data/ODBC/testsuite/TestSuite_VS71.vcproj
Normal file
@ -0,0 +1,227 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="TestSuite"
|
||||
ProjectGUID="{1b30a91b-375f-11db-837b-00123fc423b5}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include;..\..\..\Foundation\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib PocoDatad.lib PocoODBCd.lib odbc32.lib odbccp32.lib"
|
||||
OutputFile="bin/TestSuited.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="bin/TestSuited.pdb"
|
||||
SubSystem="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForWindowsApplication="TRUE"
|
||||
AdditionalIncludeDirectories="..\include;..\..\..\Foundation\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib PocoData.lib PocoODBC.lib odbc32.lib odbccp32.lib"
|
||||
OutputFile="bin/TestSuite.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="ODBC"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\ODBCAccessTest.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCDB2Test.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCMySQLTest.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCOracleTest.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCPostgreSQLTest.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCSQLiteTest.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCSQLServerTest.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SQLExecutor.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\ODBCAccessTest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCDB2Test.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCMySQLTest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCOracleTest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCPostgreSQLTest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCSQLiteTest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCSQLServerTest.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SQLExecutor.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="_Suite"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\ODBCTestSuite.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\ODBCTestSuite.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="_Driver"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\WinDriver.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
307
Data/ODBC/testsuite/TestSuite_VS80.vcproj
Normal file
307
Data/ODBC/testsuite/TestSuite_VS80.vcproj
Normal file
@ -0,0 +1,307 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="TestSuite"
|
||||
ProjectGUID="{1B30A91B-375F-11DB-837B-00123FC423B5}"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include;..\..\..\Foundation\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib PocoODBCd.lib PocoDatad.lib odbc32.lib odbccp32.lib"
|
||||
OutputFile="bin/TestSuited.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="bin/TestSuited.pdb"
|
||||
SubSystem="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories="..\include;..\..\..\Foundation\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib PocoODBC.lib PocoData.lib odbc32.lib odbccp32.lib"
|
||||
OutputFile="bin/TestSuite.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="ODBC"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\ODBCAccessTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCDB2Test.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCMySQLTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCOracleTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCPostgreSQLTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCSQLiteTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCSQLServerTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SQLExecutor.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\ODBCAccessTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCDB2Test.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCMySQLTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCOracleTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCPostgreSQLTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCSQLiteTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ODBCSQLServerTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SQLExecutor.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="_Suite"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\ODBCTestSuite.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\ODBCTestSuite.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="_Driver"
|
||||
>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\WinDriver.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
39
Data/ODBC/testsuite/src/Driver.cpp
Normal file
39
Data/ODBC/testsuite/src/Driver.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/Driver.cpp#2 $
|
||||
//
|
||||
// Console-based test driver for Poco SQLite.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "ODBCTestSuite.h"
|
||||
|
||||
|
||||
CppUnitMain(ODBCTestSuite)
|
244
Data/ODBC/testsuite/src/ODBCAccessTest.cpp
Normal file
244
Data/ODBC/testsuite/src/ODBCAccessTest.cpp
Normal file
@ -0,0 +1,244 @@
|
||||
//
|
||||
// ODBCAccessTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCAccessTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ODBCAccessTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/ODBC/SessionInstantiator.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include <sqltypes.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
using Poco::Data::ODBC::Utility;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using Poco::Data::ODBC::StatementDiagnostics;
|
||||
using Poco::format;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCAccessTest::_pSession = 0;
|
||||
std::string ODBCAccessTest::_dsn = "PocoDataAccessTest";
|
||||
std::string ODBCAccessTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCAccessTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCAccessTest::_dataSources;
|
||||
|
||||
|
||||
ODBCAccessTest::ODBCAccessTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
ODBC::SessionInstantiator::addToFactory();
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::SessionInstantiator::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. Access tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
//N.B. Access driver does not suport check for connection.
|
||||
if (_pSession) std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. Access tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
ODBCAccessTest::~ODBCAccessTest()
|
||||
{
|
||||
ODBC::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void ODBCAccessTest::testSimpleAccess()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string lastName = "lastName";
|
||||
int age = 133132;
|
||||
int count = 0;
|
||||
std::string result;
|
||||
|
||||
recreatePersonTable();
|
||||
|
||||
count = 0;
|
||||
try { *_pSession << "INSERT INTO PERSON VALUES('lastName', 'firstName', 'Address', 133132)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
catch(StatementException& ex){ std::cout << ex.toString() << std::endl; fail ("testSimpleAccess()");}
|
||||
|
||||
try { *_pSession << "SELECT COUNT(*) FROM PERSON", into(count), now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
catch(StatementException& ex){ std::cout << ex.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
assert (count == 1);
|
||||
|
||||
try { *_pSession << "SELECT LastName FROM PERSON", into(result), now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
catch(StatementException& ex){ std::cout << ex.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
assert (lastName == result);
|
||||
|
||||
try { *_pSession << "SELECT Age FROM PERSON", into(count), now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
catch(StatementException& ex){ std::cout << ex.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
assert (count == age);
|
||||
}
|
||||
|
||||
|
||||
void ODBCAccessTest::dropTable(const std::string& tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
*_pSession << format("DROP TABLE %s", tableName), now;
|
||||
}
|
||||
catch (StatementException& ex)
|
||||
{
|
||||
bool ignoreError = false;
|
||||
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
|
||||
StatementDiagnostics::Iterator it = flds.begin();
|
||||
for (; it != flds.end(); ++it)
|
||||
{
|
||||
if (-1305 == it->_nativeError)//MS Access -1305 (table does not exist)
|
||||
{
|
||||
ignoreError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreError) throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCAccessTest::recreatePersonTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
*_pSession << "CREATE TABLE Person (LastName TEXT(30), FirstName TEXT(30), Address TEXT(30), Age INTEGER)", now;
|
||||
}
|
||||
|
||||
|
||||
void ODBCAccessTest::checkODBCSetup()
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("Microsoft Access Driver") != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
{
|
||||
std::cout << "Driver NOT found, will throw." << std::endl;
|
||||
throw NotFoundException("Microsoft Access ODBC driver.");
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("Microsoft Access Driver") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "Access DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;Uid=Admin;Pwd=;", _dsn);
|
||||
}
|
||||
|
||||
|
||||
void ODBCAccessTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ODBCAccessTest::tearDown()
|
||||
{
|
||||
dropTable("Person");
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCAccessTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCAccessTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ODBCAccessTest, testSimpleAccess);
|
||||
|
||||
return pSuite;
|
||||
}
|
80
Data/ODBC/testsuite/src/ODBCAccessTest.h
Normal file
80
Data/ODBC/testsuite/src/ODBCAccessTest.h
Normal file
@ -0,0 +1,80 @@
|
||||
//
|
||||
// ODBCAccessTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCAccessTest.h#2 $
|
||||
//
|
||||
// Definition of the ODBCAccessTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBCAccessTest_INCLUDED
|
||||
#define ODBCAccessTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "SQLExecutor.h"
|
||||
|
||||
|
||||
class ODBCAccessTest: public CppUnit::TestCase
|
||||
/// MS Access ODBC test class
|
||||
/// Tested:
|
||||
///
|
||||
/// Driver | DB | OS
|
||||
/// ------------+-----------+------------------------------------------
|
||||
/// 4.00.6305.00| Jet 4.0 | MS Windows XP Professional x64 v.2003/SP1
|
||||
{
|
||||
public:
|
||||
ODBCAccessTest(const std::string& name);
|
||||
~ODBCAccessTest();
|
||||
|
||||
void testSimpleAccess();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
bool _owner;
|
||||
};
|
||||
|
||||
|
||||
#endif // ODBCAccessTest_INCLUDED
|
946
Data/ODBC/testsuite/src/ODBCDB2Test.cpp
Normal file
946
Data/ODBC/testsuite/src/ODBCDB2Test.cpp
Normal file
@ -0,0 +1,946 @@
|
||||
//
|
||||
// ODBCDB2Test.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCDB2Test.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ODBCDB2Test.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/ODBC/SessionInstantiator.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include <sqltypes.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
using Poco::Data::ODBC::Utility;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using Poco::Data::ODBC::StatementDiagnostics;
|
||||
using Poco::format;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
const bool ODBCDB2Test::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCDB2Test::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCDB2Test::_pExecutor = 0;
|
||||
std::string ODBCDB2Test::_dsn = "PocoDataDB2Test";
|
||||
std::string ODBCDB2Test::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCDB2Test::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCDB2Test::_dataSources;
|
||||
|
||||
|
||||
ODBCDB2Test::ODBCDB2Test(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
ODBC::SessionInstantiator::addToFactory();
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::SessionInstantiator::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. DB2 tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor) _pExecutor = new SQLExecutor("DB2 SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. DB2 tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
ODBCDB2Test::~ODBCDB2Test()
|
||||
{
|
||||
ODBC::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testBareboneODBC()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableCreateString = "CREATE TABLE Test "
|
||||
"(First VARCHAR(30),"
|
||||
"Second VARCHAR(30),"
|
||||
"Third BLOB,"
|
||||
"Fourth INTEGER,"
|
||||
"Fifth FLOAT)";
|
||||
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSimpleAccess()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableName("Person");
|
||||
int count = 0;
|
||||
|
||||
recreatePersonTable();
|
||||
|
||||
*_pSession << "SELECT count(*) FROM sysibm.systables WHERE name = 'PERSON' AND creator = 'DB2ADMIN'",
|
||||
into(count),
|
||||
use(tableName),
|
||||
now;
|
||||
assert (1 == count);
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccess();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testComplexType()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexType();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSimpleAccessVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccessVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testComplexTypeVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexTypeVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testInsertVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testInsertEmptyVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertEmptyVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testInsertSingleBulk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testInsertSingleBulkVec()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulkVec();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testLimit()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testLimitZero()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitZero();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testLimitOnce()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
recreateIntsTable();
|
||||
_pExecutor->limitOnce();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testLimitPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitPrepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCDB2Test::testPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->prepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSetComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void ODBCDB2Test::testMultiSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testMultiSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testMapComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testMultiMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiMapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSelectIntoSingle()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingle();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSelectIntoSingleStep()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleStep();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSelectIntoSingleFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testLowerLimitOk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitOk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testSingleSelect()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->singleSelect();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testLowerLimitFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testCombinedLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCDB2Test::testRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->ranges();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testCombinedIllegalLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedIllegalLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCDB2Test::testIllegalRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->illegalRange();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testEmptyDB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->emptyDB();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testBLOB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
const std::size_t maxFldSize = 1000000;
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
|
||||
recreatePersonBLOBTable();
|
||||
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&)
|
||||
{
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blob(maxFldSize);
|
||||
i += 2;
|
||||
}
|
||||
|
||||
recreatePersonBLOBTable();
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize+1);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&) { }
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testBLOBStmt()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blobStmt();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testFloat()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->floats();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testDouble()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->doubles();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testTuple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tuples();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testTupleVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tupleVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::testInternalExtraction()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateVectorsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->internalExtraction();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::dropTable(const std::string& tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
*_pSession << format("DROP TABLE %s", tableName), now;
|
||||
}
|
||||
catch (StatementException& ex)
|
||||
{
|
||||
bool ignoreError = false;
|
||||
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
|
||||
StatementDiagnostics::Iterator it = flds.begin();
|
||||
for (; it != flds.end(); ++it)
|
||||
{
|
||||
if (-204 == it->_nativeError)//(table does not exist)
|
||||
{
|
||||
ignoreError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreError) throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::recreatePersonTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::recreatePersonBLOBTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::recreateIntsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::recreateStringsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::recreateFloatsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::recreateTuplesTable()
|
||||
{
|
||||
dropTable("Tuples");
|
||||
try { *_pSession << "CREATE TABLE Tuples "
|
||||
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
|
||||
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
|
||||
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::recreateVectorsTable()
|
||||
{
|
||||
dropTable("Vectors");
|
||||
try { *_pSession << "CREATE TABLE Vectors (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::checkODBCSetup()
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("IBM DB2") != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
{
|
||||
std::cout << "DB2 driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("IBM DB2") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "DB2 DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;Uid=db2admin;Pwd=db2admin;", _dsn);
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ODBCDB2Test::tearDown()
|
||||
{
|
||||
dropTable("Person");
|
||||
dropTable("Strings");
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCDB2Test::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCDB2Test");
|
||||
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testBareboneODBC);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccess);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testComplexType);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSimpleAccessVector);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testComplexTypeVector);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertVector);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertEmptyVector);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertSingleBulk);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testInsertSingleBulkVec);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testLimit);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testLimitOnce);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testLimitPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testLimitZero);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSetComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testMultiSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testMultiSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testMapComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testMultiMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingle);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingleStep);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSelectIntoSingleFail);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testLowerLimitOk);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testLowerLimitFail);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testCombinedLimits);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testCombinedIllegalLimits);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testRange);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testIllegalRange);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testSingleSelect);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testEmptyDB);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testBLOB);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testBLOBStmt);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testFloat);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testDouble);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testTuple);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testTupleVector);
|
||||
CppUnit_addTest(pSuite, ODBCDB2Test, testInternalExtraction);
|
||||
|
||||
return pSuite;
|
||||
}
|
134
Data/ODBC/testsuite/src/ODBCDB2Test.h
Normal file
134
Data/ODBC/testsuite/src/ODBCDB2Test.h
Normal file
@ -0,0 +1,134 @@
|
||||
//
|
||||
// ODBCDB2Test.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCDB2Test.h#2 $
|
||||
//
|
||||
// Definition of the ODBCDB2Test class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBCDB2Test_INCLUDED
|
||||
#define ODBCDB2Test_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "SQLExecutor.h"
|
||||
|
||||
|
||||
class ODBCDB2Test: public CppUnit::TestCase
|
||||
/// IBM DB2 UDB ODBC test class
|
||||
/// Tested:
|
||||
///
|
||||
/// Driver | DB | OS
|
||||
/// ------------+-------------------+------------------------------------------
|
||||
/// 9.01.00.356 | DB2 Express-C 9.1 | MS Windows XP Professional x64 v.2003/SP1
|
||||
{
|
||||
public:
|
||||
ODBCDB2Test(const std::string& name);
|
||||
~ODBCDB2Test();
|
||||
|
||||
void testBareboneODBC();
|
||||
|
||||
void testSimpleAccess();
|
||||
void testComplexType();
|
||||
void testSimpleAccessVector();
|
||||
void testComplexTypeVector();
|
||||
void testInsertVector();
|
||||
void testInsertEmptyVector();
|
||||
|
||||
void testInsertSingleBulk();
|
||||
void testInsertSingleBulkVec();
|
||||
|
||||
void testLimit();
|
||||
void testLimitOnce();
|
||||
void testLimitPrepare();
|
||||
void testLimitZero();
|
||||
void testPrepare();
|
||||
|
||||
void testSetSimple();
|
||||
void testSetComplex();
|
||||
void testSetComplexUnique();
|
||||
void testMultiSetSimple();
|
||||
void testMultiSetComplex();
|
||||
void testMapComplex();
|
||||
void testMapComplexUnique();
|
||||
void testMultiMapComplex();
|
||||
void testSelectIntoSingle();
|
||||
void testSelectIntoSingleStep();
|
||||
void testSelectIntoSingleFail();
|
||||
void testLowerLimitOk();
|
||||
void testLowerLimitFail();
|
||||
void testCombinedLimits();
|
||||
void testCombinedIllegalLimits();
|
||||
void testRange();
|
||||
void testIllegalRange();
|
||||
void testSingleSelect();
|
||||
void testEmptyDB();
|
||||
|
||||
void testBLOB();
|
||||
void testBLOBStmt();
|
||||
|
||||
void testFloat();
|
||||
void testDouble();
|
||||
|
||||
void testTuple();
|
||||
void testTupleVector();
|
||||
|
||||
void testInternalExtraction();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreateStringsTable();
|
||||
void recreateIntsTable();
|
||||
void recreateFloatsTable();
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
static const bool bindValues[8];
|
||||
};
|
||||
|
||||
|
||||
#endif // ODBCDB2Test_INCLUDED
|
945
Data/ODBC/testsuite/src/ODBCMySQLTest.cpp
Normal file
945
Data/ODBC/testsuite/src/ODBCMySQLTest.cpp
Normal file
@ -0,0 +1,945 @@
|
||||
//
|
||||
// ODBCMySQLTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCMySQLTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ODBCMySQLTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/ODBC/SessionInstantiator.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include <sqltypes.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
using Poco::Data::ODBC::Utility;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using Poco::Data::ODBC::StatementDiagnostics;
|
||||
using Poco::format;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
const bool ODBCMySQLTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCMySQLTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCMySQLTest::_pExecutor = 0;
|
||||
std::string ODBCMySQLTest::_dsn = "PocoDataMySQLTest";
|
||||
std::string ODBCMySQLTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCMySQLTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCMySQLTest::_dataSources;
|
||||
|
||||
|
||||
ODBCMySQLTest::ODBCMySQLTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
ODBC::SessionInstantiator::addToFactory();
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::SessionInstantiator::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. MySQL tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor) _pExecutor = new SQLExecutor("MySQL SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. MySQL tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
ODBCMySQLTest::~ODBCMySQLTest()
|
||||
{
|
||||
ODBC::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testBareboneODBC()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableCreateString = "CREATE TABLE Test "
|
||||
"(First VARCHAR(30),"
|
||||
"Second VARCHAR(30),"
|
||||
"Third VARBINARY(30),"
|
||||
"Fourth INTEGER,"
|
||||
"Fifth FLOAT)";
|
||||
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSimpleAccess()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
int count = 0;
|
||||
|
||||
//recreatePersonTable();
|
||||
|
||||
//try { *_pSession << "SELECT count(*) FROM sys.tables WHERE name = 'Person'", into(count), use(tableName), now; }
|
||||
//catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
//catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
|
||||
//assert (1 == count);
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccess();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testComplexType()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexType();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSimpleAccessVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccessVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testComplexTypeVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexTypeVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testInsertVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testInsertEmptyVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertEmptyVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testInsertSingleBulk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testInsertSingleBulkVec()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulkVec();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testLimit()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testLimitZero()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitZero();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testLimitOnce()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
recreateIntsTable();
|
||||
_pExecutor->limitOnce();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testLimitPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitPrepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCMySQLTest::testPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->prepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSetComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void ODBCMySQLTest::testMultiSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testMultiSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testMapComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testMultiMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiMapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSelectIntoSingle()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingle();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSelectIntoSingleStep()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleStep();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSelectIntoSingleFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testLowerLimitOk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitOk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testSingleSelect()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->singleSelect();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testLowerLimitFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testCombinedLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCMySQLTest::testRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->ranges();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testCombinedIllegalLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedIllegalLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCMySQLTest::testIllegalRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->illegalRange();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testEmptyDB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->emptyDB();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testBLOB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
const std::size_t maxFldSize = 65534;
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
|
||||
recreatePersonBLOBTable();
|
||||
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&)
|
||||
{
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blob(maxFldSize);
|
||||
i += 2;
|
||||
}
|
||||
|
||||
recreatePersonBLOBTable();
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize+1);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&) { }
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testBLOBStmt()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blobStmt();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testFloat()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->floats();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testDouble()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->doubles();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testTuple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tuples();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testTupleVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tupleVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::testInternalExtraction()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateVectorsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->internalExtraction();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::dropTable(const std::string& tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
*_pSession << format("DROP TABLE %s", tableName), now;
|
||||
}
|
||||
catch (StatementException& ex)
|
||||
{
|
||||
bool ignoreError = false;
|
||||
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
|
||||
StatementDiagnostics::Iterator it = flds.begin();
|
||||
for (; it != flds.end(); ++it)
|
||||
{
|
||||
if (1051 == it->_nativeError)//(table does not exist)
|
||||
{
|
||||
ignoreError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreError) throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::recreatePersonTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::recreatePersonBLOBTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::recreateIntsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::recreateStringsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::recreateFloatsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::recreateTuplesTable()
|
||||
{
|
||||
dropTable("Tuples");
|
||||
try { *_pSession << "CREATE TABLE Tuples "
|
||||
"(i0 INTEGER, i1 INTEGER, i2 INTEGER, i3 INTEGER, i4 INTEGER, i5 INTEGER, i6 INTEGER, "
|
||||
"i7 INTEGER, i8 INTEGER, i9 INTEGER, i10 INTEGER, i11 INTEGER, i12 INTEGER, i13 INTEGER,"
|
||||
"i14 INTEGER, i15 INTEGER, i16 INTEGER, i17 INTEGER, i18 INTEGER, i19 INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::recreateVectorsTable()
|
||||
{
|
||||
dropTable("Vectors");
|
||||
try { *_pSession << "CREATE TABLE Vectors (i0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::checkODBCSetup()
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("MySQL") != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
{
|
||||
std::cout << "MySQL driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("MySQL") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "SQL Server DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;", _dsn);
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ODBCMySQLTest::tearDown()
|
||||
{
|
||||
dropTable("Person");
|
||||
dropTable("Strings");
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCMySQLTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCMySQLTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testBareboneODBC);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccess);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexType);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSimpleAccessVector);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testComplexTypeVector);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertVector);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertEmptyVector);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulk);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testInsertSingleBulkVec);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimit);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitOnce);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testLimitZero);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSetComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testMapComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testMultiMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingle);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleStep);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSelectIntoSingleFail);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitOk);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testLowerLimitFail);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedLimits);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testCombinedIllegalLimits);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testRange);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testIllegalRange);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testSingleSelect);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testEmptyDB);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOB);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testBLOBStmt);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testFloat);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testDouble);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testTuple);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testTupleVector);
|
||||
CppUnit_addTest(pSuite, ODBCMySQLTest, testInternalExtraction);
|
||||
|
||||
return pSuite;
|
||||
}
|
136
Data/ODBC/testsuite/src/ODBCMySQLTest.h
Normal file
136
Data/ODBC/testsuite/src/ODBCMySQLTest.h
Normal file
@ -0,0 +1,136 @@
|
||||
//
|
||||
// ODBCMySQLTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCMySQLTest.h#2 $
|
||||
//
|
||||
// Definition of the ODBCMySQLTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBCMySQLTest_INCLUDED
|
||||
#define ODBCMySQLTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "SQLExecutor.h"
|
||||
|
||||
|
||||
class ODBCMySQLTest: public CppUnit::TestCase
|
||||
/// MySQL ODBC test class
|
||||
/// Tested:
|
||||
///
|
||||
/// Driver | DB | OS
|
||||
/// ----------------+---------------------------+------------------------------------------
|
||||
/// 03.51.12.00 | MySQL 5.0.27-community-nt | MS Windows XP Professional x64 v.2003/SP1
|
||||
///
|
||||
|
||||
{
|
||||
public:
|
||||
ODBCMySQLTest(const std::string& name);
|
||||
~ODBCMySQLTest();
|
||||
|
||||
void testBareboneODBC();
|
||||
|
||||
void testSimpleAccess();
|
||||
void testComplexType();
|
||||
void testSimpleAccessVector();
|
||||
void testComplexTypeVector();
|
||||
void testInsertVector();
|
||||
void testInsertEmptyVector();
|
||||
|
||||
void testInsertSingleBulk();
|
||||
void testInsertSingleBulkVec();
|
||||
|
||||
void testLimit();
|
||||
void testLimitOnce();
|
||||
void testLimitPrepare();
|
||||
void testLimitZero();
|
||||
void testPrepare();
|
||||
|
||||
void testSetSimple();
|
||||
void testSetComplex();
|
||||
void testSetComplexUnique();
|
||||
void testMultiSetSimple();
|
||||
void testMultiSetComplex();
|
||||
void testMapComplex();
|
||||
void testMapComplexUnique();
|
||||
void testMultiMapComplex();
|
||||
void testSelectIntoSingle();
|
||||
void testSelectIntoSingleStep();
|
||||
void testSelectIntoSingleFail();
|
||||
void testLowerLimitOk();
|
||||
void testLowerLimitFail();
|
||||
void testCombinedLimits();
|
||||
void testCombinedIllegalLimits();
|
||||
void testRange();
|
||||
void testIllegalRange();
|
||||
void testSingleSelect();
|
||||
void testEmptyDB();
|
||||
|
||||
void testBLOB();
|
||||
void testBLOBStmt();
|
||||
|
||||
void testFloat();
|
||||
void testDouble();
|
||||
|
||||
void testTuple();
|
||||
void testTupleVector();
|
||||
|
||||
void testInternalExtraction();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreateStringsTable();
|
||||
void recreateIntsTable();
|
||||
void recreateFloatsTable();
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
static const bool bindValues[8];
|
||||
};
|
||||
|
||||
|
||||
#endif // ODBCMySQLTest_INCLUDED
|
944
Data/ODBC/testsuite/src/ODBCOracleTest.cpp
Normal file
944
Data/ODBC/testsuite/src/ODBCOracleTest.cpp
Normal file
@ -0,0 +1,944 @@
|
||||
//
|
||||
// ODBCOracleTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCOracleTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ODBCOracleTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/ODBC/SessionInstantiator.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include <sqltypes.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
using Poco::Data::ODBC::Utility;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using Poco::Data::ODBC::StatementDiagnostics;
|
||||
using Poco::format;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
const bool ODBCOracleTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCOracleTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCOracleTest::_pExecutor = 0;
|
||||
std::string ODBCOracleTest::_dsn = "PocoDataOracleTest";
|
||||
std::string ODBCOracleTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCOracleTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCOracleTest::_dataSources;
|
||||
|
||||
|
||||
ODBCOracleTest::ODBCOracleTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
ODBC::SessionInstantiator::addToFactory();
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::SessionInstantiator::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. Oracle tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor) _pExecutor = new SQLExecutor("Oracle SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. Oracle tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
ODBCOracleTest::~ODBCOracleTest()
|
||||
{
|
||||
ODBC::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testBareboneODBC()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableCreateString = "CREATE TABLE Test "
|
||||
"(First VARCHAR(30),"
|
||||
"Second VARCHAR(30),"
|
||||
"Third BLOB,"
|
||||
"Fourth INTEGER,"
|
||||
"Fifth NUMBER)";
|
||||
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSimpleAccess()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableName("Person");
|
||||
int count = 0;
|
||||
|
||||
recreatePersonTable();
|
||||
|
||||
*_pSession << "SELECT count(*) FROM sys.all_all_tables WHERE table_name = upper(?)", into(count), use(tableName), now;
|
||||
assert (1 == count);
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccess();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testComplexType()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexType();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSimpleAccessVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccessVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testComplexTypeVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexTypeVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testInsertVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testInsertEmptyVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertEmptyVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testInsertSingleBulk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testInsertSingleBulkVec()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulkVec();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testLimit()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testLimitZero()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitZero();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testLimitOnce()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
recreateIntsTable();
|
||||
_pExecutor->limitOnce();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testLimitPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitPrepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCOracleTest::testPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->prepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSetComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void ODBCOracleTest::testMultiSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testMultiSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testMapComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testMultiMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiMapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSelectIntoSingle()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingle();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSelectIntoSingleStep()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleStep();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSelectIntoSingleFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testLowerLimitOk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitOk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testSingleSelect()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->singleSelect();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testLowerLimitFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testCombinedLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCOracleTest::testRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->ranges();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testCombinedIllegalLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedIllegalLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCOracleTest::testIllegalRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->illegalRange();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testEmptyDB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->emptyDB();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testBLOB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
const std::size_t maxFldSize = 1000000;
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
|
||||
recreatePersonBLOBTable();
|
||||
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&)
|
||||
{
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blob(maxFldSize);
|
||||
i += 2;
|
||||
}
|
||||
|
||||
recreatePersonBLOBTable();
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize+1);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&) { }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testBLOBStmt()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blobStmt();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testFloat()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->floats();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testDouble()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->doubles();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testTuple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tuples();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testTupleVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tupleVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::testInternalExtraction()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateVectorsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->internalExtraction();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::dropTable(const std::string& tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
*_pSession << format("DROP TABLE %s", tableName), now;
|
||||
}
|
||||
catch (StatementException& ex)
|
||||
{
|
||||
bool ignoreError = false;
|
||||
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
|
||||
StatementDiagnostics::Iterator it = flds.begin();
|
||||
for (; it != flds.end(); ++it)
|
||||
{
|
||||
if (942 == it->_nativeError)//ORA-00942 (table does not exist)
|
||||
{
|
||||
ignoreError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreError) throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreatePersonTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR2(30), FirstName VARCHAR2(30), Address VARCHAR2(30), Age INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreatePersonBLOBTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreateIntsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreateStringsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreateFloatsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str NUMBER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreateTuplesTable()
|
||||
{
|
||||
dropTable("Tuples");
|
||||
try { *_pSession << "CREATE TABLE Tuples "
|
||||
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
|
||||
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
|
||||
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::recreateVectorsTable()
|
||||
{
|
||||
dropTable("Vectors");
|
||||
try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 NUMBER, str0 VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::checkODBCSetup()
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("Oracle") != std::string::npos) &&
|
||||
((itDrv->first).find("Microsoft") == std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
{
|
||||
std::cout << "Oracle driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("Oracle") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "Oracle DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;Uid=Scott;Pwd=Tiger;", _dsn);
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ODBCOracleTest::tearDown()
|
||||
{
|
||||
dropTable("Person");
|
||||
dropTable("Strings");
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCOracleTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCOracleTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testBareboneODBC);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccess);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexType);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSimpleAccessVector);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testComplexTypeVector);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertVector);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertEmptyVector);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertSingleBulk);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testInsertSingleBulkVec);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testLimit);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testLimitOnce);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testLimitPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testLimitZero);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSetComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testMultiSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testMultiSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testMapComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testMultiMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingle);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingleStep);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSelectIntoSingleFail);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testLowerLimitOk);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testLowerLimitFail);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testCombinedLimits);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testCombinedIllegalLimits);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testRange);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testIllegalRange);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testSingleSelect);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testEmptyDB);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testBLOB);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testBLOBStmt);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testFloat);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testDouble);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testTuple);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testTupleVector);
|
||||
CppUnit_addTest(pSuite, ODBCOracleTest, testInternalExtraction);
|
||||
|
||||
return pSuite;
|
||||
}
|
135
Data/ODBC/testsuite/src/ODBCOracleTest.h
Normal file
135
Data/ODBC/testsuite/src/ODBCOracleTest.h
Normal file
@ -0,0 +1,135 @@
|
||||
//
|
||||
// ODBCOracleTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCOracleTest.h#2 $
|
||||
//
|
||||
// Definition of the ODBCOracleTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBCOracleTest_INCLUDED
|
||||
#define ODBCOracleTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "SQLExecutor.h"
|
||||
|
||||
|
||||
class ODBCOracleTest: public CppUnit::TestCase
|
||||
/// Oracle ODBC test class
|
||||
/// Tested:
|
||||
///
|
||||
/// Driver | DB | OS
|
||||
/// ------------+-------------------------------+------------------------------------------
|
||||
/// 10.02.00.01 | Oracle9i Release 9.2.0.4.0 | MS Windows XP Professional x64 v.2003/SP1
|
||||
/// 10.02.00.01 | Oracle XE Release 10.2.0.1.0 | MS Windows XP Professional x64 v.2003/SP1
|
||||
{
|
||||
public:
|
||||
ODBCOracleTest(const std::string& name);
|
||||
~ODBCOracleTest();
|
||||
|
||||
void testBareboneODBC();
|
||||
|
||||
void testSimpleAccess();
|
||||
void testComplexType();
|
||||
void testSimpleAccessVector();
|
||||
void testComplexTypeVector();
|
||||
void testInsertVector();
|
||||
void testInsertEmptyVector();
|
||||
|
||||
void testInsertSingleBulk();
|
||||
void testInsertSingleBulkVec();
|
||||
|
||||
void testLimit();
|
||||
void testLimitOnce();
|
||||
void testLimitPrepare();
|
||||
void testLimitZero();
|
||||
void testPrepare();
|
||||
|
||||
void testSetSimple();
|
||||
void testSetComplex();
|
||||
void testSetComplexUnique();
|
||||
void testMultiSetSimple();
|
||||
void testMultiSetComplex();
|
||||
void testMapComplex();
|
||||
void testMapComplexUnique();
|
||||
void testMultiMapComplex();
|
||||
void testSelectIntoSingle();
|
||||
void testSelectIntoSingleStep();
|
||||
void testSelectIntoSingleFail();
|
||||
void testLowerLimitOk();
|
||||
void testLowerLimitFail();
|
||||
void testCombinedLimits();
|
||||
void testCombinedIllegalLimits();
|
||||
void testRange();
|
||||
void testIllegalRange();
|
||||
void testSingleSelect();
|
||||
void testEmptyDB();
|
||||
|
||||
void testBLOB();
|
||||
void testBLOBStmt();
|
||||
|
||||
void testFloat();
|
||||
void testDouble();
|
||||
|
||||
void testTuple();
|
||||
void testTupleVector();
|
||||
|
||||
void testInternalExtraction();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreateStringsTable();
|
||||
void recreateIntsTable();
|
||||
void recreateFloatsTable();
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
static const bool bindValues[8];
|
||||
};
|
||||
|
||||
|
||||
#endif // ODBCOracleTest_INCLUDED
|
935
Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp
Normal file
935
Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp
Normal file
@ -0,0 +1,935 @@
|
||||
//
|
||||
// ODBCPostgreSQLTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCPostgreSQLTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ODBCPostgreSQLTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/ODBC/SessionInstantiator.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include <sqltypes.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
using Poco::Data::ODBC::Utility;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using Poco::Data::ODBC::StatementDiagnostics;
|
||||
using Poco::format;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
const bool ODBCPostgreSQLTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCPostgreSQLTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCPostgreSQLTest::_pExecutor = 0;
|
||||
std::string ODBCPostgreSQLTest::_dsn = "PocoDataPgSQLTest";
|
||||
std::string ODBCPostgreSQLTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCPostgreSQLTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCPostgreSQLTest::_dataSources;
|
||||
|
||||
|
||||
ODBCPostgreSQLTest::ODBCPostgreSQLTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
ODBC::SessionInstantiator::addToFactory();
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::SessionInstantiator::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. PostgreSQL tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor) _pExecutor = new SQLExecutor("PostgreSQL SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. PostgreSQL tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
ODBCPostgreSQLTest::~ODBCPostgreSQLTest()
|
||||
{
|
||||
ODBC::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testBareboneODBC()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableCreateString = "CREATE TABLE Test "
|
||||
"(First VARCHAR(30),"
|
||||
"Second VARCHAR(30),"
|
||||
"Third BYTEA,"
|
||||
"Fourth INTEGER,"
|
||||
"Fifth FLOAT)";
|
||||
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSimpleAccess()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableName("Person");
|
||||
int count = 0;
|
||||
|
||||
recreatePersonTable();
|
||||
|
||||
//*_pSession << "SELECT count(*) FROM sys.all_all_tables WHERE table_name = upper(?)", into(count), use(tableName), now;
|
||||
//assert (1 == count);
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccess();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testComplexType()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexType();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSimpleAccessVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccessVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testComplexTypeVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexTypeVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testInsertVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testInsertEmptyVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertEmptyVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testInsertSingleBulk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testInsertSingleBulkVec()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulkVec();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testLimit()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testLimitZero()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitZero();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testLimitOnce()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
recreateIntsTable();
|
||||
_pExecutor->limitOnce();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testLimitPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitPrepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->prepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSetComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void ODBCPostgreSQLTest::testMultiSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testMultiSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testMapComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testMultiMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiMapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSelectIntoSingle()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingle();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSelectIntoSingleStep()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleStep();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSelectIntoSingleFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testLowerLimitOk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitOk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testSingleSelect()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->singleSelect();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testLowerLimitFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testCombinedLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->ranges();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testCombinedIllegalLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedIllegalLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testIllegalRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->illegalRange();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testEmptyDB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->emptyDB();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testBLOB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
const std::size_t maxFldSize = 1000000;
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
|
||||
recreatePersonBLOBTable();
|
||||
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&)
|
||||
{
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blob(1000000);
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testBLOBStmt()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blobStmt();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testFloat()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->floats();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testDouble()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->doubles();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testTuple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tuples();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testTupleVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tupleVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::testInternalExtraction()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateVectorsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->internalExtraction();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::dropTable(const std::string& tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
*_pSession << format("DROP TABLE %s", tableName), now;
|
||||
}
|
||||
catch (StatementException& ex)
|
||||
{
|
||||
bool ignoreError = false;
|
||||
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
|
||||
StatementDiagnostics::Iterator it = flds.begin();
|
||||
for (; it != flds.end(); ++it)
|
||||
{
|
||||
if (7 == it->_nativeError)//(table does not exist)
|
||||
{
|
||||
ignoreError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreError) throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreatePersonTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreatePersonBLOBTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BYTEA)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreateIntsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreateStringsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreateFloatsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreateTuplesTable()
|
||||
{
|
||||
dropTable("Tuples");
|
||||
try { *_pSession << "CREATE TABLE Tuples "
|
||||
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
|
||||
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
|
||||
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::recreateVectorsTable()
|
||||
{
|
||||
dropTable("Vectors");
|
||||
try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::checkODBCSetup()
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("PostgreSQL") != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
{
|
||||
std::cout << "PostgreSQL driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
((itDSN->second).find("PostgreSQL") != std::string::npos))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "PostgreSQL DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;", _dsn);
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ODBCPostgreSQLTest::tearDown()
|
||||
{
|
||||
dropTable("Person");
|
||||
dropTable("Strings");
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCPostgreSQLTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCPostgreSQLTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBareboneODBC);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccess);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexType);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSimpleAccessVector);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testComplexTypeVector);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertVector);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertEmptyVector);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulk);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInsertSingleBulkVec);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimit);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitOnce);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLimitZero);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSetComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMapComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testMultiMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingle);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleStep);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSelectIntoSingleFail);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitOk);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testLowerLimitFail);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedLimits);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testCombinedIllegalLimits);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testRange);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testIllegalRange);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testSingleSelect);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testEmptyDB);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOB);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testBLOBStmt);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testFloat);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testDouble);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTuple);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testTupleVector);
|
||||
CppUnit_addTest(pSuite, ODBCPostgreSQLTest, testInternalExtraction);
|
||||
|
||||
return pSuite;
|
||||
}
|
136
Data/ODBC/testsuite/src/ODBCPostgreSQLTest.h
Normal file
136
Data/ODBC/testsuite/src/ODBCPostgreSQLTest.h
Normal file
@ -0,0 +1,136 @@
|
||||
//
|
||||
// ODBCPostgreSQLTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCPostgreSQLTest.h#2 $
|
||||
//
|
||||
// Definition of the ODBCPostgreSQLTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBCPostgreSQLTest_INCLUDED
|
||||
#define ODBCPostgreSQLTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "SQLExecutor.h"
|
||||
|
||||
|
||||
class ODBCPostgreSQLTest: public CppUnit::TestCase
|
||||
/// PostgreSQL ODBC test class
|
||||
/// Tested:
|
||||
///
|
||||
/// Driver | DB | OS | Notes
|
||||
/// ------------+-------------------+-------------------------------------------+--------------------------------
|
||||
/// 07.03.02.60 | PostgreSQL 7.4.6 | MS Windows XP Professional x64 v.2003/SP1 | BLOB fails (missing 'lo' module)
|
||||
/// 08.01.02.00 | PostgreSQL 8.1.5-1| MS Windows XP Professional x64 v.2003/SP1 |
|
||||
///
|
||||
{
|
||||
public:
|
||||
ODBCPostgreSQLTest(const std::string& name);
|
||||
~ODBCPostgreSQLTest();
|
||||
|
||||
void testBareboneODBC();
|
||||
|
||||
void testSimpleAccess();
|
||||
void testComplexType();
|
||||
void testSimpleAccessVector();
|
||||
void testComplexTypeVector();
|
||||
void testInsertVector();
|
||||
void testInsertEmptyVector();
|
||||
|
||||
void testInsertSingleBulk();
|
||||
void testInsertSingleBulkVec();
|
||||
|
||||
void testLimit();
|
||||
void testLimitOnce();
|
||||
void testLimitPrepare();
|
||||
void testLimitZero();
|
||||
void testPrepare();
|
||||
|
||||
void testSetSimple();
|
||||
void testSetComplex();
|
||||
void testSetComplexUnique();
|
||||
void testMultiSetSimple();
|
||||
void testMultiSetComplex();
|
||||
void testMapComplex();
|
||||
void testMapComplexUnique();
|
||||
void testMultiMapComplex();
|
||||
void testSelectIntoSingle();
|
||||
void testSelectIntoSingleStep();
|
||||
void testSelectIntoSingleFail();
|
||||
void testLowerLimitOk();
|
||||
void testLowerLimitFail();
|
||||
void testCombinedLimits();
|
||||
void testCombinedIllegalLimits();
|
||||
void testRange();
|
||||
void testIllegalRange();
|
||||
void testSingleSelect();
|
||||
void testEmptyDB();
|
||||
|
||||
void testBLOB();
|
||||
void testBLOBStmt();
|
||||
|
||||
void testFloat();
|
||||
void testDouble();
|
||||
|
||||
void testTuple();
|
||||
void testTupleVector();
|
||||
|
||||
void testInternalExtraction();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreateStringsTable();
|
||||
void recreateIntsTable();
|
||||
void recreateFloatsTable();
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
static const bool bindValues[8];
|
||||
};
|
||||
|
||||
|
||||
#endif // ODBCPostgreSQLTest_INCLUDED
|
956
Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp
Normal file
956
Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp
Normal file
@ -0,0 +1,956 @@
|
||||
//
|
||||
// ODBCSQLServerTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCSQLServerTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ODBCSQLServerTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/ODBC/SessionInstantiator.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include <sqltypes.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
using Poco::Data::ODBC::Utility;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using Poco::Data::ODBC::StatementDiagnostics;
|
||||
using Poco::format;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
const bool ODBCSQLServerTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCSQLServerTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCSQLServerTest::_pExecutor = 0;
|
||||
std::string ODBCSQLServerTest::_dsn = "PocoDataSQLServerTest";
|
||||
std::string ODBCSQLServerTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCSQLServerTest::_drivers;
|
||||
Poco::Data::ODBC::Utility::DSNMap ODBCSQLServerTest::_dataSources;
|
||||
|
||||
|
||||
ODBCSQLServerTest::ODBCSQLServerTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
ODBC::SessionInstantiator::addToFactory();
|
||||
if (_drivers.empty() || _dataSources.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
Utility::dataSources(_dataSources);
|
||||
checkODBCSetup();
|
||||
}
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::SessionInstantiator::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. SQL Server tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dsn << '(' << _dbConnString << ')' << std::endl;
|
||||
if (!_pExecutor) _pExecutor = new SQLExecutor("SQLServer SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. SQL Server tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
ODBCSQLServerTest::~ODBCSQLServerTest()
|
||||
{
|
||||
ODBC::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testBareboneODBC()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableCreateString = "CREATE TABLE Test "
|
||||
"(First VARCHAR(30),"
|
||||
"Second VARCHAR(30),"
|
||||
"Third VARBINARY(30),"
|
||||
"Fourth INTEGER,"
|
||||
"Fifth FLOAT)";
|
||||
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSimpleAccess()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableName("Person");
|
||||
int count = 0;
|
||||
|
||||
recreatePersonTable();
|
||||
|
||||
try { *_pSession << "SELECT count(*) FROM sys.tables WHERE name = 'Person'", into(count), use(tableName), now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("testSimpleAccess()"); }
|
||||
|
||||
assert (1 == count);
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccess();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testComplexType()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexType();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSimpleAccessVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccessVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testComplexTypeVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexTypeVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testInsertVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testInsertEmptyVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertEmptyVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testInsertSingleBulk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testInsertSingleBulkVec()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulkVec();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testLimit()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testLimitZero()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitZero();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testLimitOnce()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
recreateIntsTable();
|
||||
_pExecutor->limitOnce();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testLimitPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitPrepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->prepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSetComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void ODBCSQLServerTest::testMultiSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testMultiSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testMapComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testMultiMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiMapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSelectIntoSingle()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingle();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSelectIntoSingleStep()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleStep();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSelectIntoSingleFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testLowerLimitOk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitOk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testSingleSelect()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->singleSelect();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testLowerLimitFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testCombinedLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->ranges();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testCombinedIllegalLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedIllegalLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testIllegalRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->illegalRange();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testEmptyDB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->emptyDB();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testBLOB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
const std::size_t maxFldSize = 250000;
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize-1));
|
||||
recreatePersonBLOBTable();
|
||||
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&)
|
||||
{
|
||||
_pSession->setProperty("maxFieldSize", Poco::Any(maxFldSize));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blob(maxFldSize);
|
||||
i += 2;
|
||||
}
|
||||
|
||||
recreatePersonBLOBTable();
|
||||
try
|
||||
{
|
||||
_pExecutor->blob(maxFldSize+1);
|
||||
fail ("must fail");
|
||||
}
|
||||
catch (DataException&) { }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testBLOBStmt()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blobStmt();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testFloat()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->floats();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testDouble()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->doubles();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testTuple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tuples();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testTupleVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tupleVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::testInternalExtraction()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateVectorsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->internalExtraction();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::dropTable(const std::string& tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
*_pSession << format("DROP TABLE %s", tableName), now;
|
||||
}
|
||||
catch (StatementException& ex)
|
||||
{
|
||||
bool ignoreError = false;
|
||||
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
|
||||
StatementDiagnostics::Iterator it = flds.begin();
|
||||
for (; it != flds.end(); ++it)
|
||||
{
|
||||
if (3701 == it->_nativeError)//(table does not exist)
|
||||
{
|
||||
ignoreError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreError) throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::recreatePersonTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Age INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::recreatePersonBLOBTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image VARBINARY(MAX))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::recreateIntsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::recreateStringsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::recreateFloatsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str FLOAT)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::recreateTuplesTable()
|
||||
{
|
||||
dropTable("Tuples");
|
||||
try { *_pSession << "CREATE TABLE Tuples "
|
||||
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
|
||||
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
|
||||
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::recreateVectorTable()
|
||||
{
|
||||
dropTable("Vector");
|
||||
try { *_pSession << "CREATE TABLE Vector (i0 INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::recreateVectorsTable()
|
||||
{
|
||||
dropTable("Vectors");
|
||||
try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 FLOAT, str0 VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::checkODBCSetup()
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
|
||||
bool driverFound = false;
|
||||
bool dsnFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDrv = _drivers.begin();
|
||||
for (; itDrv != _drivers.end(); ++itDrv)
|
||||
{
|
||||
if (((itDrv->first).find("SQL Server") != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDrv->first
|
||||
<< " (" << itDrv->second << ')' << std::endl;
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
{
|
||||
std::cout << "SQL Server driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Utility::DSNMap::iterator itDSN = _dataSources.begin();
|
||||
for (; itDSN != _dataSources.end(); ++itDSN)
|
||||
{
|
||||
if (((itDSN->first).find(_dsn) != std::string::npos) &&
|
||||
(((itDSN->second).find("SQL Server") != std::string::npos) ||
|
||||
((itDSN->second).find("SQL Native Client") != std::string::npos)))
|
||||
{
|
||||
std::cout << "DSN found: " << itDSN->first
|
||||
<< " (" << itDSN->second << ')' << std::endl;
|
||||
dsnFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dsnFound)
|
||||
{
|
||||
std::cout << "SQL Server DSN NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
format(_dbConnString, "DSN=%s;Uid=test;Pwd=test;", _dsn);
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLServerTest::tearDown()
|
||||
{
|
||||
dropTable("Person");
|
||||
dropTable("Strings");
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCSQLServerTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLServerTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBareboneODBC);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccess);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexType);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSimpleAccessVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testComplexTypeVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertEmptyVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertSingleBulk);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInsertSingleBulkVec);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimit);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitOnce);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLimitZero);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSetComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMapComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testMultiMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingle);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingleStep);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSelectIntoSingleFail);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLowerLimitOk);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testLowerLimitFail);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testCombinedLimits);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testCombinedIllegalLimits);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testRange);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testIllegalRange);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testSingleSelect);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testEmptyDB);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBLOB);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testBLOBStmt);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testFloat);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testDouble);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTuple);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testTupleVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLServerTest, testInternalExtraction);
|
||||
|
||||
return pSuite;
|
||||
}
|
138
Data/ODBC/testsuite/src/ODBCSQLServerTest.h
Normal file
138
Data/ODBC/testsuite/src/ODBCSQLServerTest.h
Normal file
@ -0,0 +1,138 @@
|
||||
//
|
||||
// ODBCSQLServerTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCSQLServerTest.h#2 $
|
||||
//
|
||||
// Definition of the ODBCSQLServerTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBCSQLServerTest_INCLUDED
|
||||
#define ODBCSQLServerTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "SQLExecutor.h"
|
||||
|
||||
|
||||
class ODBCSQLServerTest: public CppUnit::TestCase
|
||||
/// SQLServer ODBC test class
|
||||
/// Tested:
|
||||
///
|
||||
/// Driver | DB | OS
|
||||
/// ----------------+-------------------------------+------------------------------------------
|
||||
/// 2000.86.1830.00 | SQL Server Express 9.0.2047 | MS Windows XP Professional x64 v.2003/SP1
|
||||
/// 2005.90.2047.00 | SQL Server Express 9.0.2047 | MS Windows XP Professional x64 v.2003/SP1
|
||||
///
|
||||
|
||||
{
|
||||
public:
|
||||
ODBCSQLServerTest(const std::string& name);
|
||||
~ODBCSQLServerTest();
|
||||
|
||||
void testBareboneODBC();
|
||||
|
||||
void testSimpleAccess();
|
||||
void testComplexType();
|
||||
void testSimpleAccessVector();
|
||||
void testComplexTypeVector();
|
||||
void testInsertVector();
|
||||
void testInsertEmptyVector();
|
||||
|
||||
void testInsertSingleBulk();
|
||||
void testInsertSingleBulkVec();
|
||||
|
||||
void testLimit();
|
||||
void testLimitOnce();
|
||||
void testLimitPrepare();
|
||||
void testLimitZero();
|
||||
void testPrepare();
|
||||
|
||||
void testSetSimple();
|
||||
void testSetComplex();
|
||||
void testSetComplexUnique();
|
||||
void testMultiSetSimple();
|
||||
void testMultiSetComplex();
|
||||
void testMapComplex();
|
||||
void testMapComplexUnique();
|
||||
void testMultiMapComplex();
|
||||
void testSelectIntoSingle();
|
||||
void testSelectIntoSingleStep();
|
||||
void testSelectIntoSingleFail();
|
||||
void testLowerLimitOk();
|
||||
void testLowerLimitFail();
|
||||
void testCombinedLimits();
|
||||
void testCombinedIllegalLimits();
|
||||
void testRange();
|
||||
void testIllegalRange();
|
||||
void testSingleSelect();
|
||||
void testEmptyDB();
|
||||
|
||||
void testBLOB();
|
||||
void testBLOBStmt();
|
||||
|
||||
void testFloat();
|
||||
void testDouble();
|
||||
|
||||
void testTuple();
|
||||
void testTupleVector();
|
||||
|
||||
void testInternalExtraction();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreateStringsTable();
|
||||
void recreateIntsTable();
|
||||
void recreateFloatsTable();
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static Poco::Data::ODBC::Utility::DSNMap _dataSources;
|
||||
static std::string _dsn;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
static const bool bindValues[8];
|
||||
};
|
||||
|
||||
|
||||
#endif // ODBCSQLServerTest_INCLUDED
|
902
Data/ODBC/testsuite/src/ODBCSQLiteTest.cpp
Normal file
902
Data/ODBC/testsuite/src/ODBCSQLiteTest.cpp
Normal file
@ -0,0 +1,902 @@
|
||||
//
|
||||
// ODBCSQLiteTest.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCSQLiteTest.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ODBCSQLiteTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Format.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/ODBC/SessionInstantiator.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/Data/ODBC/Diagnostics.h"
|
||||
#include "Poco/Data/ODBC/ODBCException.h"
|
||||
#include "Poco/Data/ODBC/ODBCStatementImpl.h"
|
||||
#include <sqltypes.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
using namespace Poco::Data;
|
||||
using Poco::Data::ODBC::Utility;
|
||||
using Poco::Data::ODBC::ConnectionException;
|
||||
using Poco::Data::ODBC::StatementException;
|
||||
using Poco::Data::ODBC::StatementDiagnostics;
|
||||
using Poco::format;
|
||||
using Poco::NotFoundException;
|
||||
|
||||
|
||||
const bool ODBCSQLiteTest::bindValues[8] = {true, true, true, false, false, true, false, false};
|
||||
Poco::SharedPtr<Poco::Data::Session> ODBCSQLiteTest::_pSession = 0;
|
||||
Poco::SharedPtr<SQLExecutor> ODBCSQLiteTest::_pExecutor = 0;
|
||||
std::string ODBCSQLiteTest::_dbConnString;
|
||||
Poco::Data::ODBC::Utility::DriverMap ODBCSQLiteTest::_drivers;
|
||||
|
||||
|
||||
ODBCSQLiteTest::ODBCSQLiteTest(const std::string& name):
|
||||
CppUnit::TestCase(name)
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
ODBC::SessionInstantiator::addToFactory();
|
||||
if (_drivers.empty())
|
||||
{
|
||||
Utility::drivers(_drivers);
|
||||
checkODBCSetup();
|
||||
}
|
||||
if (!_pSession && !_dbConnString.empty() && !beenHere)
|
||||
{
|
||||
try
|
||||
{
|
||||
_pSession = new Session(SessionFactory::instance().create(ODBC::SessionInstantiator::KEY, _dbConnString));
|
||||
}catch (ConnectionException& ex)
|
||||
{
|
||||
std::cout << "!!! WARNING: Connection failed. SQLite tests will fail !!!" << std::endl;
|
||||
std::cout << ex.toString() << std::endl;
|
||||
}
|
||||
|
||||
if (_pSession && _pSession->isConnected())
|
||||
std::cout << "*** Connected to " << _dbConnString << std::endl;
|
||||
if (!_pExecutor) _pExecutor = new SQLExecutor("SQLite SQL Executor", _pSession);
|
||||
}
|
||||
else
|
||||
if (!_pSession && !beenHere)
|
||||
std::cout << "!!! WARNING: No driver or DSN found. SQLite tests will fail !!!" << std::endl;
|
||||
|
||||
beenHere = true;
|
||||
}
|
||||
|
||||
|
||||
ODBCSQLiteTest::~ODBCSQLiteTest()
|
||||
{
|
||||
ODBC::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testBareboneODBC()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableCreateString = "CREATE TABLE Test "
|
||||
"(First VARCHAR(30),"
|
||||
"Second VARCHAR(30),"
|
||||
"Third BLOB,"
|
||||
"Fourth INTEGER,"
|
||||
"Fifth REAL)";
|
||||
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_IMMEDIATE, SQLExecutor::DE_BOUND);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_MANUAL);
|
||||
_pExecutor->bareboneODBCTest(_dbConnString, tableCreateString, SQLExecutor::PB_AT_EXEC, SQLExecutor::DE_BOUND);
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSimpleAccess()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
std::string tableName("Person");
|
||||
std::string result;
|
||||
|
||||
_pSession->setFeature("autoBind", false);
|
||||
|
||||
recreatePersonTable();
|
||||
|
||||
try { *_pSession << "SELECT name FROM sqlite_master WHERE tbl_name=?", into(result), use(tableName), now; }
|
||||
catch(StatementException& ex) { std::cout << ex.toString() << std::endl; }
|
||||
|
||||
assert (result == tableName);
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccess();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testComplexType()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexType();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSimpleAccessVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->simpleAccessVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testComplexTypeVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->complexTypeVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testInsertVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testInsertEmptyVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateStringsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertEmptyVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testInsertSingleBulk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testInsertSingleBulkVec()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->insertSingleBulkVec();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testLimit()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testLimitZero()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitZero();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testLimitOnce()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
recreateIntsTable();
|
||||
_pExecutor->limitOnce();
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testLimitPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->limitPrepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testPrepare()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateIntsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->prepare();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSetComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->setComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
void ODBCSQLiteTest::testMultiSetSimple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetSimple();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testMultiSetComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiSetComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testMapComplexUnique()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->mapComplexUnique();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testMultiMapComplex()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->multiMapComplex();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSelectIntoSingle()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingle();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSelectIntoSingleStep()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleStep();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSelectIntoSingleFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->selectIntoSingleFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testLowerLimitOk()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitOk();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testSingleSelect()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->singleSelect();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testLowerLimitFail()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->lowerLimitFail();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testCombinedLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->ranges();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testCombinedIllegalLimits()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->combinedIllegalLimits();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testIllegalRange()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->illegalRange();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testEmptyDB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->emptyDB();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testBLOB()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blob();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testBLOBStmt()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreatePersonBLOBTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->blobStmt();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testFloat()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->floats();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testDouble()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateFloatsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->doubles();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testTuple()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tuples();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testTupleVector()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateTuplesTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->tupleVector();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::testInternalExtraction()
|
||||
{
|
||||
if (!_pSession) fail ("Test not available.");
|
||||
|
||||
for (int i = 0; i < 8;)
|
||||
{
|
||||
recreateVectorsTable();
|
||||
_pSession->setFeature("autoBind", bindValues[i]);
|
||||
_pSession->setFeature("autoExtract", bindValues[i+1]);
|
||||
_pExecutor->internalExtraction();
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::dropTable(const std::string& tableName)
|
||||
{
|
||||
try
|
||||
{
|
||||
*_pSession << format("DROP TABLE %s", tableName), now;
|
||||
}
|
||||
catch (StatementException& ex)
|
||||
{
|
||||
bool ignoreError = false;
|
||||
const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
|
||||
StatementDiagnostics::Iterator it = flds.begin();
|
||||
for (; it != flds.end(); ++it)
|
||||
{
|
||||
if (1 == it->_nativeError)//(no such table)
|
||||
{
|
||||
ignoreError = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ignoreError) throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::recreatePersonTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR2(30), FirstName VARCHAR2(30), Address VARCHAR2(30), Age INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::recreatePersonBLOBTable()
|
||||
{
|
||||
dropTable("Person");
|
||||
try { *_pSession << "CREATE TABLE Person (LastName VARCHAR(30), FirstName VARCHAR(30), Address VARCHAR(30), Image BLOB)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreatePersonBLOBTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::recreateIntsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateIntsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::recreateStringsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str VARCHAR(30))", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateStringsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::recreateFloatsTable()
|
||||
{
|
||||
dropTable("Strings");
|
||||
try { *_pSession << "CREATE TABLE Strings (str REAL)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateFloatsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::recreateTuplesTable()
|
||||
{
|
||||
dropTable("Tuples");
|
||||
try { *_pSession << "CREATE TABLE Tuples "
|
||||
"(int0 INTEGER, int1 INTEGER, int2 INTEGER, int3 INTEGER, int4 INTEGER, int5 INTEGER, int6 INTEGER, "
|
||||
"int7 INTEGER, int8 INTEGER, int9 INTEGER, int10 INTEGER, int11 INTEGER, int12 INTEGER, int13 INTEGER,"
|
||||
"int14 INTEGER, int15 INTEGER, int16 INTEGER, int17 INTEGER, int18 INTEGER, int19 INTEGER)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateTuplesTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::recreateVectorsTable()
|
||||
{
|
||||
dropTable("Vectors");
|
||||
try { *_pSession << "CREATE TABLE Vectors (int0 INTEGER, flt0 REAL, str0 VARCHAR)", now; }
|
||||
catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateVectorsTable()"); }
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::checkODBCSetup()
|
||||
{
|
||||
static bool beenHere = false;
|
||||
|
||||
if (!beenHere)
|
||||
{
|
||||
beenHere = true;
|
||||
bool driverFound = false;
|
||||
|
||||
Utility::DriverMap::iterator itDriver = _drivers.begin();
|
||||
for (; itDriver != _drivers.end(); ++itDriver)
|
||||
{
|
||||
if (((itDriver->first).find("SQLite3") != std::string::npos))
|
||||
{
|
||||
std::cout << "Driver found: " << itDriver->first
|
||||
<< " (" << itDriver->second << ')' << std::endl;
|
||||
|
||||
driverFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!driverFound)
|
||||
{
|
||||
std::cout << "SQLite3 driver NOT found, tests will fail." << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!_pSession)
|
||||
_dbConnString = "Driver=SQLite3 ODBC Driver;Database=dummy.db;";
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void ODBCSQLiteTest::tearDown()
|
||||
{
|
||||
dropTable("Person");
|
||||
dropTable("Strings");
|
||||
}
|
||||
|
||||
|
||||
CppUnit::Test* ODBCSQLiteTest::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCSQLiteTest");
|
||||
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testBareboneODBC);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccess);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexType);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSimpleAccessVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testComplexTypeVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertEmptyVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertSingleBulk);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInsertSingleBulkVec);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimit);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitOnce);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLimitZero);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testPrepare);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSetComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiSetSimple);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiSetComplex);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMapComplexUnique);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testMultiMapComplex);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingle);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingleStep);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSelectIntoSingleFail);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLowerLimitOk);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testLowerLimitFail);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testCombinedLimits);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testCombinedIllegalLimits);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testRange);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testIllegalRange);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testSingleSelect);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testEmptyDB);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testBLOB);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testBLOBStmt);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testFloat);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testDouble);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testTuple);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testTupleVector);
|
||||
CppUnit_addTest(pSuite, ODBCSQLiteTest, testInternalExtraction);
|
||||
|
||||
return pSuite;
|
||||
}
|
132
Data/ODBC/testsuite/src/ODBCSQLiteTest.h
Normal file
132
Data/ODBC/testsuite/src/ODBCSQLiteTest.h
Normal file
@ -0,0 +1,132 @@
|
||||
//
|
||||
// ODBCSQLiteTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCSQLiteTest.h#2 $
|
||||
//
|
||||
// Definition of the ODBCSQLiteTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBCSQLiteTest_INCLUDED
|
||||
#define ODBCSQLiteTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
#include "SQLExecutor.h"
|
||||
|
||||
|
||||
class ODBCSQLiteTest: public CppUnit::TestCase
|
||||
/// SQLite3 ODBC test class
|
||||
/// Tested:
|
||||
///
|
||||
/// Driver | DB | OS
|
||||
/// ------------+---------------+------------------------------------------
|
||||
/// 00.70.00.00 | SQLite 3.* | MS Windows XP Professional x64 v.2003/SP1
|
||||
{
|
||||
public:
|
||||
ODBCSQLiteTest(const std::string& name);
|
||||
~ODBCSQLiteTest();
|
||||
|
||||
void testBareboneODBC();
|
||||
|
||||
void testSimpleAccess();
|
||||
void testComplexType();
|
||||
void testSimpleAccessVector();
|
||||
void testComplexTypeVector();
|
||||
void testInsertVector();
|
||||
void testInsertEmptyVector();
|
||||
|
||||
void testInsertSingleBulk();
|
||||
void testInsertSingleBulkVec();
|
||||
|
||||
void testLimit();
|
||||
void testLimitOnce();
|
||||
void testLimitPrepare();
|
||||
void testLimitZero();
|
||||
void testPrepare();
|
||||
|
||||
void testSetSimple();
|
||||
void testSetComplex();
|
||||
void testSetComplexUnique();
|
||||
void testMultiSetSimple();
|
||||
void testMultiSetComplex();
|
||||
void testMapComplex();
|
||||
void testMapComplexUnique();
|
||||
void testMultiMapComplex();
|
||||
void testSelectIntoSingle();
|
||||
void testSelectIntoSingleStep();
|
||||
void testSelectIntoSingleFail();
|
||||
void testLowerLimitOk();
|
||||
void testLowerLimitFail();
|
||||
void testCombinedLimits();
|
||||
void testCombinedIllegalLimits();
|
||||
void testRange();
|
||||
void testIllegalRange();
|
||||
void testSingleSelect();
|
||||
void testEmptyDB();
|
||||
|
||||
void testBLOB();
|
||||
void testBLOBStmt();
|
||||
|
||||
void testFloat();
|
||||
void testDouble();
|
||||
|
||||
void testTuple();
|
||||
void testTupleVector();
|
||||
|
||||
void testInternalExtraction();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
void checkODBCSetup();
|
||||
void dropTable(const std::string& tableName);
|
||||
void recreatePersonTable();
|
||||
void recreatePersonBLOBTable();
|
||||
void recreateStringsTable();
|
||||
void recreateIntsTable();
|
||||
void recreateFloatsTable();
|
||||
void recreateTuplesTable();
|
||||
void recreateVectorsTable();
|
||||
|
||||
static Poco::Data::ODBC::Utility::DriverMap _drivers;
|
||||
static std::string _dbConnString;
|
||||
static Poco::SharedPtr<Poco::Data::Session> _pSession;
|
||||
static Poco::SharedPtr<SQLExecutor> _pExecutor;
|
||||
static const bool bindValues[8];
|
||||
};
|
||||
|
||||
|
||||
#endif // ODBCSQLiteTest_INCLUDED
|
73
Data/ODBC/testsuite/src/ODBCTestSuite.cpp
Normal file
73
Data/ODBC/testsuite/src/ODBCTestSuite.cpp
Normal file
@ -0,0 +1,73 @@
|
||||
//
|
||||
// ODBCTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "ODBCTestSuite.h"
|
||||
#include "ODBCDB2Test.h"
|
||||
#include "ODBCMySQLTest.h"
|
||||
#include "ODBCOracleTest.h"
|
||||
#include "ODBCPostgreSQLTest.h"
|
||||
#include "ODBCSQLiteTest.h"
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
#include "ODBCAccessTest.h"
|
||||
#include "ODBCSQLServerTest.h"
|
||||
#endif
|
||||
|
||||
CppUnit::Test* ODBCTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("ODBCTestSuite");
|
||||
|
||||
//!FIXME
|
||||
// On Win XP Pro:
|
||||
//
|
||||
// 1) The PostgreSQL connection fails if attempted after DB2 w/ following error:
|
||||
//
|
||||
// sqlState="IM003"
|
||||
// message="Specified driver could not be loaded due to system error 127 (PostgreSQL ANSI)."
|
||||
// nativeError=160
|
||||
// System error 127 is "The specified procedure could not be found."
|
||||
// Workaround is to connect to PostgreSQL prior to connecting to DB2.
|
||||
//
|
||||
// 2) When Oracle test is loaded after DB2, the test application does not exit cleanly.
|
||||
// All tests pass, though.
|
||||
//
|
||||
|
||||
pSuite->addTest(ODBCOracleTest::suite());
|
||||
pSuite->addTest(ODBCPostgreSQLTest::suite());
|
||||
pSuite->addTest(ODBCDB2Test::suite());
|
||||
pSuite->addTest(ODBCMySQLTest::suite());
|
||||
pSuite->addTest(ODBCSQLiteTest::suite());
|
||||
#if defined(POCO_OS_FAMILY_WINDOWS)
|
||||
pSuite->addTest(ODBCAccessTest::suite());
|
||||
pSuite->addTest(ODBCSQLServerTest::suite());
|
||||
#endif
|
||||
return pSuite;
|
||||
}
|
49
Data/ODBC/testsuite/src/ODBCTestSuite.h
Normal file
49
Data/ODBC/testsuite/src/ODBCTestSuite.h
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// ODBCTestSuite.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/ODBCTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the ODBCTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef ODBCTestSuite_INCLUDED
|
||||
#define ODBCTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class ODBCTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // ODBCTestSuite_INCLUDED
|
1661
Data/ODBC/testsuite/src/SQLExecutor.cpp
Normal file
1661
Data/ODBC/testsuite/src/SQLExecutor.cpp
Normal file
File diff suppressed because it is too large
Load Diff
124
Data/ODBC/testsuite/src/SQLExecutor.h
Normal file
124
Data/ODBC/testsuite/src/SQLExecutor.h
Normal file
@ -0,0 +1,124 @@
|
||||
//
|
||||
// SQLExecutor.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/SQLExecutor.h#2 $
|
||||
//
|
||||
// Definition of the SQLExecutor class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLExecutor_INCLUDED
|
||||
#define SQLExecutor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/ODBC/ODBC.h"
|
||||
#include "Poco/Data/Session.h"
|
||||
#include "Poco/Data/ODBC/Utility.h"
|
||||
|
||||
|
||||
class SQLExecutor: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
enum DataBinding
|
||||
{
|
||||
PB_IMMEDIATE,
|
||||
PB_AT_EXEC
|
||||
};
|
||||
|
||||
enum DataExtraction
|
||||
{
|
||||
DE_MANUAL,
|
||||
DE_BOUND
|
||||
};
|
||||
|
||||
SQLExecutor(const std::string& name, Poco::Data::Session* _pSession);
|
||||
~SQLExecutor();
|
||||
|
||||
void bareboneODBCTest(const std::string& dbConnString,
|
||||
const std::string& tableCreateString,
|
||||
DataBinding bindMode,
|
||||
DataExtraction extractMode);
|
||||
/// This function uses "bare bone" ODBC API calls (i.e. calls are not
|
||||
/// "wrapped" in PocoData framework structures).
|
||||
/// The purpose of the function is to verify that driver behaves
|
||||
/// correctly as well as to determine its capabilities
|
||||
/// (e.g. SQLGetData() restrictions relaxation policy, if any).
|
||||
/// If this test passes, subsequent tests failures are likely ours.
|
||||
|
||||
void simpleAccess();
|
||||
void complexType();
|
||||
void simpleAccessVector();
|
||||
void complexTypeVector();
|
||||
void insertVector();
|
||||
void insertEmptyVector();
|
||||
|
||||
void insertSingleBulk();
|
||||
void insertSingleBulkVec();
|
||||
|
||||
void limits();
|
||||
void limitOnce();
|
||||
void limitPrepare();
|
||||
void limitZero();
|
||||
void prepare();
|
||||
|
||||
void setSimple();
|
||||
void setComplex();
|
||||
void setComplexUnique();
|
||||
void multiSetSimple();
|
||||
void multiSetComplex();
|
||||
void mapComplex();
|
||||
void mapComplexUnique();
|
||||
void multiMapComplex();
|
||||
void selectIntoSingle();
|
||||
void selectIntoSingleStep();
|
||||
void selectIntoSingleFail();
|
||||
void lowerLimitOk();
|
||||
void lowerLimitFail();
|
||||
void combinedLimits();
|
||||
void combinedIllegalLimits();
|
||||
void ranges();
|
||||
void illegalRange();
|
||||
void singleSelect();
|
||||
void emptyDB();
|
||||
|
||||
void blob(int bigSize = 1024);
|
||||
void blobStmt();
|
||||
|
||||
void floats();
|
||||
void doubles();
|
||||
void tuples();
|
||||
void tupleVector();
|
||||
|
||||
void internalExtraction();
|
||||
|
||||
private:
|
||||
Poco::Data::Session* _pSession;
|
||||
};
|
||||
|
||||
|
||||
#endif // SQLExecutor_INCLUDED
|
50
Data/ODBC/testsuite/src/WinDriver.cpp
Normal file
50
Data/ODBC/testsuite/src/WinDriver.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// WinDriver.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/ODBC/testsuite/src/WinDriver.cpp#2 $
|
||||
//
|
||||
// Windows test driver for Poco ODBC.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "WinTestRunner/WinTestRunner.h"
|
||||
#include "ODBCTestSuite.h"
|
||||
|
||||
|
||||
class TestDriver: public CppUnit::WinTestRunnerApp
|
||||
{
|
||||
void TestMain()
|
||||
{
|
||||
CppUnit::WinTestRunner runner;
|
||||
runner.addTest(ODBCTestSuite::suite());
|
||||
runner.run();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TestDriver theDriver;
|
21
Data/SQLite/Makefile
Normal file
21
Data/SQLite/Makefile
Normal file
@ -0,0 +1,21 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/Main/Data/SQLite/Makefile#2 $
|
||||
#
|
||||
# Makefile for Poco SQLite
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
SYSFLAGS += -DTHREADSAFE -DNO_TCL
|
||||
|
||||
objects = Binder Extractor SessionImpl SessionInstantiator \
|
||||
SQLiteException SQLiteStatementImpl Utility \
|
||||
sqlite3
|
||||
|
||||
target = PocoSQLite
|
||||
target_version = $(LIBVERSION)
|
||||
target_libs = PocoData PocoFoundation
|
||||
|
||||
include $(POCO_BASE)/build/rules/lib
|
30
Data/SQLite/SQLite_VS71.sln
Normal file
30
Data/SQLite/SQLite_VS71.sln
Normal file
@ -0,0 +1,30 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SQLite", "SQLite_VS71.vcproj", "{1B29820D-375F-11DB-837B-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS71.vcproj", "{1B30A91B-375F-11DB-837B-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5} = {1B29820D-375F-11DB-837B-00123FC423B5}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
debug_shared = debug_shared
|
||||
release_shared = release_shared
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.debug_shared.ActiveCfg = debug_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.debug_shared.Build.0 = debug_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.release_shared.ActiveCfg = release_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.release_shared.Build.0 = release_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.debug_shared.ActiveCfg = debug_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.debug_shared.Build.0 = debug_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.release_shared.ActiveCfg = release_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.release_shared.Build.0 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
223
Data/SQLite/SQLite_VS71.vcproj
Normal file
223
Data/SQLite/SQLite_VS71.vcproj
Normal file
@ -0,0 +1,223 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="SQLite"
|
||||
ProjectGUID="{1b29820d-375f-11db-837b-00123fc423b5}"
|
||||
RootNamespace="SQLite"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;.\src;..\..\Foundation\include;..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;SQLite_EXPORTS;NO_TCL;THREADSAFE"
|
||||
StringPooling="TRUE"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoDatad.lib"
|
||||
OutputFile="..\..\bin\PocoSQLited.dll"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="..\..\bin\PocoSQLited.pdb"
|
||||
SubSystem="1"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\..\lib\PocoSQLited.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForProcessor="3"
|
||||
AdditionalIncludeDirectories=".\include;.\src;..\..\Foundation\include;..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;SQLite_EXPORTS;NO_TCL;THREADSAFE"
|
||||
GeneratePreprocessedFile="0"
|
||||
KeepComments="FALSE"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="FALSE"
|
||||
DebugInformationFormat="0"
|
||||
CompileAs="0"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoData.lib"
|
||||
OutputFile="..\..\bin\PocoSQLite.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="TRUE"
|
||||
AdditionalLibraryDirectories="..\..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\..\lib\PocoSQLite.lib"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="SQLite"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\Binder.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\Extractor.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SessionImpl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SessionInstantiator.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SQLite.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SQLiteException.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SQLiteStatementImpl.h">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\Utility.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\Binder.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Extractor.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionImpl.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionInstantiator.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SQLiteException.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SQLiteStatementImpl.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Utility.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="3rdparty"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\sqlite3.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\sqlite3.c">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
28
Data/SQLite/SQLite_VS80.sln
Normal file
28
Data/SQLite/SQLite_VS80.sln
Normal file
@ -0,0 +1,28 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SQLite", "SQLite_VS80.vcproj", "{1B29820D-375F-11DB-837B-00123FC423B5}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestSuite", "testsuite\TestSuite_VS80.vcproj", "{1B30A91B-375F-11DB-837B-00123FC423B5}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5} = {1B29820D-375F-11DB-837B-00123FC423B5}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
debug_shared|Win32 = debug_shared|Win32
|
||||
release_shared|Win32 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{1B29820D-375F-11DB-837B-00123FC423B5}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.debug_shared|Win32.ActiveCfg = debug_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.debug_shared|Win32.Build.0 = debug_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.release_shared|Win32.ActiveCfg = release_shared|Win32
|
||||
{1B30A91B-375F-11DB-837B-00123FC423B5}.release_shared|Win32.Build.0 = release_shared|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
301
Data/SQLite/SQLite_VS80.vcproj
Normal file
301
Data/SQLite/SQLite_VS80.vcproj
Normal file
@ -0,0 +1,301 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="SQLite"
|
||||
ProjectGUID="{1B29820D-375F-11DB-837B-00123FC423B5}"
|
||||
RootNamespace="SQLite"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=".\include;.\src;..\..\Foundation\include;..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;POCO_DLL;SQLite_EXPORTS;NO_TCL;THREADSAFE"
|
||||
StringPooling="true"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="4"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundationd.lib PocoDatad.lib"
|
||||
OutputFile="..\..\bin\PocoSQLited.dll"
|
||||
LinkIncremental="2"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="..\..\bin\PocoSQLited.pdb"
|
||||
SubSystem="1"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\..\lib\PocoSQLited.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories=".\include;.\src;..\..\Foundation\include;..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;POCO_DLL;SQLite_EXPORTS;NO_TCL;THREADSAFE"
|
||||
GeneratePreprocessedFile="0"
|
||||
KeepComments="false"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="false"
|
||||
DebugInformationFormat="0"
|
||||
CompileAs="0"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="PocoFoundation.lib PocoData.lib"
|
||||
OutputFile="..\..\bin\PocoSQLite.dll"
|
||||
LinkIncremental="1"
|
||||
SuppressStartupBanner="true"
|
||||
AdditionalLibraryDirectories="..\..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
OptimizeForWindows98="1"
|
||||
ImportLibrary="..\..\lib\PocoSQLite.lib"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="SQLite"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\Binder.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\Extractor.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SessionImpl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SessionInstantiator.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SQLite.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SQLiteException.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\SQLiteStatementImpl.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\Poco\Data\SQLite\Utility.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\Binder.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Extractor.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SessionInstantiator.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SQLiteException.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\SQLiteStatementImpl.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Utility.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="3rdparty"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\sqlite3.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\sqlite3.c"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
196
Data/SQLite/include/Poco/Data/SQLite/Binder.h
Normal file
196
Data/SQLite/include/Poco/Data/SQLite/Binder.h
Normal file
@ -0,0 +1,196 @@
|
||||
//
|
||||
// Binder.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Binder.h#3 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Binder
|
||||
//
|
||||
// Definition of the Binder class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_SQLite_Binder_INCLUDED
|
||||
#define DataConnectors_SQLite_Binder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/AbstractBinder.h"
|
||||
#include "Poco/Any.h"
|
||||
|
||||
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Binder: public Poco::Data::AbstractBinder
|
||||
/// Binds placeholders in the sql query to the provided values. Performs data types mapping.
|
||||
{
|
||||
public:
|
||||
Binder(sqlite3_stmt* pStmt);
|
||||
/// Creates the Binder.
|
||||
|
||||
~Binder();
|
||||
/// Destroys the Binder.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int8 &val);
|
||||
/// Binds an Int8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt8 &val);
|
||||
/// Binds an UInt8.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int16 &val);
|
||||
/// Binds an Int16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt16 &val);
|
||||
/// Binds an UInt16.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int32 &val);
|
||||
/// Binds an Int32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt32 &val);
|
||||
/// Binds an UInt32.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Int64 &val);
|
||||
/// Binds an Int64.
|
||||
|
||||
void bind(std::size_t pos, const Poco::UInt64 &val);
|
||||
/// Binds an UInt64.
|
||||
|
||||
void bind(std::size_t pos, const bool &val);
|
||||
/// Binds a boolean.
|
||||
|
||||
void bind(std::size_t pos, const float &val);
|
||||
/// Binds a float.
|
||||
|
||||
void bind(std::size_t pos, const double &val);
|
||||
/// Binds a double.
|
||||
|
||||
void bind(std::size_t pos, const char &val);
|
||||
/// Binds a single character.
|
||||
|
||||
void bind(std::size_t pos, const char* const &pVal);
|
||||
/// Binds a const char ptr.
|
||||
|
||||
void bind(std::size_t pos, const std::string& val);
|
||||
/// Binds a string.
|
||||
|
||||
void bind(std::size_t pos, const Poco::Data::BLOB& val);
|
||||
/// Binds a BLOB.
|
||||
|
||||
private:
|
||||
void checkReturn(int rc);
|
||||
/// Checks the SQLite return code and throws an appropriate exception.
|
||||
|
||||
private:
|
||||
sqlite3_stmt* _pStmt;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int8 &val)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt8 &val)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::Int16 &val)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt16 &val)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt32 &val)
|
||||
{
|
||||
Poco::Int32 tmp = static_cast<Poco::Int32>(val);
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const Poco::UInt64 &val)
|
||||
{
|
||||
Poco::Int64 tmp = static_cast<Poco::Int64>(val);
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const bool &val)
|
||||
{
|
||||
Poco::Int32 tmp = (val ? 1 : 0);
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const float &val)
|
||||
{
|
||||
double tmp = val;
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const char &val)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp);
|
||||
}
|
||||
|
||||
|
||||
inline void Binder::bind(std::size_t pos, const char* const &pVal)
|
||||
{
|
||||
std::string val(pVal);
|
||||
bind(pos, val);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // DataConnectors_SQLite_Binder_INCLUDED
|
123
Data/SQLite/include/Poco/Data/SQLite/Extractor.h
Normal file
123
Data/SQLite/include/Poco/Data/SQLite/Extractor.h
Normal file
@ -0,0 +1,123 @@
|
||||
//
|
||||
// Extractor.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Extractor.h#3 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Extractor
|
||||
//
|
||||
// Definition of the Extractor class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_SQLite_Extractor_INCLUDED
|
||||
#define DataConnectors_SQLite_Extractor_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/AbstractExtractor.h"
|
||||
#include "Poco/Any.h"
|
||||
|
||||
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Extractor: public Poco::Data::AbstractExtractor
|
||||
/// Extracts and converts data values form the result row returned by SQLite.
|
||||
/// If NULL is received, the incoming val value is not changed and false is returned
|
||||
{
|
||||
public:
|
||||
Extractor(sqlite3_stmt* pStmt);
|
||||
/// Creates the Extractor.
|
||||
|
||||
~Extractor();
|
||||
/// Destroys the Extractor.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int8& val);
|
||||
/// Extracts an Int8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt8& val);
|
||||
/// Extracts an UInt8.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int16& val);
|
||||
/// Extracts an Int16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt16& val);
|
||||
/// Extracts an UInt16.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int32& val);
|
||||
/// Extracts an Int32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt32& val);
|
||||
/// Extracts an UInt32.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Int64& val);
|
||||
/// Extracts an Int64.
|
||||
|
||||
bool extract(std::size_t pos, Poco::UInt64& val);
|
||||
/// Extracts an UInt64.
|
||||
|
||||
bool extract(std::size_t pos, bool& val);
|
||||
/// Extracts a boolean.
|
||||
|
||||
bool extract(std::size_t pos, float& val);
|
||||
/// Extracts a float.
|
||||
|
||||
bool extract(std::size_t pos, double& val);
|
||||
/// Extracts a double.
|
||||
|
||||
bool extract(std::size_t pos, char& val);
|
||||
/// Extracts a single character.
|
||||
|
||||
bool extract(std::size_t pos, std::string& val);
|
||||
/// Extracts a string.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Data::BLOB& val);
|
||||
/// Extracts a BLOB.
|
||||
|
||||
bool extract(std::size_t pos, Poco::Any& val);
|
||||
/// Extracts an Any.
|
||||
|
||||
private:
|
||||
bool isNull(std::size_t pos);
|
||||
/// Returns true if a non null value can be extracted
|
||||
|
||||
sqlite3_stmt* _pStmt;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // DataConnectors_SQLite_Extractor_INCLUDED
|
92
Data/SQLite/include/Poco/Data/SQLite/SQLite.h
Normal file
92
Data/SQLite/include/Poco/Data/SQLite/SQLite.h
Normal file
@ -0,0 +1,92 @@
|
||||
//
|
||||
// SQLite.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLite.h#3 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLIte
|
||||
// Module: SQLite
|
||||
//
|
||||
// Basic definitions for the Poco SQLite library.
|
||||
// This file must be the first file included by every other SQLite
|
||||
// header file.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_SQLite_INCLUDED
|
||||
#define SQLite_SQLite_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
|
||||
|
||||
//
|
||||
// The following block is the standard way of creating macros which make exporting
|
||||
// from a DLL simpler. All files within this DLL are compiled with the SQLite_EXPORTS
|
||||
// symbol defined on the command line. this symbol should not be defined on any project
|
||||
// that uses this DLL. This way any other project whose source files include this file see
|
||||
// SQLite_API functions as being imported from a DLL, wheras this DLL sees symbols
|
||||
// defined with this macro as being exported.
|
||||
//
|
||||
#if defined(_WIN32) && defined(POCO_DLL)
|
||||
#if defined(SQLite_EXPORTS)
|
||||
#define SQLite_API __declspec(dllexport)
|
||||
#else
|
||||
#define SQLite_API __declspec(dllimport)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(SQLite_API)
|
||||
#define SQLite_API
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// Automatically link Data library.
|
||||
//
|
||||
#if defined(_MSC_VER)
|
||||
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(SQLite_EXPORTS)
|
||||
#if defined(POCO_DLL)
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoSQLited.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoSQLite.lib")
|
||||
#endif
|
||||
#else
|
||||
#if defined(_DEBUG)
|
||||
#pragma comment(lib, "PocoSQLitemtd.lib")
|
||||
#else
|
||||
#pragma comment(lib, "PocoSQLitemt.lib")
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SQLite_SQLite_INCLUDED
|
81
Data/SQLite/include/Poco/Data/SQLite/SQLiteException.h
Normal file
81
Data/SQLite/include/Poco/Data/SQLite/SQLiteException.h
Normal file
@ -0,0 +1,81 @@
|
||||
//
|
||||
// SQLiteException.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLiteException.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteException
|
||||
//
|
||||
// Definition of SQLiteException.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_SQLiteException_INCLUDED
|
||||
#define SQLite_SQLiteException_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, SQLiteException, Poco::Data::DataException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InvalidSQLStatementException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InternalDBErrorException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DBAccessDeniedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ExecutionAbortedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DBLockedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TableLockedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, NoMemoryException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ReadOnlyException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InterruptException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, IOErrorException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, CorruptImageException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TableNotFoundException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DatabaseFullException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, CantOpenDBFileException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, LockProtocolException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, SchemaDiffersException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, RowTooBigException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, ConstraintViolationException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, DataTypeMismatchException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, InvalidLibraryUseException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, OSFeaturesMissingException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, AuthorizationDeniedException, SQLiteException)
|
||||
POCO_DECLARE_EXCEPTION(SQLite_API, TransactionException, SQLiteException)
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif
|
134
Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h
Normal file
134
Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h
Normal file
@ -0,0 +1,134 @@
|
||||
//
|
||||
// SQLiteStatementImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SQLiteStatementImpl.h#3 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteStatementImpl
|
||||
//
|
||||
// Definition of the SQLiteStatementImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_SQLite_SQLiteStatementImpl_INCLUDED
|
||||
#define DataConnectors_SQLite_SQLiteStatementImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/SQLite/Extractor.h"
|
||||
#include "Poco/Data/StatementImpl.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API SQLiteStatementImpl: public Poco::Data::StatementImpl
|
||||
/// Implements statement functionality needed for SQLite
|
||||
{
|
||||
public:
|
||||
SQLiteStatementImpl(sqlite3* pDB);
|
||||
/// Creates the SQLiteStatementImpl.
|
||||
|
||||
~SQLiteStatementImpl();
|
||||
/// Destroys the SQLiteStatementImpl.
|
||||
|
||||
protected:
|
||||
Poco::UInt32 columnsReturned() const;
|
||||
/// Returns number of columns returned by query.
|
||||
|
||||
const MetaColumn& metaColumn(Poco::UInt32 pos) const;
|
||||
/// Returns column meta data.
|
||||
|
||||
bool hasNext();
|
||||
/// Returns true if a call to next() will return data.
|
||||
|
||||
void next();
|
||||
/// Retrieves the next row from the resultset.
|
||||
/// Will throw, if the resultset is empty.
|
||||
|
||||
bool canBind() const;
|
||||
/// Returns true if a valid statement is set and we can bind.
|
||||
|
||||
void compileImpl();
|
||||
/// Compiles the statement, doesn't bind yet
|
||||
|
||||
void bindImpl();
|
||||
/// Binds parameters
|
||||
|
||||
AbstractExtractor& extractor();
|
||||
/// Returns the concrete extractor used by the statement.
|
||||
|
||||
AbstractBinder& binder();
|
||||
/// Returns the concrete binder used by the statement.
|
||||
|
||||
private:
|
||||
void clear();
|
||||
/// Removes the _pStmt
|
||||
|
||||
typedef Poco::Data::AbstractBindingVec Bindings;
|
||||
typedef Poco::Data::AbstractExtractionVec Extractions;
|
||||
|
||||
sqlite3* _pDB;
|
||||
sqlite3_stmt* _pStmt;
|
||||
bool _stepCalled;
|
||||
int _nextResponse;
|
||||
Poco::SharedPtr<Binder> _pBinder;
|
||||
Poco::SharedPtr<Extractor> _pExtractor;
|
||||
std::vector<Poco::Data::MetaColumn> _columns;
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline AbstractExtractor& SQLiteStatementImpl::extractor()
|
||||
{
|
||||
return *_pExtractor;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBinder& SQLiteStatementImpl::binder()
|
||||
{
|
||||
return *_pBinder;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // DataConnectors_SQLite_SQLiteStatementImpl_INCLUDED
|
103
Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h
Normal file
103
Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h
Normal file
@ -0,0 +1,103 @@
|
||||
//
|
||||
// SessionImpl.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SessionImpl.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SessionImpl
|
||||
//
|
||||
// Definition of the SessionImpl class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_SQLite_SessionImpl_INCLUDED
|
||||
#define DataConnectors_SQLite_SessionImpl_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/AbstractSessionImpl.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API SessionImpl: public Poco::Data::AbstractSessionImpl<SessionImpl>
|
||||
/// Implements SessionImpl interface.
|
||||
{
|
||||
public:
|
||||
SessionImpl(const std::string& fileName);
|
||||
/// Creates the SessionImpl. Opens a connection to the database.
|
||||
|
||||
~SessionImpl();
|
||||
/// Destroys the SessionImpl.
|
||||
|
||||
Poco::Data::StatementImpl* createStatementImpl();
|
||||
/// Returns an SQLite StatementImpl.
|
||||
|
||||
void begin();
|
||||
/// Starts a transaction.
|
||||
|
||||
void commit();
|
||||
/// Commits and ends a transaction.
|
||||
|
||||
void rollback();
|
||||
/// Aborts a transaction.
|
||||
|
||||
void close();
|
||||
/// Closes the session.
|
||||
|
||||
bool isConnected();
|
||||
/// Returns true if connected, false otherwise.
|
||||
|
||||
private:
|
||||
void open();
|
||||
/// Opens a connection to the Database.
|
||||
|
||||
std::string _dbFileName;
|
||||
sqlite3* _pDB;
|
||||
bool _connected;
|
||||
|
||||
static const std::string DEFERRED_BEGIN_TRANSACTION;
|
||||
static const std::string COMMIT_TRANSACTION;
|
||||
static const std::string ABORT_TRANSACTION;
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // DataConnectors_SQLite_SessionImpl_INCLUDED
|
79
Data/SQLite/include/Poco/Data/SQLite/SessionInstantiator.h
Normal file
79
Data/SQLite/include/Poco/Data/SQLite/SessionInstantiator.h
Normal file
@ -0,0 +1,79 @@
|
||||
//
|
||||
// SessionInstantiator.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/SessionInstantiator.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SessionInstantiator
|
||||
//
|
||||
// Definition of the SessionInstantiator class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef DataConnectors_SQLite_SessionInstantiator_INCLUDED
|
||||
#define DataConnectors_SQLite_SessionInstantiator_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/SessionInstantiator.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API SessionInstantiator: public Poco::Data::SessionInstantiator
|
||||
/// SessionInstantiator instantiates SqLite SessionImpl objects.
|
||||
{
|
||||
public:
|
||||
static const std::string KEY;
|
||||
/// Keyword for creating SQLite sessions.
|
||||
|
||||
SessionInstantiator();
|
||||
/// Creates the SessionInstantiator.
|
||||
|
||||
~SessionInstantiator();
|
||||
/// Destroys the SessionInstantiator.
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> create(const std::string& initString);
|
||||
/// Creates a SQLite SessionImpl object and initializes it with the given initString.
|
||||
|
||||
static void addToFactory();
|
||||
/// Registers the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory.
|
||||
|
||||
static void removeFromFactory();
|
||||
/// Unregisters the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory.
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif // DataConnectors_SQLite_SessionInstantiator_INCLUDED
|
74
Data/SQLite/include/Poco/Data/SQLite/Utility.h
Normal file
74
Data/SQLite/include/Poco/Data/SQLite/Utility.h
Normal file
@ -0,0 +1,74 @@
|
||||
//
|
||||
// Utility.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/include/Poco/Data/SQLite/Utility.h#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Utility
|
||||
//
|
||||
// Definition of Utility.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLite_Utility_INCLUDED
|
||||
#define SQLite_Utility_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "Poco/Data/MetaColumn.h"
|
||||
|
||||
|
||||
struct sqlite3;
|
||||
struct sqlite3_stmt;
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
class SQLite_API Utility
|
||||
/// Various utility functions for SQLite, mostly return code handling
|
||||
{
|
||||
public:
|
||||
static std::string lastError(sqlite3* pDb);
|
||||
/// Retreives the last error code from sqlite and converts it to a string
|
||||
|
||||
static void throwException(int rc, const std::string& addErrMsg = std::string());
|
||||
/// Throws for an error code the appropriate exception
|
||||
|
||||
static MetaColumn::ColumnDataType getColumnType(sqlite3_stmt* pStmt, std::size_t pos);
|
||||
/// Returns column data type.
|
||||
};
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
||||
|
||||
|
||||
#endif
|
107
Data/SQLite/src/Binder.cpp
Normal file
107
Data/SQLite/src/Binder.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
//
|
||||
// Binder.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Binder.cpp#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Binder
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/Binder.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "sqlite3.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
Binder::Binder(sqlite3_stmt* pStmt):
|
||||
_pStmt(pStmt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Binder::~Binder()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int32 &val)
|
||||
{
|
||||
int rc = sqlite3_bind_int(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int64 &val)
|
||||
{
|
||||
int rc = sqlite3_bind_int64(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const double &val)
|
||||
{
|
||||
int rc = sqlite3_bind_double(_pStmt, (int) pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const std::string& val)
|
||||
{
|
||||
int rc = sqlite3_bind_text(_pStmt, (int) pos, val.c_str(), (int) val.size()*sizeof(char), SQLITE_TRANSIENT);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Data::BLOB& val)
|
||||
{
|
||||
// convert a blob to a an unsigned char* array
|
||||
const unsigned char* pData = reinterpret_cast<const unsigned char*>(val.rawContent());
|
||||
int valSize = static_cast<int>(val.size());
|
||||
|
||||
int rc = sqlite3_bind_blob(_pStmt, static_cast<int>(pos), pData, valSize, SQLITE_STATIC); // no deep copy, do not free memory
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
|
||||
void Binder::checkReturn(int rc)
|
||||
{
|
||||
if (rc != SQLITE_OK)
|
||||
Utility::throwException(rc);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
306
Data/SQLite/src/Extractor.cpp
Normal file
306
Data/SQLite/src/Extractor.cpp
Normal file
@ -0,0 +1,306 @@
|
||||
//
|
||||
// Extractor.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Extractor.cpp#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Extractor
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/Extractor.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/BLOB.h"
|
||||
#include "Poco/Data/DataException.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "sqlite3.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
Extractor::Extractor(sqlite3_stmt* pStmt):
|
||||
_pStmt(pStmt)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Extractor::~Extractor()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int64& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, double& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_double(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, std::string& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
const char *pBuf = reinterpret_cast<const char*>(sqlite3_column_text(_pStmt, (int) pos));
|
||||
if (!pBuf)
|
||||
val.clear();
|
||||
else
|
||||
val = std::string(pBuf);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Data::BLOB& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
int size = sqlite3_column_bytes(_pStmt, (int) pos);
|
||||
const char* pTmp = reinterpret_cast<const char*>(sqlite3_column_blob(_pStmt, (int) pos));
|
||||
val = Poco::Data::BLOB(pTmp, size);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int8& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt8& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt16& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt32& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::UInt64& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = sqlite3_column_int64(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, bool& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = (0 != sqlite3_column_int(_pStmt, (int) pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, float& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = static_cast<float>(sqlite3_column_double(_pStmt, (int) pos));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, char& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
val = sqlite3_column_int(_pStmt, (int) pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Any& val)
|
||||
{
|
||||
if (isNull(pos)) return false;
|
||||
|
||||
bool ret = false;
|
||||
|
||||
switch (Utility::getColumnType(_pStmt, pos))
|
||||
{
|
||||
case MetaColumn::FDT_BOOL:
|
||||
{
|
||||
bool i = false;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT8:
|
||||
{
|
||||
Poco::Int8 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT8:
|
||||
{
|
||||
Poco::UInt8 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT16:
|
||||
{
|
||||
Poco::Int16 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT16:
|
||||
{
|
||||
Poco::UInt16 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT32:
|
||||
{
|
||||
Poco::Int32 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT32:
|
||||
{
|
||||
Poco::UInt32 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_INT64:
|
||||
{
|
||||
Poco::Int64 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_UINT64:
|
||||
{
|
||||
Poco::UInt64 i = 0;
|
||||
ret = extract(pos, i);
|
||||
val = i;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_STRING:
|
||||
{
|
||||
std::string s;
|
||||
ret = extract(pos, s);
|
||||
val = s;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_DOUBLE:
|
||||
{
|
||||
double d(0.0);
|
||||
ret = extract(pos, d);
|
||||
val = d;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_FLOAT:
|
||||
{
|
||||
float f(0.0);
|
||||
ret = extract(pos, f);
|
||||
val = f;
|
||||
break;
|
||||
}
|
||||
case MetaColumn::FDT_BLOB:
|
||||
{
|
||||
BLOB b;
|
||||
ret = extract(pos, b);
|
||||
val = b;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw Poco::Data::UnknownTypeException("Unknown type during extraction");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool Extractor::isNull(std::size_t pos)
|
||||
{
|
||||
return sqlite3_column_type(_pStmt, (int) pos) == SQLITE_NULL;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
72
Data/SQLite/src/SQLiteException.cpp
Normal file
72
Data/SQLite/src/SQLiteException.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
//
|
||||
// SQLiteException.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SQLiteException.cpp#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteException
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include <typeinfo>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
POCO_IMPLEMENT_EXCEPTION(SQLiteException, Poco::Data::DataException, "Generic SQLite error")
|
||||
POCO_IMPLEMENT_EXCEPTION(InvalidSQLStatementException, SQLiteException, "SQL Statement invalid")
|
||||
POCO_IMPLEMENT_EXCEPTION(InternalDBErrorException, SQLiteException, "Internal error")
|
||||
POCO_IMPLEMENT_EXCEPTION(DBAccessDeniedException, SQLiteException, "Access permission denied")
|
||||
POCO_IMPLEMENT_EXCEPTION(ExecutionAbortedException, SQLiteException, "Execution of SQL statement aborted")
|
||||
POCO_IMPLEMENT_EXCEPTION(DBLockedException, SQLiteException, "The database is locked")
|
||||
POCO_IMPLEMENT_EXCEPTION(TableLockedException, SQLiteException, "A table in the database is locked")
|
||||
POCO_IMPLEMENT_EXCEPTION(NoMemoryException, SQLiteException, "Out of Memory")
|
||||
POCO_IMPLEMENT_EXCEPTION(ReadOnlyException, SQLiteException, "Attempt to write a readonly database")
|
||||
POCO_IMPLEMENT_EXCEPTION(InterruptException, SQLiteException, "Operation terminated by an interrupt")
|
||||
POCO_IMPLEMENT_EXCEPTION(IOErrorException, SQLiteException, "Some kind of disk I/O error occurred")
|
||||
POCO_IMPLEMENT_EXCEPTION(CorruptImageException, SQLiteException, "The database disk image is malformed")
|
||||
POCO_IMPLEMENT_EXCEPTION(TableNotFoundException, SQLiteException, "Table not found")
|
||||
POCO_IMPLEMENT_EXCEPTION(DatabaseFullException, SQLiteException, "Insertion failed because database is full")
|
||||
POCO_IMPLEMENT_EXCEPTION(CantOpenDBFileException, SQLiteException, "Unable to open the database file")
|
||||
POCO_IMPLEMENT_EXCEPTION(LockProtocolException, SQLiteException, "Database lock protocol error")
|
||||
POCO_IMPLEMENT_EXCEPTION(SchemaDiffersException, SQLiteException, "The database schema changed")
|
||||
POCO_IMPLEMENT_EXCEPTION(RowTooBigException, SQLiteException, "Too much data for one row of a table")
|
||||
POCO_IMPLEMENT_EXCEPTION(ConstraintViolationException, SQLiteException, "Abort due to constraint violation")
|
||||
POCO_IMPLEMENT_EXCEPTION(DataTypeMismatchException, SQLiteException, "Data type mismatch")
|
||||
POCO_IMPLEMENT_EXCEPTION(InvalidLibraryUseException, SQLiteException, "Library used incorrectly")
|
||||
POCO_IMPLEMENT_EXCEPTION(OSFeaturesMissingException, SQLiteException, "Uses OS features not supported on host")
|
||||
POCO_IMPLEMENT_EXCEPTION(AuthorizationDeniedException, SQLiteException, "Authorization denied")
|
||||
POCO_IMPLEMENT_EXCEPTION(TransactionException, SQLiteException, "Transaction exception")
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
233
Data/SQLite/src/SQLiteStatementImpl.cpp
Normal file
233
Data/SQLite/src/SQLiteStatementImpl.cpp
Normal file
@ -0,0 +1,233 @@
|
||||
//
|
||||
// SQLiteStatementImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SQLiteStatementImpl.cpp#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SQLiteStatementImpl
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLiteStatementImpl.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/String.h"
|
||||
#include "sqlite3.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
SQLiteStatementImpl::SQLiteStatementImpl(sqlite3* pDB):
|
||||
_pDB(pDB),
|
||||
_pStmt(0),
|
||||
_stepCalled(false),
|
||||
_nextResponse(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SQLiteStatementImpl::~SQLiteStatementImpl()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::compileImpl()
|
||||
{
|
||||
if (_pStmt) return;
|
||||
|
||||
std::string statement(toString());
|
||||
if (statement.empty())
|
||||
throw InvalidSQLStatementException("Empty statements are illegal");
|
||||
|
||||
sqlite3_stmt* pStmt = 0;
|
||||
const char* pSql = statement.c_str(); // The SQL to be executed
|
||||
int rc = SQLITE_OK;
|
||||
const char* pLeftover = 0;
|
||||
bool queryFound = false;
|
||||
|
||||
while (rc == SQLITE_OK && !pStmt && !queryFound)
|
||||
{
|
||||
rc = sqlite3_prepare(_pDB, pSql, -1, &pStmt, &pLeftover);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
if (pStmt)
|
||||
{
|
||||
sqlite3_finalize(pStmt);
|
||||
}
|
||||
pStmt = 0;
|
||||
std::string errMsg = sqlite3_errmsg(_pDB);
|
||||
Utility::throwException(rc, errMsg);
|
||||
}
|
||||
else if (rc == SQLITE_OK && pStmt)
|
||||
{
|
||||
queryFound = true;
|
||||
}
|
||||
else if(rc == SQLITE_OK && !pStmt) // comment/whitespace ignore
|
||||
{
|
||||
pSql = pLeftover;
|
||||
if (strlen(pSql) == 0)
|
||||
{
|
||||
// empty statement or an conditional statement! like CREATE IF NOT EXISTS
|
||||
// this is valid
|
||||
queryFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clear();
|
||||
_pStmt = pStmt;
|
||||
|
||||
// prepare binding
|
||||
_pBinder = new Binder(_pStmt);
|
||||
_pExtractor = new Extractor(_pStmt);
|
||||
|
||||
int colCount = sqlite3_column_count(_pStmt);
|
||||
|
||||
for (int i = 0; i < colCount; ++i)
|
||||
{
|
||||
MetaColumn mc(i + 1, sqlite3_column_name(_pStmt, i), Utility::getColumnType(_pStmt, i));
|
||||
_columns.push_back(mc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SQLiteStatementImpl::canBind() const
|
||||
{
|
||||
bool ret = false;
|
||||
if (!bindings().empty() && _pStmt)
|
||||
ret = (*bindings().begin())->canBind();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::bindImpl()
|
||||
{
|
||||
_stepCalled = false;
|
||||
_nextResponse = 0;
|
||||
if (_pStmt == 0) return;
|
||||
|
||||
sqlite3_reset(_pStmt);
|
||||
|
||||
// bind
|
||||
Bindings& binds = bindings();
|
||||
if (binds.empty()) return;
|
||||
|
||||
std::size_t pos = 1; // sqlite starts with 1 not 0!
|
||||
|
||||
Bindings::iterator it = binds.begin();
|
||||
Bindings::iterator itEnd = binds.end();
|
||||
for (; it != itEnd && (*it)->canBind(); ++it)
|
||||
{
|
||||
(*it)->bind(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::clear()
|
||||
{
|
||||
_columns.clear();
|
||||
|
||||
if (_pStmt)
|
||||
{
|
||||
sqlite3_finalize(_pStmt);
|
||||
_pStmt=0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool SQLiteStatementImpl::hasNext()
|
||||
{
|
||||
if (_stepCalled)
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
|
||||
// _pStmt is allowed to be null for conditional SQL statements
|
||||
if (_pStmt == 0)
|
||||
{
|
||||
_stepCalled = true;
|
||||
_nextResponse = SQLITE_DONE;
|
||||
return false;
|
||||
}
|
||||
|
||||
_stepCalled = true;
|
||||
_nextResponse = sqlite3_step(_pStmt);
|
||||
|
||||
return (_nextResponse == SQLITE_ROW);
|
||||
}
|
||||
|
||||
|
||||
void SQLiteStatementImpl::next()
|
||||
{
|
||||
if (SQLITE_ROW == _nextResponse)
|
||||
{
|
||||
poco_assert (columnsReturned() == sqlite3_column_count(_pStmt));
|
||||
|
||||
Extractions& extracts = extractions();
|
||||
Extractions::iterator it = extracts.begin();
|
||||
Extractions::iterator itEnd = extracts.end();
|
||||
std::size_t pos = 0; // sqlite starts with pos 0 for results!
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
_stepCalled = false;
|
||||
}
|
||||
else if (SQLITE_DONE == _nextResponse)
|
||||
{
|
||||
throw Poco::Data::DataException("No data received");
|
||||
}
|
||||
else
|
||||
{
|
||||
int rc = _nextResponse;
|
||||
Utility::throwException(rc, std::string("Iterator Error: trying to access the next value"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Poco::UInt32 SQLiteStatementImpl::columnsReturned() const
|
||||
{
|
||||
return (Poco::UInt32) _columns.size();
|
||||
}
|
||||
|
||||
|
||||
const MetaColumn& SQLiteStatementImpl::metaColumn(Poco::UInt32 pos) const
|
||||
{
|
||||
poco_assert (pos > 0 && pos <= _columns.size());
|
||||
return _columns[pos-1];
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
132
Data/SQLite/src/SessionImpl.cpp
Normal file
132
Data/SQLite/src/SessionImpl.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
//
|
||||
// SessionImpl.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SessionImpl.cpp#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SessionImpl
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SessionImpl.h"
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteStatementImpl.h"
|
||||
#include "sqlite3.h"
|
||||
#include <cstdlib>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const std::string SessionImpl::DEFERRED_BEGIN_TRANSACTION("BEGIN DEFERRED");
|
||||
const std::string SessionImpl::COMMIT_TRANSACTION("COMMIT");
|
||||
const std::string SessionImpl::ABORT_TRANSACTION("ROLLBACK");
|
||||
|
||||
|
||||
SessionImpl::SessionImpl(const std::string& fileName):
|
||||
_dbFileName(fileName),
|
||||
_pDB(0),
|
||||
_connected(false)
|
||||
{
|
||||
open();
|
||||
}
|
||||
|
||||
|
||||
SessionImpl::~SessionImpl()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
Poco::Data::StatementImpl* SessionImpl::createStatementImpl()
|
||||
{
|
||||
poco_check_ptr (_pDB);
|
||||
return new SQLiteStatementImpl(_pDB);
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::begin()
|
||||
{
|
||||
SQLiteStatementImpl tmp(_pDB);
|
||||
tmp.add(DEFERRED_BEGIN_TRANSACTION);
|
||||
tmp.execute();
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::commit()
|
||||
{
|
||||
SQLiteStatementImpl tmp(_pDB);
|
||||
tmp.add(COMMIT_TRANSACTION);
|
||||
tmp.execute();
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::rollback()
|
||||
{
|
||||
SQLiteStatementImpl tmp(_pDB);
|
||||
tmp.add(ABORT_TRANSACTION);
|
||||
tmp.execute();
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::open()
|
||||
{
|
||||
int rc = sqlite3_open(_dbFileName.c_str(), &_pDB);
|
||||
|
||||
if (rc != 0)
|
||||
{
|
||||
close();
|
||||
Utility::throwException(rc);
|
||||
}
|
||||
|
||||
_connected = true;
|
||||
}
|
||||
|
||||
|
||||
void SessionImpl::close()
|
||||
{
|
||||
if (_pDB)
|
||||
{
|
||||
sqlite3_close(_pDB);
|
||||
_pDB = 0;
|
||||
}
|
||||
|
||||
_connected = false;
|
||||
}
|
||||
|
||||
|
||||
bool SessionImpl::isConnected()
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
78
Data/SQLite/src/SessionInstantiator.cpp
Normal file
78
Data/SQLite/src/SessionInstantiator.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
//
|
||||
// SessionInstantiator.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/SessionInstantiator.cpp#2 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: SessionInstantiator
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SessionInstantiator.h"
|
||||
#include "Poco/Data/SQLite/SessionImpl.h"
|
||||
#include "Poco/Data/SessionFactory.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
const std::string SessionInstantiator::KEY("sqlite");
|
||||
|
||||
|
||||
SessionInstantiator::SessionInstantiator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SessionInstantiator::~SessionInstantiator()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Poco::AutoPtr<Poco::Data::SessionImpl> SessionInstantiator::create(const std::string& initString)
|
||||
{
|
||||
return Poco::AutoPtr<Poco::Data::SessionImpl>(new SessionImpl(initString));
|
||||
}
|
||||
|
||||
|
||||
void SessionInstantiator::addToFactory()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().add(KEY, new SessionInstantiator());
|
||||
}
|
||||
|
||||
|
||||
void SessionInstantiator::removeFromFactory()
|
||||
{
|
||||
Poco::Data::SessionFactory::instance().remove(KEY);
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
152
Data/SQLite/src/Utility.cpp
Normal file
152
Data/SQLite/src/Utility.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
//
|
||||
// Utility.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/src/Utility.cpp#4 $
|
||||
//
|
||||
// Library: SQLite
|
||||
// Package: SQLite
|
||||
// Module: Utility
|
||||
//
|
||||
// Implementation of Utility
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/Utility.h"
|
||||
#include "Poco/Data/SQLite/SQLiteException.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include "Poco/String.h"
|
||||
#include "Poco/Exception.h"
|
||||
#include "sqlite3.h"
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
namespace SQLite {
|
||||
|
||||
|
||||
std::string Utility::lastError(sqlite3 *pDB)
|
||||
{
|
||||
return std::string(sqlite3_errmsg(pDB));
|
||||
}
|
||||
|
||||
|
||||
MetaColumn::ColumnDataType Utility::getColumnType(sqlite3_stmt* pStmt, std::size_t pos)
|
||||
{
|
||||
poco_assert_dbg (pStmt);
|
||||
|
||||
const char* pc = sqlite3_column_decltype(pStmt, (int)pos);
|
||||
std::string sqliteType = pc ? pc : "";
|
||||
Poco::toUpperInPlace(sqliteType);
|
||||
|
||||
if (sqliteType.npos != sqliteType.find("INT"))
|
||||
return MetaColumn::FDT_INT32;
|
||||
else if (sqliteType.empty() ||
|
||||
sqliteType.npos != sqliteType.find("CHAR") ||
|
||||
sqliteType.npos != sqliteType.find("CLOB") ||
|
||||
sqliteType.npos != sqliteType.find("TEXT"))
|
||||
return MetaColumn::FDT_STRING;
|
||||
else if (sqliteType.npos != sqliteType.find("REAL") ||
|
||||
sqliteType.npos != sqliteType.find("FLOA") ||
|
||||
sqliteType.npos != sqliteType.find("DOUB"))
|
||||
return MetaColumn::FDT_DOUBLE;
|
||||
else if (sqliteType.npos != sqliteType.find("BLOB"))
|
||||
return MetaColumn::FDT_BLOB;
|
||||
|
||||
throw Poco::NotFoundException();
|
||||
}
|
||||
|
||||
|
||||
void Utility::throwException(int rc, const std::string& addErrMsg)
|
||||
{
|
||||
switch (rc)
|
||||
{
|
||||
case SQLITE_OK:
|
||||
break;
|
||||
case SQLITE_ERROR:
|
||||
throw InvalidSQLStatementException(std::string("SQL error or missing database"), addErrMsg);
|
||||
case SQLITE_INTERNAL:
|
||||
throw InternalDBErrorException(std::string("An internal logic error in SQLite"), addErrMsg);
|
||||
case SQLITE_PERM:
|
||||
throw DBAccessDeniedException(std::string("Access permission denied"), addErrMsg);
|
||||
case SQLITE_ABORT:
|
||||
throw ExecutionAbortedException(std::string("Callback routine requested an abort"), addErrMsg);
|
||||
case SQLITE_BUSY:
|
||||
throw DBLockedException(std::string("The database file is locked"), addErrMsg);
|
||||
case SQLITE_LOCKED:
|
||||
throw TableLockedException(std::string("A table in the database is locked"), addErrMsg);
|
||||
case SQLITE_NOMEM:
|
||||
throw NoMemoryException(std::string("A malloc() failed"), addErrMsg);
|
||||
case SQLITE_READONLY:
|
||||
throw ReadOnlyException(std::string("Attempt to write a readonly database"), addErrMsg);
|
||||
case SQLITE_INTERRUPT:
|
||||
throw InterruptException(std::string("Operation terminated by sqlite_interrupt()"), addErrMsg);
|
||||
case SQLITE_IOERR:
|
||||
throw IOErrorException(std::string("Some kind of disk I/O error occurred"), addErrMsg);
|
||||
case SQLITE_CORRUPT:
|
||||
throw CorruptImageException(std::string("The database disk image is malformed"), addErrMsg);
|
||||
case SQLITE_NOTFOUND:
|
||||
throw TableNotFoundException(std::string("Table or record not found"), addErrMsg);
|
||||
case SQLITE_FULL:
|
||||
throw DatabaseFullException(std::string("Insertion failed because database is full"), addErrMsg);
|
||||
case SQLITE_CANTOPEN:
|
||||
throw CantOpenDBFileException(std::string("Unable to open the database file"), addErrMsg);
|
||||
case SQLITE_PROTOCOL:
|
||||
throw LockProtocolException(std::string("Database lock protocol error"), addErrMsg);
|
||||
case SQLITE_EMPTY:
|
||||
throw InternalDBErrorException(std::string("(Internal Only) Database table is empty"), addErrMsg);
|
||||
case SQLITE_SCHEMA:
|
||||
throw SchemaDiffersException(std::string("The database schema changed"), addErrMsg);
|
||||
case SQLITE_TOOBIG:
|
||||
throw RowTooBigException(std::string("Too much data for one row of a table"), addErrMsg);
|
||||
case SQLITE_CONSTRAINT:
|
||||
throw ConstraintViolationException(std::string("Abort due to constraint violation"), addErrMsg);
|
||||
case SQLITE_MISMATCH:
|
||||
throw DataTypeMismatchException(std::string("Data type mismatch"), addErrMsg);
|
||||
case SQLITE_MISUSE:
|
||||
throw InvalidLibraryUseException(std::string("Library used incorrectly"), addErrMsg);
|
||||
case SQLITE_NOLFS:
|
||||
throw OSFeaturesMissingException(std::string("Uses OS features not supported on host"), addErrMsg);
|
||||
case SQLITE_AUTH:
|
||||
throw AuthorizationDeniedException(std::string("Authorization denied"), addErrMsg);
|
||||
case SQLITE_FORMAT:
|
||||
throw CorruptImageException(std::string("Auxiliary database format error"), addErrMsg);
|
||||
case SQLITE_NOTADB:
|
||||
throw CorruptImageException(std::string("File opened that is not a database file"), addErrMsg);
|
||||
case SQLITE_RANGE:
|
||||
throw InvalidSQLStatementException(std::string("Bind Parameter out of range (Access of invalid position 0? bind starts with 1!)"), addErrMsg);
|
||||
case SQLITE_ROW:
|
||||
break; // sqlite_step() has another row ready
|
||||
case SQLITE_DONE:
|
||||
break; // sqlite_step() has finished executing
|
||||
default:
|
||||
throw SQLiteException(std::string("Unkown error code: ") + Poco::NumberFormatter::format(rc), addErrMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} } } // namespace Poco::Data::SQLite
|
64901
Data/SQLite/src/sqlite3.c
Normal file
64901
Data/SQLite/src/sqlite3.c
Normal file
File diff suppressed because it is too large
Load Diff
1885
Data/SQLite/src/sqlite3.h
Normal file
1885
Data/SQLite/src/sqlite3.h
Normal file
File diff suppressed because it is too large
Load Diff
18
Data/SQLite/testsuite/Makefile
Normal file
18
Data/SQLite/testsuite/Makefile
Normal file
@ -0,0 +1,18 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
# $Id: //poco/Main/Data/SQLite/testsuite/Makefile#1 $
|
||||
#
|
||||
# Makefile for Poco SQLite testsuite
|
||||
#
|
||||
|
||||
include $(POCO_BASE)/build/rules/global
|
||||
|
||||
objects = SQLiteTestSuite Driver \
|
||||
SQLiteTest
|
||||
|
||||
target = testrunner
|
||||
target_version = 1
|
||||
target_libs = PocoSQLite PocoData PocoFoundation CppUnit
|
||||
|
||||
include $(POCO_BASE)/build/rules/exec
|
185
Data/SQLite/testsuite/TestSuite_VS71.vcproj
Normal file
185
Data/SQLite/testsuite/TestSuite_VS71.vcproj
Normal file
@ -0,0 +1,185 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="7.10"
|
||||
Name="TestSuite"
|
||||
ProjectGUID="{1b30a91b-375f-11db-837b-00123fc423b5}"
|
||||
Keyword="Win32Proj">
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"/>
|
||||
</Platforms>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include;..\..\..\Foundation\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="TRUE"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="TRUE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="4"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib PocoDatad.lib PocoSQLited.lib"
|
||||
OutputFile="bin/TestSuited.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="TRUE"
|
||||
ProgramDatabaseFile="bin/TestSuited.pdb"
|
||||
SubSystem="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2">
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="TRUE"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="TRUE"
|
||||
OptimizeForWindowsApplication="TRUE"
|
||||
AdditionalIncludeDirectories="..\include;..\..\..\Foundation\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="TRUE"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="FALSE"
|
||||
TreatWChar_tAsBuiltInType="TRUE"
|
||||
ForceConformanceInForLoopScope="TRUE"
|
||||
RuntimeTypeInfo="TRUE"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="TRUE"
|
||||
DebugInformationFormat="3"/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib PocoData.lib PocoSQLite.lib"
|
||||
OutputFile="bin/TestSuite.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="FALSE"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"/>
|
||||
<Tool
|
||||
Name="VCManagedWrapperGeneratorTool"/>
|
||||
<Tool
|
||||
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="SQLite"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\SQLiteTest.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\SQLiteTest.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="_Suite"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\SQLiteTestSuite.h">
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\SQLiteTestSuite.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="_Driver"
|
||||
Filter="">
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="">
|
||||
<File
|
||||
RelativePath=".\src\WinDriver.cpp">
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
251
Data/SQLite/testsuite/TestSuite_VS80.vcproj
Normal file
251
Data/SQLite/testsuite/TestSuite_VS80.vcproj
Normal file
@ -0,0 +1,251 @@
|
||||
<?xml version="1.0" encoding="Windows-1252"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8,00"
|
||||
Name="TestSuite"
|
||||
ProjectGUID="{1B30A91B-375F-11DB-837B-00123FC423B5}"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="debug_shared|Win32"
|
||||
OutputDirectory="obj\debug_shared"
|
||||
IntermediateDirectory="obj\debug_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories="..\include;..\..\..\Foundation\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
BufferSecurityCheck="true"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="CppUnitd.lib WinTestRunnerd.lib PocoFoundationd.lib PocoSQLited.lib PocoDatad.lib"
|
||||
OutputFile="bin/TestSuited.exe"
|
||||
LinkIncremental="2"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="true"
|
||||
ProgramDatabaseFile="bin/TestSuited.pdb"
|
||||
SubSystem="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="release_shared|Win32"
|
||||
OutputDirectory="obj\release_shared"
|
||||
IntermediateDirectory="obj\release_shared"
|
||||
ConfigurationType="1"
|
||||
UseOfMFC="2"
|
||||
CharacterSet="2"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="4"
|
||||
InlineFunctionExpansion="1"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
OmitFramePointers="true"
|
||||
AdditionalIncludeDirectories="..\include;..\..\..\Foundation\include;..\..\..\CppUnit\include;..\..\..\CppUnit\WinTestRunner\include;..\..\..\Data\include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;POCO_DLL;WINVER=0x0500"
|
||||
StringPooling="true"
|
||||
RuntimeLibrary="2"
|
||||
BufferSecurityCheck="false"
|
||||
TreatWChar_tAsBuiltInType="true"
|
||||
ForceConformanceInForLoopScope="true"
|
||||
RuntimeTypeInfo="true"
|
||||
UsePrecompiledHeader="0"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="CppUnit.lib WinTestRunner.lib PocoFoundation.lib PocoSQLite.lib PocoData.lib"
|
||||
OutputFile="bin/TestSuite.exe"
|
||||
LinkIncremental="1"
|
||||
AdditionalLibraryDirectories="..\..\..\lib"
|
||||
GenerateDebugInformation="false"
|
||||
ProgramDatabaseFile=""
|
||||
SubSystem="2"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="SQLite"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\SQLiteTest.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\SQLiteTest.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="_Suite"
|
||||
>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\SQLiteTestSuite.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\SQLiteTestSuite.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="_Driver"
|
||||
>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\src\WinDriver.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
39
Data/SQLite/testsuite/src/Driver.cpp
Normal file
39
Data/SQLite/testsuite/src/Driver.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
//
|
||||
// Driver.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/Driver.cpp#2 $
|
||||
//
|
||||
// Console-based test driver for Poco SQLite.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "CppUnit/TestRunner.h"
|
||||
#include "SQLiteTestSuite.h"
|
||||
|
||||
|
||||
CppUnitMain(SQLiteTestSuite)
|
1682
Data/SQLite/testsuite/src/SQLiteTest.cpp
Normal file
1682
Data/SQLite/testsuite/src/SQLiteTest.cpp
Normal file
File diff suppressed because it is too large
Load Diff
124
Data/SQLite/testsuite/src/SQLiteTest.h
Normal file
124
Data/SQLite/testsuite/src/SQLiteTest.h
Normal file
@ -0,0 +1,124 @@
|
||||
//
|
||||
// SQLiteTest.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTest.h#2 $
|
||||
//
|
||||
// Definition of the SQLiteTest class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLiteTest_INCLUDED
|
||||
#define SQLiteTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/SQLite/SQLite.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class SQLiteTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
SQLiteTest(const std::string& name);
|
||||
~SQLiteTest();
|
||||
|
||||
void testSimpleAccess();
|
||||
void testInsertCharPointer();
|
||||
void testInsertCharPointer2();
|
||||
void testComplexType();
|
||||
void testSimpleAccessVector();
|
||||
void testComplexTypeVector();
|
||||
void testInsertVector();
|
||||
void testInsertEmptyVector();
|
||||
|
||||
void testInsertSingleBulk();
|
||||
void testInsertSingleBulkVec();
|
||||
|
||||
void testLimit();
|
||||
void testLimitOnce();
|
||||
void testLimitPrepare();
|
||||
void testLimitZero();
|
||||
void testPrepare();
|
||||
|
||||
void testSetSimple();
|
||||
void testSetComplex();
|
||||
void testSetComplexUnique();
|
||||
void testMultiSetSimple();
|
||||
void testMultiSetComplex();
|
||||
void testMapComplex();
|
||||
void testMapComplexUnique();
|
||||
void testMultiMapComplex();
|
||||
void testSelectIntoSingle();
|
||||
void testSelectIntoSingleStep();
|
||||
void testSelectIntoSingleFail();
|
||||
void testLowerLimitOk();
|
||||
void testLowerLimitFail();
|
||||
void testCombinedLimits();
|
||||
void testCombinedIllegalLimits();
|
||||
void testRange();
|
||||
void testIllegalRange();
|
||||
void testSingleSelect();
|
||||
void testEmptyDB();
|
||||
|
||||
void testBLOB();
|
||||
void testBLOBStmt();
|
||||
|
||||
void testTuple1();
|
||||
void testTupleVector1();
|
||||
void testTuple2();
|
||||
void testTupleVector2();
|
||||
void testTuple3();
|
||||
void testTupleVector3();
|
||||
void testTuple4();
|
||||
void testTupleVector4();
|
||||
void testTuple5();
|
||||
void testTupleVector5();
|
||||
void testTuple6();
|
||||
void testTupleVector6();
|
||||
void testTuple7();
|
||||
void testTupleVector7();
|
||||
void testTuple8();
|
||||
void testTupleVector8();
|
||||
void testTuple9();
|
||||
void testTupleVector9();
|
||||
void testTuple10();
|
||||
void testTupleVector10();
|
||||
|
||||
void testInternalExtraction();
|
||||
|
||||
void testTAC();
|
||||
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
static CppUnit::Test* suite();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif // SQLiteTest_INCLUDED
|
44
Data/SQLite/testsuite/src/SQLiteTestSuite.cpp
Normal file
44
Data/SQLite/testsuite/src/SQLiteTestSuite.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
//
|
||||
// SQLiteTestSuite.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTestSuite.cpp#2 $
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "SQLiteTestSuite.h"
|
||||
#include "SQLiteTest.h"
|
||||
|
||||
|
||||
CppUnit::Test* SQLiteTestSuite::suite()
|
||||
{
|
||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SQLiteTestSuite");
|
||||
|
||||
pSuite->addTest(SQLiteTest::suite());
|
||||
|
||||
return pSuite;
|
||||
}
|
49
Data/SQLite/testsuite/src/SQLiteTestSuite.h
Normal file
49
Data/SQLite/testsuite/src/SQLiteTestSuite.h
Normal file
@ -0,0 +1,49 @@
|
||||
//
|
||||
// SQLiteTestSuite.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/SQLiteTestSuite.h#2 $
|
||||
//
|
||||
// Definition of the SQLiteTestSuite class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef SQLiteTestSuite_INCLUDED
|
||||
#define SQLiteTestSuite_INCLUDED
|
||||
|
||||
|
||||
#include "CppUnit/TestSuite.h"
|
||||
|
||||
|
||||
class SQLiteTestSuite
|
||||
{
|
||||
public:
|
||||
static CppUnit::Test* suite();
|
||||
};
|
||||
|
||||
|
||||
#endif // SQLiteTestSuite_INCLUDED
|
50
Data/SQLite/testsuite/src/WinDriver.cpp
Normal file
50
Data/SQLite/testsuite/src/WinDriver.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// WinDriver.cpp
|
||||
//
|
||||
// $Id: //poco/Main/Data/SQLite/testsuite/src/WinDriver.cpp#2 $
|
||||
//
|
||||
// Windows test driver for Poco SQLite.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#include "WinTestRunner/WinTestRunner.h"
|
||||
#include "SQLiteTestSuite.h"
|
||||
|
||||
|
||||
class TestDriver: public CppUnit::WinTestRunnerApp
|
||||
{
|
||||
void TestMain()
|
||||
{
|
||||
CppUnit::WinTestRunner runner;
|
||||
runner.addTest(SQLiteTestSuite::suite());
|
||||
runner.run();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TestDriver theDriver;
|
428
Data/doc/DataDeveloperManual.page
Normal file
428
Data/doc/DataDeveloperManual.page
Normal file
@ -0,0 +1,428 @@
|
||||
POCO Data Developer Guide
|
||||
Data
|
||||
|
||||
!!!Overview
|
||||
Developing one's own <[DataConnector]> implementation is rather straight-forward.
|
||||
Just implement the following interfaces:
|
||||
* Poco::Data::AbstractBinder
|
||||
* Poco::Data::AbstractExtractor
|
||||
* Poco::Data::StatementImpl
|
||||
* Poco::Data::SessionImpl
|
||||
* Poco::Data::SessionInstantiator
|
||||
* optional: Poco::Data::AbstractPreparation
|
||||
|
||||
It is recommended to implement the classes from top to down (ie. start with Binder and Extractor) and to use a namespace that has <[ Poco::Data ]> as parent, e.g.<[ Poco::Data::SQLite ]>.
|
||||
|
||||
!!!AbstractBinder
|
||||
An <[AbstractBinder]> is a class that maps values to placeholders. It is also responsible to bind primitive C++ data types to database
|
||||
data types. The constructor of the subclass should receive everything needed to bind variables to
|
||||
placeholders by position. An example taken from the SQLite implementation would be:
|
||||
|
||||
Binder::Binder(sqlite3_stmt* pStmt):
|
||||
_pStmt(pStmt)
|
||||
{
|
||||
}
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int32& val)
|
||||
{
|
||||
int rc = sqlite3_bind_int(_pStmt, (int)pos, val);
|
||||
checkReturn(rc);
|
||||
}
|
||||
|
||||
void Binder::bind(std::size_t pos, const Poco::Int16& val)
|
||||
{
|
||||
Poco::Int32 tmp = val;
|
||||
bind(pos, tmp);
|
||||
}
|
||||
----
|
||||
SQLite only needs an <*sqlite3_stmt*> as internal state, Int32 is bound via <*sqlite3_bind_int*> and Int16 values are mapped to Int32 values.
|
||||
|
||||
!!Complete Interface
|
||||
All methods are public.
|
||||
|
||||
AbstractBinder();
|
||||
/// Creates the AbstractBinder.
|
||||
|
||||
virtual ~AbstractBinder();
|
||||
/// Destroys the AbstractBinder.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int8 &val) = 0;
|
||||
/// Binds an Int8.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt8 &val) = 0;
|
||||
/// Binds an UInt8.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int16 &val) = 0;
|
||||
/// Binds an Int16.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt16 &val) = 0;
|
||||
/// Binds an UInt16.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int32 &val) = 0;
|
||||
/// Binds an Int32.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt32 &val) = 0;
|
||||
/// Binds an UInt32.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int64 &val) = 0;
|
||||
/// Binds an Int64.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt64 &val) = 0;
|
||||
/// Binds an UInt64.
|
||||
|
||||
virtual void bind(std::size_t pos, const bool &val) = 0;
|
||||
/// Binds a boolean.
|
||||
|
||||
virtual void bind(std::size_t pos, const float &val) = 0;
|
||||
/// Binds a float.
|
||||
|
||||
virtual void bind(std::size_t pos, const double &val) = 0;
|
||||
/// Binds a double.
|
||||
|
||||
virtual void bind(std::size_t pos, const char &val) = 0;
|
||||
/// Binds a single character.
|
||||
|
||||
virtual void bind(std::size_t pos, const char* const &pVal) = 0;
|
||||
/// Binds a const char ptr.
|
||||
|
||||
virtual void bind(std::size_t pos, const std::string& val) = 0;
|
||||
/// Binds a string.
|
||||
|
||||
virtual void bind(std::size_t pos, const BLOB& val) = 0;
|
||||
/// Binds a BLOB.
|
||||
|
||||
virtual void reset() = 0;
|
||||
/// Resets the internal state, called before a rebind
|
||||
----
|
||||
|
||||
!!!AbstractExtractor
|
||||
An <[AbstractExtractor]> takes a result row and extracts from a given position one single value. It performs the reverse operation to the <[AbstractBinder]>,
|
||||
ie. it maps database types to primitive C++ types. An <[AbstractExtractor]> also has to handle null values. If it detects a null value, it is not allowed to modify
|
||||
the incoming value but will simply return false. An example taken from the SQLite implementation:
|
||||
|
||||
Extractor::Extractor(sqlite3_stmt* pStmt):
|
||||
_pStmt(pStmt)
|
||||
{
|
||||
}
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int32& val)
|
||||
{
|
||||
if (isNull(pos<[
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int)pos);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
if (isNull(pos<[
|
||||
return false;
|
||||
val = sqlite3_column_int(_pStmt, (int)pos);
|
||||
return true;
|
||||
}
|
||||
----
|
||||
|
||||
!!Complete Interface
|
||||
All methods are public.
|
||||
|
||||
AbstractExtractor();
|
||||
/// Creates the AbstractExtractor.
|
||||
|
||||
virtual ~AbstractExtractor();
|
||||
/// Destroys the AbstractExtractor.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int8& val) = 0;
|
||||
/// Extracts an Int8. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt8& val) = 0;
|
||||
/// Extracts an UInt8. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int16& val) = 0;
|
||||
/// Extracts an Int16. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt16& val) = 0;
|
||||
/// Extracts an UInt16. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int32& val) = 0;
|
||||
/// Extracts an Int32. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt32& val) = 0;
|
||||
/// Extracts an UInt32. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::Int64& val) = 0;
|
||||
/// Extracts an Int64. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, Poco::UInt64& val) = 0;
|
||||
/// Extracts an UInt64. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, bool& val) = 0;
|
||||
/// Extracts a boolean. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, float& val) = 0;
|
||||
/// Extracts a float. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, double& val) = 0;
|
||||
/// Extracts a double. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, char& val) = 0;
|
||||
/// Extracts a single character. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, std::string& val) = 0;
|
||||
/// Extracts a string. Returns false if null was received.
|
||||
|
||||
virtual bool extract(std::size_t pos, BLOB& val) = 0;
|
||||
/// Extracts a BLOB. Returns false if null was received.
|
||||
----
|
||||
|
||||
!!!AbstractPreparation
|
||||
<[AbstractPreparation]> is an optional interface responsible for preparing an extract. If you need it depends on the <[DataConnector]> you implement. For example, SQLite can do perfectly without it, ODBC instead requires it.
|
||||
SQLite doesn't need it because it works as follows:
|
||||
* sendQuery
|
||||
* getNextResult
|
||||
* extract single row values from result set
|
||||
|
||||
This works because SQLites <*getNextResult*> provides the data as string, i.e. it doesn't need any type information.
|
||||
|
||||
The ODBC implementation is different:
|
||||
* register/prepare for each column an output location
|
||||
* getNextResult
|
||||
* extract for each row the value by copying the content of the previously registered output location
|
||||
|
||||
<[AbstractPreparation]> is responsible for the first step. A typical prepare implementation will look like that:
|
||||
|
||||
void prepare(std::size_t pos, Poco::Int32 val)
|
||||
{
|
||||
_myVec[pos] = Poco::Any a(val);
|
||||
int* i = AnyCast<int>(&_myVec[pos]);
|
||||
//register int* i for output, Db specific
|
||||
}
|
||||
----
|
||||
Extract now changes to:
|
||||
|
||||
bool Extractor::extract(std::size_t pos, Poco::Int16& val)
|
||||
{
|
||||
if (isNull(pos))
|
||||
return false;
|
||||
val = AnyCast<int>(_myVec[pos]);
|
||||
return true;
|
||||
}
|
||||
----
|
||||
|
||||
!!Complete Interface
|
||||
|
||||
AbstractPreparation();
|
||||
/// Creates the AbstractPreparation.
|
||||
|
||||
virtual ~AbstractPreparation();
|
||||
/// Destroys the AbstractPreparation.
|
||||
|
||||
virtual void prepare(std::size_t pos, Poco::Int8) = 0;
|
||||
/// Prepares an Int8.
|
||||
|
||||
virtual void prepare(std::size_t pos, Poco::UInt8) = 0;
|
||||
/// Prepares an UInt8.
|
||||
|
||||
virtual void prepare(std::size_t pos, Poco::Int16) = 0;
|
||||
/// Prepares an Int16.
|
||||
|
||||
virtual void prepare(std::size_t pos, Poco::UInt16) = 0;
|
||||
/// Prepares an UInt16.
|
||||
|
||||
virtual void prepare(std::size_t pos, Poco::Int32) = 0;
|
||||
/// Prepares an Int32.
|
||||
|
||||
virtual void prepare(std::size_t pos, Poco::UInt32) = 0;
|
||||
/// Prepares an UInt32.
|
||||
|
||||
virtual void prepare(std::size_t pos, Poco::Int64) = 0;
|
||||
/// Prepares an Int64.
|
||||
|
||||
virtual void prepare(std::size_t pos, Poco::UInt64) = 0;
|
||||
/// Prepares an UInt64.
|
||||
|
||||
virtual void prepare(std::size_t pos, bool) = 0;
|
||||
/// Prepares a boolean.
|
||||
|
||||
virtual void prepare(std::size_t pos, float) = 0;
|
||||
/// Prepares a float.
|
||||
|
||||
virtual void prepare(std::size_t pos, double) = 0;
|
||||
/// Prepares a double.
|
||||
|
||||
virtual void prepare(std::size_t pos, char) = 0;
|
||||
/// Prepares a single character.
|
||||
|
||||
virtual void prepare(std::size_t pos, const std::string& ) = 0;
|
||||
/// Prepares a string.
|
||||
|
||||
virtual void prepare(std::size_t pos, const BLOB&) = 0;
|
||||
----
|
||||
|
||||
Note that it is recommended to prepare a statement only once in the compileImpl of <[StatementImpl]>. The AbstractPrepare objects (which make use of <[AbstractPreparation]>
|
||||
can be created by iterating over the Extractor objects of the StatementImpl:
|
||||
|
||||
Poco::Data::AbstractExtractingVec::iterator it = extractings().begin();
|
||||
Poco::Data::AbstractExtractingVec::iterator itEnd = extractings().end();
|
||||
std::size_t pos = 0; // sqlite starts with pos 0 for results! your DB maybe with 1
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
AbstractPrepare* pPrep = (*it)->createPrepareObject(pPreparation, pos);
|
||||
_prepareVec.push_back(pPrep);
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
----
|
||||
!!!StatementImpl
|
||||
A <[StatementImpl]> stores as member a Binder and an Extractor (optional a Preparation object) and is responsible for compiling, binding, fetching single rows from the database and invoking the <*Extracting*> objects.
|
||||
The interface it has to implement is given as:
|
||||
|
||||
public:
|
||||
StatementImpl();
|
||||
/// Creates the StatementImpl.
|
||||
|
||||
virtual ~StatementImpl();
|
||||
/// Destroys the StatementImpl.
|
||||
|
||||
protected:
|
||||
virtual bool hasNext() = 0;
|
||||
/// Returns true if a call to next() will return data. Note that the
|
||||
/// implementation must support several consecutive calls to hasNext
|
||||
/// without data getting lost, ie. hasNext(); hasNext(); next() must
|
||||
/// be equal to hasNext(); next();
|
||||
|
||||
virtual void next() = 0;
|
||||
/// Retrieves the next row from the resultset.
|
||||
/// Will throw, if the resultset is empty.
|
||||
/// Expects the statement to be compiled and bound
|
||||
|
||||
virtual bool canBind() const = 0;
|
||||
/// Returns if another bind is possible.
|
||||
|
||||
virtual void compileImpl() = 0;
|
||||
/// Compiles the statement, doesn't bind yet.
|
||||
/// From now on AbstractBinder and AbstractExtractor
|
||||
/// will be used
|
||||
|
||||
virtual void bindImpl() = 0;
|
||||
/// Binds parameters.
|
||||
|
||||
virtual AbstractExtractor& extractor() = 0;
|
||||
/// Returns the concrete extractor used by the statement.
|
||||
|
||||
virtual AbstractBinder& binder() = 0;
|
||||
/// Returns the concrete binder used by the statement.
|
||||
----
|
||||
|
||||
The Extracting and Binding objects can be accessed via the calls to the super-class methods <*extractings()*> and <*bindings()*>.
|
||||
A high-level <*bind*> implementation will look like this:
|
||||
|
||||
[...]
|
||||
Poco::Data::AbstractBindingVec& binds = bindings();
|
||||
std::size_t pos = 1; // or 0 depending on your database
|
||||
Poco::Data::AbstractBindingVec::iterator it = binds.begin();
|
||||
Poco::Data::AbstractBindingVec::iterator itEnd = binds.end();
|
||||
for (; it != itEnd && (*it)->canBind(); ++it)
|
||||
{
|
||||
(*it)->bind(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
----
|
||||
|
||||
A high-level <*next*> implementation:
|
||||
|
||||
if (!hasNext())
|
||||
throw Poco::Data::DataException("No data received");
|
||||
int nCol = countColumnsInResult...;
|
||||
poco_assert (columnsHandled() == nCol);
|
||||
Poco::Data::AbstractExtractingVec::iterator it = extractings().begin();
|
||||
Poco::Data::AbstractExtractingVec::iterator itEnd = extractings().end();
|
||||
std::size_t pos = 0; // sqlite starts with pos 0 for results! your DB maybe with 1
|
||||
for (; it != itEnd; ++it)
|
||||
{
|
||||
(*it)->extract(pos);
|
||||
pos += (*it)->numOfColumnsHandled();
|
||||
}
|
||||
enableHasNext();
|
||||
----
|
||||
|
||||
A high-level <*hasNext*> implementation:
|
||||
|
||||
if (enabledhasNext())
|
||||
{
|
||||
checkIfItHasMoreData
|
||||
cacheResult
|
||||
disablehasNext()
|
||||
}
|
||||
|
||||
return cachedResult;
|
||||
----
|
||||
|
||||
A high-level <*compileImpl*>:
|
||||
|
||||
if (compiled)
|
||||
return;
|
||||
|
||||
std::string sqlStmt(toString());
|
||||
|
||||
if database expects placeholders in different format than ":name", parse and replace them
|
||||
|
||||
compile statement;
|
||||
|
||||
create Binder;
|
||||
create Extractor;
|
||||
----
|
||||
|
||||
A high-level <*canBind*>:
|
||||
|
||||
bool ret = false;
|
||||
if (!bindings().empty() && validCompiledStatement)
|
||||
ret = (*bindings().begin())->canBind();
|
||||
|
||||
return ret;
|
||||
----
|
||||
|
||||
!!!SessionImpl
|
||||
The purpose of the <[SessionImpl]> is simply to open/close a connection to the database, to act as factory for <[StatementImpl]> objects, and to handle transactions.
|
||||
The connection is opened in the constructor, and closed in the destructor.
|
||||
|
||||
Poco::Data::StatementImpl* createStatementImpl();
|
||||
/// Returns an SQLite StatementImpl
|
||||
|
||||
void begin();
|
||||
/// Starts a transaction
|
||||
|
||||
void commit();
|
||||
/// Commits and ends a transaction
|
||||
|
||||
void rollback();
|
||||
/// Aborts a transaction
|
||||
----
|
||||
|
||||
!!!SessionInstantiator
|
||||
Finally, one needs to implement the <[SessionInstantiator]>.
|
||||
Each <[SessionInstantiator]> should have a public static const string member named <*KEY*> and must have a factory method to <*create*> <[ Poco::AutoPtr ]> objects of type <[SessionImpl]>.
|
||||
It should also have a static <*addToFactory()*> and a static <*removeFromFactory()*> method:
|
||||
|
||||
class My_API SessionInstantiator: public Poco::Data::SessionInstantiator
|
||||
/// SessionInstantiator instantiates SessionImpl objects.
|
||||
{
|
||||
public:
|
||||
static const std::string KEY;
|
||||
/// Keyword for creating sessions
|
||||
|
||||
SessionInstantiator();
|
||||
/// Creates the SessionInstantiator.
|
||||
|
||||
~SessionInstantiator();
|
||||
/// Destroys the SessionInstantiator.
|
||||
|
||||
Poco::AutoPtr < Poco::Data::SessionImpl > create(const std::string& initString);
|
||||
/// Creates a SessionImpl object and initializes it with the given initString.
|
||||
|
||||
static void addToFactory();
|
||||
/// Registers the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory
|
||||
|
||||
static void removeFromFactory();
|
||||
/// Unregisters the SessionInstantiator under the Keyword SessionInstantiator::KEY at the Poco::Data::SessionFactory
|
||||
};
|
||||
----
|
372
Data/doc/DataUserManual.page
Normal file
372
Data/doc/DataUserManual.page
Normal file
@ -0,0 +1,372 @@
|
||||
POCO Data User Guide
|
||||
Data
|
||||
|
||||
!!!First Steps
|
||||
PocoData is POCO's database abstraction layer which allows users to easily send/retrieve data to/from various different databases.
|
||||
The following complete example shows how to use it:
|
||||
|
||||
|
||||
#include "Poco/Data/Common.h"
|
||||
#include "Poco/Data/SQLite/SessionInstantiator.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace Poco::Data;
|
||||
|
||||
|
||||
void init()
|
||||
{
|
||||
SQLite::SessionInstantiator::addToFactory();
|
||||
}
|
||||
|
||||
|
||||
void shutdown()
|
||||
{
|
||||
SQLite::SessionInstantiator::removeFromFactory();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
init();
|
||||
Session ses (SessionFactory::instance().create(SQLite::SessionInstantiator::KEY, "dummy.db"));
|
||||
int count = 0;
|
||||
ses << "SELECT COUNT(*) FROM PERSON", into(count), now;
|
||||
std::cout << "People in DB " << count;
|
||||
shutdown();
|
||||
}
|
||||
----
|
||||
|
||||
The above example is pretty much self explanatory. The <[Poco/Data/Common.h]> file pulls in some common includes,
|
||||
the SQLite::SessionInstantiator is used to initialize the SQLite package so that we can later create an SQLite session
|
||||
via the SessionFactory (note that <[ SQLite::SessionInstantiator::KEY ]> is simply the string "sqlite").
|
||||
The << operator is used to send SQL statements to the Session, the <*into(count)*> simply informs the session where to store the result of the query.
|
||||
Take note of the __now__ at the end of the SQL statement. It is required, otherwise the statement would not be executed.
|
||||
The <* <[ using namespace Poco::Data ]> *> is for convenience only but highly recommended for good readable code (while <* <[ ses << "SELECT COUNT(*) FROM PERSON", Poco::Data::into(count), Poco::Data::now; ]> *> is valid, it simply looks... strange).
|
||||
|
||||
The remainder of this tutorial is split up into the following parts:
|
||||
* Creating Sessions
|
||||
* Inserting and Retrieving Data: the magic of <* into *> and <*use*>
|
||||
* Working with Statements
|
||||
* Working with Collections: vector, set, multiset, map and multimap
|
||||
* Working with Limits
|
||||
* Working with complex data types: how to map C++ objects to a database table
|
||||
|
||||
!!!Creating Sessions
|
||||
Sessions are always created via the SessionFactory create method:
|
||||
|
||||
Session create(const std::string& dbType, const std::string& initParams);
|
||||
----
|
||||
The first parameter contains the type of the Session one wants to create, for the moment "sqlite" is supported and via the ODBC driver we support Oracle, SQLite, DB2, SQLServer and PostgreSQL. The second parameter contains the initialization string.
|
||||
In the case of SQLite, the location of the database file is sufficient.
|
||||
|
||||
!!!Inserting and Retrieving Data
|
||||
Inserting data works by <* using *> the content of other variables. Assume we have a table that stores only forenames:
|
||||
|
||||
ForeName (Name VARCHAR(30))
|
||||
----
|
||||
If we want to insert one single forename we could simply write:
|
||||
|
||||
std::string aName("Peter");
|
||||
ses << "INSERT INTO FORENAME VALUES(" << aName << ")", now;
|
||||
----
|
||||
|
||||
Well, we could do that, but we won't. A much better solution is to use <!placeholders!> and connect each placeholder via a <!use!> expression with a variable that will provide the value during execution. Placeholders are recognized by having a <!:!> in front of their name. Rewriting the above code now simply gives
|
||||
|
||||
std::string aName("Peter");
|
||||
ses << "INSERT INTO FORENAME VALUES(:name)", use(aName), now;
|
||||
----
|
||||
|
||||
In this example the <!use!> expression matches the <* :name *> with the <*Peter*> value. Note that apart from the nicer syntax, the real benefit of placeholders - which is performance - doesn't show here. Check the <*Working with Statements*> section to find out more.
|
||||
|
||||
Retrieving data from the Database works similar. The <!into!> expression matches the returned database values to C++ objects, it also allows to provide a default value in case null data is returned from the database:
|
||||
|
||||
std::string aName;
|
||||
ses << "SELECT NAME FROM FORENAME", into(aName), now; // the default is the empty string
|
||||
ses << "SELECT NAME FROM FORENAME", into(aName, "default"), now;
|
||||
----
|
||||
|
||||
It is also possible to combine into and use expressions:
|
||||
|
||||
std::string aName;
|
||||
std::string match("Peter")
|
||||
ses << "SELECT NAME FROM FORENAME WHERE NAME=:name", into(aName), use(match), now;
|
||||
poco_assert (aName == match);
|
||||
----
|
||||
|
||||
Typically, tables will not be so trivial, ie. they will have more than one column which allows for more than one into/use.
|
||||
Lets assume we have a Person table that contains an age, a first and a last name:
|
||||
|
||||
std::string firstName("Peter";
|
||||
std::string lastName("Junior");
|
||||
int age = 0;
|
||||
ses << INSERT INTO PERSON VALUES (:fn, :ln, :age)", use(firstName), use(lastName), use(age), now;
|
||||
ses << "SELECT (firstname, lastname, age) FROM Person", into(firstName), into(lastName), into(age), now;
|
||||
----
|
||||
|
||||
Most important here is the <!order!> of the into and use expressions. The first placeholder is matched by the first <*use*>, the 2nd by the 2nd <*use*> etc.
|
||||
The same is true for the <*into*> statement. We select <*firstname*> as the first column of the result set, thus <*into(firstName)*> must be the first into clause.
|
||||
|
||||
!! Handling NULL entries
|
||||
A common case with databases are optional data fields that can contain NULL. To accomodate for NULL, the <*into*> expression allows you to define default values.
|
||||
For example, assume that age is such an optional field and we want to provide as default value <!-1!> which is done by writing <!into(age, -1)!>:
|
||||
|
||||
std::string firstName("Peter";
|
||||
std::string lastName("Junior");
|
||||
int age = 0;
|
||||
ses << INSERT INTO PERSON VALUES (:fn, :ln, :age)", use(firstName), use(lastName), use(age), now;
|
||||
ses << "SELECT (firstname, lastname, age) FROM Person", into(firstName), into(lastName), into(age, -1), now;
|
||||
----
|
||||
|
||||
While you can achieve the same effect by initializing age previously to -1 (<*int age = -1*>), this won't work with collection types. Here you must provide the second parameter
|
||||
to init. Otherwise, values will be initialized to compiler specific values.
|
||||
|
||||
!!!Working with Statements
|
||||
We often mentioned the term <*Statement*> in the previous section, yet we only worked with database session objects so far, or at least, that's what I made you believe ;-).
|
||||
In reality, you have already worked with Statements. Lets take a look at the method signature of the << operator at Session:
|
||||
|
||||
template <typename T>
|
||||
Statement Session::operator << (const T& t)
|
||||
----
|
||||
|
||||
Simply ignore the template stuff in front, you won't need it. The only thing that counts here is that the operator <[ << ]> creates a <*Statement*> internally and returns it.
|
||||
What happened in the previous examples is that the returned Statement was never assigned to a variable but simply passed on to the <*now*> part which executed the statement. Afterwards the statement was destroyed.
|
||||
Let's take one of the previous examples and change it so that we assign the statement:
|
||||
|
||||
std::string aName("Peter");
|
||||
Statement stmt = ( ses << "INSERT INTO FORENAME VALUES(:name)", use(aName) );
|
||||
----
|
||||
Note that we must put brackets around the right part of the assignment, otherwise the compiler will complain.
|
||||
What did we achieve by assigning the statement to a variable? Well, currently nothing, apart that we can control when to <*execute*>:
|
||||
|
||||
std::string aName("Peter");
|
||||
Statement stmt = ( ses << "INSERT INTO FORENAME VALUES(:name)", use(aName) );
|
||||
stmt.execute();
|
||||
poco_assert (stmt.done());
|
||||
----
|
||||
By calling <*execute*> we asserted that our query was executed and that the value was inserted. The check to stmt.done()
|
||||
simply guarantees that the statement was fully completed.
|
||||
|
||||
!!Prepared Statements
|
||||
A prepared statement is created by omitting the <*now*> clause.
|
||||
|
||||
Statement stmt = ( ses << "INSERT INTO FORENAME VALUES(:name)", use(aName) );
|
||||
----
|
||||
The advantage of a prepared statement is performance. Assume the following loop:
|
||||
|
||||
std::string aName();
|
||||
Statement stmt = ( ses << "INSERT INTO FORENAME VALUES(:name)", use(aName) );
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
aName.append("x");
|
||||
stmt.execute();
|
||||
}
|
||||
----
|
||||
Instead of creating and parsing the Statement 100 times, we only do this once and then use the placeholder in combination with the <*use*> clause
|
||||
to insert 100 different values into the database.
|
||||
Still, this isn't the best way to insert a collection of values into a database.
|
||||
|
||||
!!Things NOT To Do
|
||||
<*use*> expects as input a <!reference!> parameter, which is bound later during execution. Thus, one can only use variables, but never constants.
|
||||
The following code will very likely fail (but this is platform/compiler dependent and also depends if your building in release or debug mode, it will work from Monday to Thursday but will always fail on Friday, so shortly spoken: the kind of bugs
|
||||
software developers REALLY love):
|
||||
|
||||
Statement stmt = (ses << INSERT INTO PERSON VALUES (:fn, :ln, :age)", use("Peter"), use("Junior"), use(4)); //ERR!
|
||||
stmt.execute();
|
||||
----
|
||||
The constant values <*Junior*>, <*Peter*> and <*4*> must be assigned to variables prior, otherwise their values will be invalid when execute is called.
|
||||
|
||||
!!!Collection Support
|
||||
If one needs to handle many values at once, one ought to use a collection class.
|
||||
Per default we support the following collection types:
|
||||
* vector: no requirements
|
||||
* set: the < operator must be supported by the datatype. Note that duplicate key/value pairs are ignored.
|
||||
* multiset: the < operator must be supported by the datatype
|
||||
* map: the () operator must be supported by the datatype and return the key of the object. Note that duplicate key/value pairs are ignored.
|
||||
* multimap: the () operator must be supported by the datatype and return the key of the object
|
||||
|
||||
A bulk insert example via vector would be:
|
||||
|
||||
std::string aName("");
|
||||
std::vector<std::string> data;
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
aName.append("x");
|
||||
data.push_back(aName);
|
||||
}
|
||||
ses << "INSERT INTO FORENAME VALUES(:name)", use(data), now;
|
||||
----
|
||||
|
||||
The same example would work with set or multiset but not with map and multimap (std::string has no () operator).
|
||||
Note that <*use*> requires <!non-empty!> collections!
|
||||
|
||||
Now reconsider the following example:
|
||||
|
||||
std::string aName;
|
||||
ses << "SELECT NAME FROM FORENAME", into(aName), now;
|
||||
----
|
||||
Previously, it worked because the table contained only one single entry but now the database table contains at least 100 strings, yet we only offer storage space for one single result.
|
||||
Thus, the above code will fail and throw an exception.
|
||||
One possible way to handle this is:
|
||||
|
||||
std::vector<std::string> names;
|
||||
ses << "SELECT NAME FROM FORENAME", into(names), now;
|
||||
----
|
||||
|
||||
And again, instead of vector, one could use set or multiset.
|
||||
|
||||
!!!The limit clause
|
||||
Working with collections might be convenient to bulk process data but there is also the risk that large operations will block your application for a very long time. In addition, you might want to have better fine-grained control over your query, e.g. you only want to extract a subset of data until a condition is met.
|
||||
To elevate that problem, one can use the <!limit!> keyword.
|
||||
|
||||
Let's assume we are retrieving thousands of rows from a database to render the data to a GUI. To allow the user to stop fetching data any time (and to avoid having the user franatically click inside the GUI because it doesn't show anything for seconds), we have to partition this process:
|
||||
|
||||
std::vector<std::string> names;
|
||||
ses << "SELECT NAME FROM FORENAME", into(names), limit(50), now;
|
||||
----
|
||||
|
||||
The above example will retrieve up to 50 rows from the database (note that returning nothing is valid!) and <*append*> it to the names collection, i.e. the collection is not cleared!
|
||||
If one wants to make sure that <!exactly!> 50 rows are returned one must set the 2nd limit parameter (which per default is set to <*false*>) to <*true*>:
|
||||
|
||||
std::vector<std::string> names;
|
||||
ses << "SELECT NAME FROM FORENAME", into(names), limit(50, true), now;
|
||||
----
|
||||
|
||||
Iterating over a complete result collection is done via the Statement object until statement.done() returns true.
|
||||
For the next example, we assume that our system knows about 101 forenames:
|
||||
|
||||
std::vector<std::string> names;
|
||||
Statement stmt = (ses << "SELECT NAME FROM FORENAME", into(names), limit(50));
|
||||
stmt.execute(); //names.size() == 50
|
||||
poco_assert (!stmt.done());
|
||||
stmt.execute(); //names.size() == 100
|
||||
poco_assert (!stmt.done());
|
||||
stmt.execute(); //names.size() == 101
|
||||
poco_assert (stmt.done());
|
||||
----
|
||||
|
||||
We previously stated that if no data is returned this is valid too. Thus, executing the following statement on an
|
||||
empty database table will work:
|
||||
|
||||
std::string aName;
|
||||
ses << "SELECT NAME FROM FORENAME", into(aName), now;
|
||||
----
|
||||
|
||||
To guarantee that at least one valid result row is returned use the <!lowerLimit!> clause:
|
||||
|
||||
std::string aName;
|
||||
ses << "SELECT NAME FROM FORENAME", into(aName), lowerLimit(1), now;
|
||||
----
|
||||
If the table is now empty, an exception will be thrown. If the query succeeds, aName is guaranteed to be initialized.
|
||||
Note that <!limit!> is only the short name for <!upperLimit!>. To iterate over a result set step-by-step, e.g. one wants to avoid using a collection class, one would write
|
||||
|
||||
std::string aName;
|
||||
Statement stmt = (ses << "SELECT NAME FROM FORENAME", into(aName), lowerLimit(1), upperLimit(1));
|
||||
while (!stmt.done())
|
||||
stmt.execute();
|
||||
----
|
||||
|
||||
And for the lazy ones, there is the <!range!> command:
|
||||
|
||||
std::string aName;
|
||||
Statement stmt = (ses << "SELECT NAME FROM FORENAME", into(aName), range(1,1));
|
||||
while (!stmt.done())
|
||||
stmt.execute();
|
||||
----
|
||||
The third parameter to range is an optional boolean value which specifies if the upper limit is a hard limit, ie. if the amount of rows returned by the query must match exactly. Per default exact matching is off.
|
||||
|
||||
!!!Complex Data Type Mapping
|
||||
All the previous examples were contented to work with only the most basic data types: integer, string, ...
|
||||
a situation, unlikely to occur in real-world scenarios.
|
||||
Assume you have a class Person:
|
||||
|
||||
class Person
|
||||
{
|
||||
public:
|
||||
// default constructor+destr.
|
||||
// getter and setter methods for all members
|
||||
[...]
|
||||
|
||||
bool operator <(const Person& p) const
|
||||
/// we need this for set and multiset support
|
||||
{
|
||||
return _socialSecNr < p._socialSecNr;
|
||||
}
|
||||
|
||||
Poco::UInt64 operator()() const
|
||||
/// we need this operator to return the key for the map and multimap
|
||||
{
|
||||
return _socialSecNr;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _firstName;
|
||||
std::string _lastName;
|
||||
Poco::UInt64 _socialSecNr;
|
||||
}
|
||||
----
|
||||
|
||||
Ideally, one would like to use a Person as simple as one used a string. All that is needed is a template specialization of the <*TypeHandler*> template. Note that template specializations must be declared in the
|
||||
<!same namespace!> as the original template, i.e. <*Poco::Data*>. The template specialization must implement the following methods:
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
template <>
|
||||
class TypeHandler<class Person>
|
||||
{
|
||||
public:
|
||||
static void bind(std::size_t pos, const Person& obj, AbstractBinder* pBinder)
|
||||
{
|
||||
poco_assert_dbg (pBinder != 0);
|
||||
// the table is defined as Person (FirstName VARCHAR(30), lastName VARCHAR, SocialSecNr INTEGER(3))
|
||||
// Note that we advance pos by the number of columns the datatype uses! For string/int this is one.
|
||||
TypeHandler<std::string>::bind(pos++, obj.getFirstName(), pBinder);
|
||||
TypeHandler<std::string>::bind(pos++, obj.getLastName(), pBinder);
|
||||
TypeHandler<Poco::UInt64>::bind(pos++, obj.getSocialSecNr(), pBinder);
|
||||
}
|
||||
|
||||
static std::size_t size()
|
||||
{
|
||||
return 3; // we handle three columns of the Table!
|
||||
}
|
||||
|
||||
static void prepare(std::size_t pos, const Person& obj, AbstractPreparation* pPrepare)
|
||||
{
|
||||
poco_assert_dbg (pBinder != 0);
|
||||
// the table is defined as Person (FirstName VARCHAR(30), lastName VARCHAR, SocialSecNr INTEGER(3))
|
||||
// Note that we advance pos by the number of columns the datatype uses! For string/int this is one.
|
||||
TypeHandler<std::string>::prepare(pos++, obj.getFirstName(), pPrepare);
|
||||
TypeHandler<std::string>::prepare(pos++, obj.getLastName(), pPrepare);
|
||||
TypeHandler<Poco::UInt64>::prepare(pos++, obj.getSocialSecNr(), pPrepare);
|
||||
}
|
||||
|
||||
static void extract(std::size_t pos, Person& obj, const Person& defVal, AbstractExtractor* pExt)
|
||||
/// obj will contain the result, defVal contains values we should use when one column is NULL
|
||||
{
|
||||
poco_assert_dbg (pExt != 0);
|
||||
std::string firstName;
|
||||
std::string lastName;
|
||||
Poco::UInt64 socialSecNr = 0;
|
||||
TypeHandler<std::string>::extract(pos++, firstName, defVal.getFirstName(), pExt);
|
||||
TypeHandler<std::string>::extract(pos++, lastName, defVal.getLastName(), pExt);
|
||||
TypeHandler<Poco::UInt64>::extract(pos++, socialSecNr, defVal.getSocialSecNr(), pExt);
|
||||
obj.setFirstName(firstName);
|
||||
obj.setLastName(lastName);
|
||||
obj.setSocialSecNr(socialSecNr);
|
||||
}
|
||||
|
||||
private:
|
||||
TypeHandler();
|
||||
~TypeHandler();
|
||||
TypeHandler(const TypeHandler&);
|
||||
TypeHandler& operator=(const TypeHandler&);
|
||||
};
|
||||
|
||||
} } // namespace Poco::Data
|
||||
----
|
||||
|
||||
And that's all you have to do. Working with Person is now as simple as working with a string:
|
||||
|
||||
std::map<Poco::UInt64, Person> people;
|
||||
ses << "SELECT * FROM Person", into(people), now;
|
||||
----
|
3
Data/doc/info.txt
Normal file
3
Data/doc/info.txt
Normal file
@ -0,0 +1,3 @@
|
||||
For the latest version of the documentation go to
|
||||
|
||||
http://appinf.com/poco/wiki/tiki-index.php?page=Data
|
115
Data/include/Poco/Data/AbstractBinder.h
Normal file
115
Data/include/Poco/Data/AbstractBinder.h
Normal file
@ -0,0 +1,115 @@
|
||||
//
|
||||
// AbstractBinder.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/include/Poco/Data/AbstractBinder.h#10 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: DataCore
|
||||
// Module: AbstractBinder
|
||||
//
|
||||
// Definition of the AbstractBinder class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_AbstractBinder_INCLUDED
|
||||
#define Data_AbstractBinder_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/Data.h"
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
|
||||
class BLOB;
|
||||
|
||||
|
||||
class Data_API AbstractBinder
|
||||
/// Interface for Binding data types to placeholders. The default placeholder format
|
||||
/// in the SQL query is ":name".
|
||||
{
|
||||
public:
|
||||
AbstractBinder();
|
||||
/// Creates the AbstractBinder.
|
||||
|
||||
virtual ~AbstractBinder();
|
||||
/// Destroys the AbstractBinder.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int8& val) = 0;
|
||||
/// Binds an Int8.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt8& val) = 0;
|
||||
/// Binds an UInt8.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int16& val) = 0;
|
||||
/// Binds an Int16.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt16& val) = 0;
|
||||
/// Binds an UInt16.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int32& val) = 0;
|
||||
/// Binds an Int32.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt32& val) = 0;
|
||||
/// Binds an UInt32.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::Int64& val) = 0;
|
||||
/// Binds an Int64.
|
||||
|
||||
virtual void bind(std::size_t pos, const Poco::UInt64& val) = 0;
|
||||
/// Binds an UInt64.
|
||||
|
||||
virtual void bind(std::size_t pos, const bool& val) = 0;
|
||||
/// Binds a boolean.
|
||||
|
||||
virtual void bind(std::size_t pos, const float& val) = 0;
|
||||
/// Binds a float.
|
||||
|
||||
virtual void bind(std::size_t pos, const double& val) = 0;
|
||||
/// Binds a double.
|
||||
|
||||
virtual void bind(std::size_t pos, const char& val) = 0;
|
||||
/// Binds a single character.
|
||||
|
||||
virtual void bind(std::size_t pos, const char* const &pVal) = 0;
|
||||
/// Binds a const char ptr.
|
||||
|
||||
virtual void bind(std::size_t pos, const std::string& val) = 0;
|
||||
/// Binds a string.
|
||||
|
||||
virtual void bind(std::size_t pos, const BLOB& val) = 0;
|
||||
/// Binds a BLOB.
|
||||
};
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
#endif // Data_AbstractBinder_INCLUDED
|
122
Data/include/Poco/Data/AbstractBinding.h
Normal file
122
Data/include/Poco/Data/AbstractBinding.h
Normal file
@ -0,0 +1,122 @@
|
||||
//
|
||||
// AbstractBinding.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/include/Poco/Data/AbstractBinding.h#4 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: DataCore
|
||||
// Module: AbstractBinding
|
||||
//
|
||||
// Definition of the AbstractBinding class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_AbstractBinding_INCLUDED
|
||||
#define Data_AbstractBinding_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/Data.h"
|
||||
#include "Poco/Any.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
|
||||
class AbstractBinder;
|
||||
|
||||
|
||||
class Data_API AbstractBinding: public Poco::RefCountedObject
|
||||
/// AbstractBinding connects a value with a placeholder via an AbstractBinder interface.
|
||||
{
|
||||
public:
|
||||
AbstractBinding();
|
||||
/// Creates the AbstractBinding.
|
||||
|
||||
virtual ~AbstractBinding();
|
||||
/// Destroys the AbstractBinding.
|
||||
|
||||
void setBinder(AbstractBinder* pBinder);
|
||||
/// Sets the object used for binding; object does NOT take ownership of the pointer.
|
||||
|
||||
AbstractBinder* getBinder() const;
|
||||
/// Returns the AbstractBinder used for binding data.
|
||||
|
||||
virtual std::size_t numOfColumnsHandled() const = 0;
|
||||
/// Returns the number of columns that the binding handles.
|
||||
///
|
||||
/// The trivial case will be one single column but when
|
||||
/// complex types are used this value can be larger than one.
|
||||
|
||||
virtual std::size_t numOfRowsHandled() const = 0;
|
||||
/// Returns the number of rows that the binding handles.
|
||||
///
|
||||
/// The trivial case will be one single row but
|
||||
/// for collection data types (ie vector) it can be larger.
|
||||
|
||||
virtual bool canBind() const = 0;
|
||||
/// Returns true if we have enough data to bind
|
||||
|
||||
virtual void bind(std::size_t pos) = 0;
|
||||
/// Binds a value to the given column position
|
||||
|
||||
virtual void reset() = 0;
|
||||
/// Allows a binding to be reused.
|
||||
|
||||
private:
|
||||
AbstractBinder* _pBinder;
|
||||
};
|
||||
|
||||
|
||||
typedef Poco::AutoPtr<AbstractBinding> AbstractBindingPtr;
|
||||
typedef std::vector<AbstractBindingPtr> AbstractBindingVec;
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void AbstractBinding::setBinder(AbstractBinder* pBinder)
|
||||
{
|
||||
_pBinder = pBinder;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractBinder* AbstractBinding::getBinder() const
|
||||
{
|
||||
return _pBinder;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
#endif // Data_AbstractBinding_INCLUDED
|
149
Data/include/Poco/Data/AbstractExtraction.h
Normal file
149
Data/include/Poco/Data/AbstractExtraction.h
Normal file
@ -0,0 +1,149 @@
|
||||
//
|
||||
// AbstractExtraction.h
|
||||
//
|
||||
// $Id: //poco/Main/Data/include/Poco/Data/AbstractExtraction.h#5 $
|
||||
//
|
||||
// Library: Data
|
||||
// Package: DataCore
|
||||
// Module: AbstractExtraction
|
||||
//
|
||||
// Definition of the AbstractExtraction class.
|
||||
//
|
||||
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
|
||||
// and Contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person or organization
|
||||
// obtaining a copy of the software and accompanying documentation covered by
|
||||
// this license (the "Software") to use, reproduce, display, distribute,
|
||||
// execute, and transmit the Software, and to prepare derivative works of the
|
||||
// Software, and to permit third-parties to whom the Software is furnished to
|
||||
// do so, all subject to the following:
|
||||
//
|
||||
// The copyright notices in the Software and this entire statement, including
|
||||
// the above license grant, this restriction and the following disclaimer,
|
||||
// must be included in all copies of the Software, in whole or in part, and
|
||||
// all derivative works of the Software, unless such copies or derivative
|
||||
// works are solely in the form of machine-executable object code generated by
|
||||
// a source language processor.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef Data_AbstractExtraction_INCLUDED
|
||||
#define Data_AbstractExtraction_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Data/Data.h"
|
||||
#include "Poco/Data/AbstractExtractor.h"
|
||||
#include "Poco/Data/Limit.h"
|
||||
#include "Poco/RefCountedObject.h"
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace Poco {
|
||||
namespace Data {
|
||||
|
||||
|
||||
class AbstractPrepare;
|
||||
class AbstractPreparation;
|
||||
|
||||
|
||||
class Data_API AbstractExtraction: public Poco::RefCountedObject
|
||||
/// AbstractExtraction is the interface class that connects output positions to concrete values
|
||||
/// retrieved via an AbstractExtractor.
|
||||
{
|
||||
public:
|
||||
AbstractExtraction(Poco::UInt32 limit = Limit::LIMIT_UNLIMITED);
|
||||
/// Creates the AbstractExtraction. A limit value equal to EXTRACT_UNLIMITED (0xffffffffu)
|
||||
/// means that we extract as much data as possible during one execute.
|
||||
/// Otherwise the limit value is used to partition data extracting to a limited amount of rows.
|
||||
|
||||
virtual ~AbstractExtraction();
|
||||
/// Destroys the AbstractExtraction.
|
||||
|
||||
void setExtractor(AbstractExtractor* pExtractor);
|
||||
/// Sets the class used for extracting the data. Does not take ownership of the pointer.
|
||||
|
||||
AbstractExtractor* getExtractor() const;
|
||||
/// Retrieves the extractor object
|
||||
|
||||
virtual std::size_t numOfColumnsHandled() const = 0;
|
||||
/// Returns the number of columns that the extraction handles.
|
||||
///
|
||||
/// The trivial case will be one single column but when
|
||||
/// complex types are used this value can be larger than one.
|
||||
|
||||
virtual std::size_t numOfRowsHandled() const = 0;
|
||||
/// Returns the number of rows that the extraction handles.
|
||||
///
|
||||
/// The trivial case will be one single row but
|
||||
/// for collection data types (ie vector) it can be larger.
|
||||
|
||||
virtual std::size_t numOfRowsAllowed() const = 0;
|
||||
/// Returns the upper limit on number of rows that the extraction will handle.
|
||||
|
||||
virtual void extract(std::size_t pos) = 0;
|
||||
/// Extracts a value from the param, starting at the given column position.
|
||||
|
||||
virtual void reset() = 0;
|
||||
/// Resets the etxractor so that it can be re-used.
|
||||
|
||||
virtual AbstractPrepare* createPrepareObject(AbstractPreparation* pPrep, std::size_t pos) const = 0;
|
||||
/// Creates a Prepare object for the etxracting object
|
||||
|
||||
void setLimit(Poco::UInt32 limit);
|
||||
/// Sets the limit.
|
||||
|
||||
Poco::UInt32 getLimit() const;
|
||||
/// Gets the limit.
|
||||
|
||||
private:
|
||||
AbstractExtractor* _pExtractor;
|
||||
Poco::UInt32 _limit;
|
||||
};
|
||||
|
||||
|
||||
typedef Poco::AutoPtr<AbstractExtraction> AbstractExtractionPtr;
|
||||
typedef std::vector<AbstractExtractionPtr> AbstractExtractionVec;
|
||||
|
||||
|
||||
//
|
||||
// inlines
|
||||
//
|
||||
inline void AbstractExtraction::setExtractor(AbstractExtractor* pExtractor)
|
||||
{
|
||||
_pExtractor = pExtractor;
|
||||
}
|
||||
|
||||
|
||||
inline AbstractExtractor* AbstractExtraction::getExtractor() const
|
||||
{
|
||||
return _pExtractor;
|
||||
}
|
||||
|
||||
|
||||
inline void AbstractExtraction::setLimit(Poco::UInt32 limit)
|
||||
{
|
||||
_limit = limit;
|
||||
}
|
||||
|
||||
|
||||
inline Poco::UInt32 AbstractExtraction::getLimit() const
|
||||
{
|
||||
return _limit;
|
||||
}
|
||||
|
||||
|
||||
} } // namespace Poco::Data
|
||||
|
||||
|
||||
#endif // Data_AbstractExtraction_INCLUDED
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user