diff --git a/Build/catch_test.vcxproj b/Build/catch_test.vcxproj
index a7648e8..8d524a9 100644
--- a/Build/catch_test.vcxproj
+++ b/Build/catch_test.vcxproj
@@ -33,6 +33,22 @@
Release
x64
+
+ v141Debug
+ Win32
+
+
+ v141Debug
+ x64
+
+
+ v141Release
+ Win32
+
+
+ v141Release
+ x64
+
{27B715B5-136F-5702-7C76-305E684DF2F2}
@@ -53,12 +69,24 @@
MultiByte
v120
+
+ Application
+ true
+ MultiByte
+ v141
+
Application
true
MultiByte
v120
+
+ Application
+ true
+ MultiByte
+ v141
+
Application
false
@@ -71,12 +99,24 @@
MultiByte
v120
+
+ Application
+ false
+ MultiByte
+ v141
+
Application
false
MultiByte
v120
+
+ Application
+ false
+ MultiByte
+ v141
+
@@ -86,18 +126,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
true
@@ -113,6 +165,13 @@
catch_test
.exe
+
+ true
+ ..\bin\catch_test\Debug\
+ ..\obj\catch_test\Debug\x32\
+ catch_test
+ .exe
+
true
..\bin\catch_test\Debug\
@@ -120,6 +179,13 @@
catch_test
.exe
+
+ true
+ ..\bin\catch_test\Debug\
+ ..\obj\catch_test\Debug\x64\
+ catch_test
+ .exe
+
false
..\bin\catch_test\Release\
@@ -134,6 +200,13 @@
catch_test
.exe
+
+ false
+ ..\bin\catch_test\Release\
+ ..\obj\catch_test\Release\x32\
+ catch_test
+ .exe
+
false
..\bin\catch_test\Release\
@@ -141,6 +214,13 @@
catch_test
.exe
+
+ false
+ ..\bin\catch_test\Release\
+ ..\obj\catch_test\Release\x64\
+ catch_test
+ .exe
+
NotUsing
@@ -177,6 +257,24 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ EditAndContinue
+ Disabled
+
+
+ Console
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
NotUsing
@@ -195,6 +293,24 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ ProgramDatabase
+ Disabled
+
+
+ Console
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
NotUsing
@@ -241,6 +357,29 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+
+
+ Console
+ false
+ true
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
NotUsing
@@ -264,6 +403,29 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+
+
+ Console
+ false
+ true
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
diff --git a/Build/hiberlite.sln b/Build/hiberlite.sln
index 8ba2053..d53c18b 100644
--- a/Build/hiberlite.sln
+++ b/Build/hiberlite.sln
@@ -1,8 +1,14 @@
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.1778
+MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "catch_test", "catch_test.vcxproj", "{27B715B5-136F-5702-7C76-305E684DF2F2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hiberlite", "hiberlite.vcxproj", "{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}"
+ ProjectSection(ProjectDependencies) = postProject
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43} = {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}
+ EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hiberlite_test", "hiberlite_test.vcxproj", "{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}"
EndProject
@@ -18,6 +24,12 @@ Global
Release|native = Release|native
Release|Win32 = Release|Win32
Release|x64 = Release|x64
+ v141Debug|native = v141Debug|native
+ v141Debug|Win32 = v141Debug|Win32
+ v141Debug|x64 = v141Debug|x64
+ v141Release|native = v141Release|native
+ v141Release|Win32 = v141Release|Win32
+ v141Release|x64 = v141Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{27B715B5-136F-5702-7C76-305E684DF2F2}.Debug|native.ActiveCfg = Debug native|Win32
@@ -32,6 +44,18 @@ Global
{27B715B5-136F-5702-7C76-305E684DF2F2}.Release|Win32.Build.0 = Release|Win32
{27B715B5-136F-5702-7C76-305E684DF2F2}.Release|x64.ActiveCfg = Release|x64
{27B715B5-136F-5702-7C76-305E684DF2F2}.Release|x64.Build.0 = Release|x64
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Debug|native.ActiveCfg = v141Debug|Win32
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Debug|native.Build.0 = v141Debug|Win32
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Debug|Win32.ActiveCfg = v141Debug|Win32
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Debug|Win32.Build.0 = v141Debug|Win32
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Debug|x64.ActiveCfg = v141Debug|x64
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Debug|x64.Build.0 = v141Debug|x64
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Release|native.ActiveCfg = v141Release|Win32
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Release|native.Build.0 = v141Release|Win32
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Release|Win32.ActiveCfg = v141Release|Win32
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Release|Win32.Build.0 = v141Release|Win32
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Release|x64.ActiveCfg = v141Release|x64
+ {27B715B5-136F-5702-7C76-305E684DF2F2}.v141Release|x64.Build.0 = v141Release|x64
{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|native.ActiveCfg = Debug native|Win32
{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|native.Build.0 = Debug native|Win32
{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -44,6 +68,16 @@ Global
{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|Win32.Build.0 = Release|Win32
{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|x64.ActiveCfg = Release|x64
{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.Release|x64.Build.0 = Release|x64
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Debug|native.ActiveCfg = v141Debug|Win32
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Debug|Win32.ActiveCfg = v141Debug|Win32
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Debug|Win32.Build.0 = v141Debug|Win32
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Debug|x64.ActiveCfg = v141Debug|x64
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Debug|x64.Build.0 = v141Debug|x64
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Release|native.ActiveCfg = v141Release|Win32
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Release|Win32.ActiveCfg = v141Release|Win32
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Release|Win32.Build.0 = v141Release|Win32
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Release|x64.ActiveCfg = v141Release|x64
+ {1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}.v141Release|x64.Build.0 = v141Release|x64
{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|native.ActiveCfg = Debug native|Win32
{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|native.Build.0 = Debug native|Win32
{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -56,6 +90,16 @@ Global
{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|Win32.Build.0 = Release|Win32
{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|x64.ActiveCfg = Release|x64
{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.Release|x64.Build.0 = Release|x64
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Debug|native.ActiveCfg = v141Debug|Win32
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Debug|Win32.ActiveCfg = v141Debug|Win32
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Debug|Win32.Build.0 = v141Debug|Win32
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Debug|x64.ActiveCfg = v141Debug|x64
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Debug|x64.Build.0 = v141Debug|x64
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Release|native.ActiveCfg = v141Release|Win32
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Release|Win32.ActiveCfg = v141Release|Win32
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Release|Win32.Build.0 = v141Release|Win32
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Release|x64.ActiveCfg = v141Release|x64
+ {FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}.v141Release|x64.Build.0 = v141Release|x64
{073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|native.ActiveCfg = Debug native|Win32
{073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|native.Build.0 = Debug native|Win32
{073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -68,6 +112,16 @@ Global
{073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|Win32.Build.0 = Release|Win32
{073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|x64.ActiveCfg = Release|x64
{073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.Release|x64.Build.0 = Release|x64
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Debug|native.ActiveCfg = v141Debug|Win32
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Debug|Win32.ActiveCfg = v141Debug|Win32
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Debug|Win32.Build.0 = v141Debug|Win32
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Debug|x64.ActiveCfg = v141Debug|x64
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Debug|x64.Build.0 = v141Debug|x64
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Release|native.ActiveCfg = v141Release|Win32
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Release|Win32.ActiveCfg = v141Release|Win32
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Release|Win32.Build.0 = v141Release|Win32
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Release|x64.ActiveCfg = v141Release|x64
+ {073E391B-F3DF-63F1-DC9A-7745C8DBEA41}.v141Release|x64.Build.0 = v141Release|x64
{F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|native.ActiveCfg = Debug native|Win32
{F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|native.Build.0 = Debug native|Win32
{F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -80,8 +134,21 @@ Global
{F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|Win32.Build.0 = Release|Win32
{F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|x64.ActiveCfg = Release|x64
{F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.Release|x64.Build.0 = Release|x64
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Debug|native.ActiveCfg = v141Debug|Win32
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Debug|Win32.ActiveCfg = v141Debug|Win32
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Debug|Win32.Build.0 = v141Debug|Win32
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Debug|x64.ActiveCfg = v141Debug|x64
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Debug|x64.Build.0 = v141Debug|x64
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Release|native.ActiveCfg = v141Release|Win32
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Release|Win32.ActiveCfg = v141Release|Win32
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Release|Win32.Build.0 = v141Release|Win32
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Release|x64.ActiveCfg = v141Release|x64
+ {F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}.v141Release|x64.Build.0 = v141Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {3F6A4405-92F7-42A7-AB5C-BF85E1EF73B4}
+ EndGlobalSection
EndGlobal
diff --git a/Build/hiberlite.vcxproj b/Build/hiberlite.vcxproj
index 320f573..7b75571 100644
--- a/Build/hiberlite.vcxproj
+++ b/Build/hiberlite.vcxproj
@@ -33,6 +33,22 @@
Release
x64
+
+ v141Debug
+ Win32
+
+
+ v141Debug
+ x64
+
+
+ v141Release
+ Win32
+
+
+ v141Release
+ x64
+
{1DFD5A97-8967-0F0E-D2A5-C0B33E4FED62}
@@ -53,12 +69,24 @@
MultiByte
v120
+
+ StaticLibrary
+ true
+ MultiByte
+ v141
+
StaticLibrary
true
MultiByte
v120
+
+ StaticLibrary
+ true
+ MultiByte
+ v141
+
StaticLibrary
false
@@ -71,12 +99,24 @@
MultiByte
v120
+
+ StaticLibrary
+ false
+ MultiByte
+ v141
+
StaticLibrary
false
MultiByte
v120
+
+ StaticLibrary
+ false
+ MultiByte
+ v141
+
@@ -86,18 +126,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
..\bin\hiberlite\Debug\
@@ -111,12 +163,24 @@
hiberlite
.lib
+
+ ..\bin\hiberlite\Debug\
+ ..\obj\hiberlite\Debug\x32\
+ hiberlite
+ .lib
+
..\bin\hiberlite\Debug\
..\obj\hiberlite\Debug\x64\
hiberlite
.lib
+
+ ..\bin\hiberlite\Debug\
+ ..\obj\hiberlite\Debug\x64\
+ hiberlite
+ .lib
+
..\bin\hiberlite\Release\
..\obj\hiberlite\Release\native\
@@ -129,12 +193,24 @@
hiberlite
.lib
+
+ ..\bin\hiberlite\Release\
+ ..\obj\hiberlite\Release\x32\
+ hiberlite
+ .lib
+
..\bin\hiberlite\Release\
..\obj\hiberlite\Release\x64\
hiberlite
.lib
+
+ ..\bin\hiberlite\Release\
+ ..\obj\hiberlite\Release\x64\
+ hiberlite
+ .lib
+
NotUsing
@@ -163,6 +239,20 @@
true
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ EditAndContinue
+ Disabled
+
+
+ Windows
+ true
+
+
NotUsing
@@ -177,6 +267,20 @@
true
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ ProgramDatabase
+ Disabled
+
+
+ Windows
+ true
+
+
NotUsing
@@ -215,6 +319,25 @@
true
+
+
+ NotUsing
+ Level3
+ RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+
+
+ Windows
+ false
+ true
+ true
+
+
NotUsing
@@ -234,6 +357,25 @@
true
+
+
+ NotUsing
+ Level3
+ RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+
+
+ Windows
+ false
+ true
+ true
+
+
diff --git a/Build/hiberlite_test.vcxproj b/Build/hiberlite_test.vcxproj
index 26dedc4..f0b6191 100644
--- a/Build/hiberlite_test.vcxproj
+++ b/Build/hiberlite_test.vcxproj
@@ -33,6 +33,22 @@
Release
x64
+
+ v141Debug
+ Win32
+
+
+ v141Debug
+ x64
+
+
+ v141Release
+ Win32
+
+
+ v141Release
+ x64
+
{FC275FB3-E8F5-52B9-D189-C3DFBDF62E1E}
@@ -53,12 +69,24 @@
MultiByte
v120
+
+ Application
+ true
+ MultiByte
+ v141
+
Application
true
MultiByte
v120
+
+ Application
+ true
+ MultiByte
+ v141
+
Application
false
@@ -71,12 +99,24 @@
MultiByte
v120
+
+ Application
+ false
+ MultiByte
+ v141
+
Application
false
MultiByte
v120
+
+ Application
+ false
+ MultiByte
+ v141
+
@@ -86,18 +126,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
true
@@ -113,6 +165,13 @@
hiberlite_test
.exe
+
+ true
+ ..\bin\hiberlite_test\Debug\
+ ..\obj\hiberlite_test\Debug\x32\
+ hiberlite_test
+ .exe
+
true
..\bin\hiberlite_test\Debug\
@@ -120,6 +179,13 @@
hiberlite_test
.exe
+
+ true
+ ..\bin\hiberlite_test\Debug\
+ ..\obj\hiberlite_test\Debug\x64\
+ hiberlite_test
+ .exe
+
false
..\bin\hiberlite_test\Release\
@@ -134,6 +200,13 @@
hiberlite_test
.exe
+
+ false
+ ..\bin\hiberlite_test\Release\
+ ..\obj\hiberlite_test\Release\x32\
+ hiberlite_test
+ .exe
+
false
..\bin\hiberlite_test\Release\
@@ -141,6 +214,13 @@
hiberlite_test
.exe
+
+ false
+ ..\bin\hiberlite_test\Release\
+ ..\obj\hiberlite_test\Release\x64\
+ hiberlite_test
+ .exe
+
NotUsing
@@ -177,6 +257,24 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ EditAndContinue
+ Disabled
+
+
+ Console
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
NotUsing
@@ -195,6 +293,24 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ ProgramDatabase
+ Disabled
+
+
+ Console
+ true
+ mainCRTStartup
+
+
+ rem "$(TargetPath)"
+
+
NotUsing
@@ -241,6 +357,29 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+
+
+ Console
+ false
+ true
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
NotUsing
@@ -264,6 +403,29 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+
+
+ Console
+ false
+ true
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
diff --git a/Build/sample.vcxproj b/Build/sample.vcxproj
index 83087ab..ae37777 100644
--- a/Build/sample.vcxproj
+++ b/Build/sample.vcxproj
@@ -33,6 +33,22 @@
Release
x64
+
+ v141Debug
+ Win32
+
+
+ v141Debug
+ x64
+
+
+ v141Release
+ Win32
+
+
+ v141Release
+ x64
+
{073E391B-F3DF-63F1-DC9A-7745C8DBEA41}
@@ -53,12 +69,24 @@
MultiByte
v120
+
+ Application
+ true
+ MultiByte
+ v141
+
Application
true
MultiByte
v120
+
+ Application
+ true
+ MultiByte
+ v141
+
Application
false
@@ -71,12 +99,24 @@
MultiByte
v120
+
+ Application
+ false
+ MultiByte
+ v141
+
Application
false
MultiByte
v120
+
+ Application
+ false
+ MultiByte
+ v141
+
@@ -86,18 +126,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
true
@@ -113,6 +165,13 @@
sample
.exe
+
+ true
+ ..\bin\sample\Debug\
+ ..\obj\sample\Debug\x32\
+ sample
+ .exe
+
true
..\bin\sample\Debug\
@@ -120,6 +179,13 @@
sample
.exe
+
+ true
+ ..\bin\sample\Debug\
+ ..\obj\sample\Debug\x64\
+ sample
+ .exe
+
false
..\bin\sample\Release\
@@ -134,6 +200,13 @@
sample
.exe
+
+ false
+ ..\bin\sample\Release\
+ ..\obj\sample\Release\x32\
+ sample
+ .exe
+
false
..\bin\sample\Release\
@@ -141,6 +214,13 @@
sample
.exe
+
+ false
+ ..\bin\sample\Release\
+ ..\obj\sample\Release\x64\
+ sample
+ .exe
+
NotUsing
@@ -177,6 +257,24 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ EditAndContinue
+ Disabled
+
+
+ Console
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
NotUsing
@@ -195,6 +293,24 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ ProgramDatabase
+ Disabled
+
+
+ Console
+ true
+ mainCRTStartup
+
+
+ rem "$(TargetPath)"
+
+
NotUsing
@@ -241,6 +357,29 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+
+
+ Console
+ false
+ true
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
NotUsing
@@ -264,6 +403,29 @@
"$(TargetPath)"
+
+
+ NotUsing
+ Level3
+ RELEASE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+
+
+ Console
+ false
+ true
+ true
+ mainCRTStartup
+
+
+ "$(TargetPath)"
+
+
diff --git a/Build/sqlite.vcxproj b/Build/sqlite.vcxproj
index 22cab93..400fb57 100644
--- a/Build/sqlite.vcxproj
+++ b/Build/sqlite.vcxproj
@@ -33,6 +33,22 @@
Release
x64
+
+ v141Debug
+ Win32
+
+
+ v141Debug
+ x64
+
+
+ v141Release
+ Win32
+
+
+ v141Release
+ x64
+
{F71C5A1C-E3BE-84F2-CC79-9846B8BA0B43}
@@ -53,12 +69,24 @@
MultiByte
v120
+
+ StaticLibrary
+ true
+ MultiByte
+ v141
+
StaticLibrary
true
MultiByte
v120
+
+ StaticLibrary
+ true
+ MultiByte
+ v141
+
StaticLibrary
false
@@ -71,12 +99,24 @@
MultiByte
v120
+
+ StaticLibrary
+ false
+ MultiByte
+ v141
+
StaticLibrary
false
MultiByte
v120
+
+ StaticLibrary
+ false
+ MultiByte
+ v141
+
@@ -86,18 +126,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
..\bin\sqlite\Debug\
@@ -111,12 +163,24 @@
sqlite
.lib
+
+ ..\bin\sqlite\Debug\
+ ..\obj\sqlite\Debug\x32\
+ sqlite
+ .lib
+
..\bin\sqlite\Debug\
..\obj\sqlite\Debug\x64\
sqlite
.lib
+
+ ..\bin\sqlite\Debug\
+ ..\obj\sqlite\Debug\x64\
+ sqlite
+ .lib
+
..\bin\sqlite\Release\
..\obj\sqlite\Release\native\
@@ -129,12 +193,24 @@
sqlite
.lib
+
+ ..\bin\sqlite\Release\
+ ..\obj\sqlite\Release\x32\
+ sqlite
+ .lib
+
..\bin\sqlite\Release\
..\obj\sqlite\Release\x64\
sqlite
.lib
+
+ ..\bin\sqlite\Release\
+ ..\obj\sqlite\Release\x64\
+ sqlite
+ .lib
+
NotUsing
@@ -165,6 +241,21 @@
true
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ EditAndContinue
+ Disabled
+ CompileAsC
+
+
+ Windows
+ true
+
+
NotUsing
@@ -180,6 +271,21 @@
true
+
+
+ NotUsing
+ Level3
+ DEBUG;_DEBUG;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ ProgramDatabase
+ Disabled
+ CompileAsC
+
+
+ Windows
+ true
+
+
NotUsing
@@ -220,6 +326,26 @@
true
+
+
+ NotUsing
+ Level3
+ RELEASE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+ CompileAsC
+
+
+ Windows
+ false
+ true
+ true
+
+
NotUsing
@@ -240,6 +366,26 @@
true
+
+
+ NotUsing
+ Level3
+ RELEASE;%(PreprocessorDefinitions)
+ ..\include;..\sqlite-amalgamation;..\Catch\single_include;%(AdditionalIncludeDirectories)
+ Full
+ true
+ true
+ false
+ true
+ CompileAsC
+
+
+ Windows
+ false
+ true
+ true
+
+
diff --git a/include/Database.h b/include/Database.h
index ac69ca8..e41815c 100644
--- a/include/Database.h
+++ b/include/Database.h
@@ -1,10 +1,35 @@
-#ifndef DATABASE_H
+#ifndef DATABASE_H
#define DATABASE_H
namespace hiberlite{
class ModelExtractor;
class UpdateBean;
+class Database;
+
+class DatabaseTransaction
+{
+public:
+ inline DatabaseTransaction();
+ inline ~DatabaseTransaction();
+ inline DatabaseTransaction( DatabaseTransaction& );
+ inline DatabaseTransaction& operator=( DatabaseTransaction& );
+
+private:
+ friend class Database;
+ inline DatabaseTransaction( Database* db, bool bRollback = true );
+ inline bool isValid() const;
+
+ //bool m_bRollback = true;
+ Database* m_pDb = nullptr;
+};
+
+enum EDBSynchronous {
+ EDBSynchronous_Default,
+ EDBSynchronous_Full,
+ EDBSynchronous_Normal,
+ EDBSynchronous_Off,
+};
class Database : noncopyable
{
@@ -12,6 +37,7 @@ class Database : noncopyable
friend class UpdateBean;
friend class KillChildren;
friend class LoadBean;
+ friend class DatabaseTransaction;
template
friend class real_bean;
@@ -19,10 +45,10 @@ class Database : noncopyable
ModelExtractor* mx;
template
- static void dbDelete(bean_key key, C& bean);
+ static void dbDelete(bean_key key, C& bean, bool bUseTransaction );
template
- static void dbUpdate(bean_key key, C& bean);
+ static void dbUpdate(bean_key key, C& bean, bool bUseTransaction );
template
static C* dbLoad(bean_key key);
@@ -44,6 +70,11 @@ class Database : noncopyable
template
static void dbDeleteRows( shared_connection con, std::string table, std::string column, C value );
+ inline bool shouldInsideUseTransaction() const;
+
+ int m_nOutTransactionNum = 0;
+ bool m_bOutbRollback = false;
+
public:
static const sqlid_t NULL_ID=-1;
@@ -51,10 +82,10 @@ class Database : noncopyable
static std::string getClassName();
Database();
- Database(std::string fname);
+ Database(std::string fname, EDBSynchronous sync = EDBSynchronous_Default );
virtual ~Database();
- void open(std::string fname);
+ void open(std::string fname, EDBSynchronous );
void close();
template
@@ -66,19 +97,29 @@ class Database : noncopyable
std::vector checkModel();
void dropModel();
void createModel();
+ void checkCreateModel();
+
+ /** 外部使用事务,内部就不再使用事务了,能快一点 */
+ inline void beginTransaction( bool bRollback = true );
+ inline void endTransaction();
+ inline DatabaseTransaction transactionGuard( bool bRollback = true );
template
- bean_ptr loadBean(sqlid_t objId);
+ bean_ptr loadBean(sqlid_t objId, ESavePolicy save = ESavePolicy_Default);
template
- std::vector getBeanIds();
+ std::vector getBeanIds( );
template
- std::vector< bean_ptr > getAllBeans();
+ std::vector< bean_ptr > getAllBeans( ESavePolicy save = ESavePolicy_Default );
template
bean_ptr copyBean(const C& c);
+ /** 不需要返回值的话,这个方法比 copyBean 高效 */
+ template
+ void copyBeanToDB( const C& c );
+
template
bean_ptr createBean();
diff --git a/include/Database_tmpl_impl.hpp b/include/Database_tmpl_impl.hpp
index 7d82394..51832d7 100644
--- a/include/Database_tmpl_impl.hpp
+++ b/include/Database_tmpl_impl.hpp
@@ -1,21 +1,105 @@
-#ifndef DATABASE_TMPL_IMPL_HPP_INCLUDED
+#ifndef DATABASE_TMPL_IMPL_HPP_INCLUDED
#define DATABASE_TMPL_IMPL_HPP_INCLUDED
namespace hiberlite{
+ inline DatabaseTransaction::DatabaseTransaction()
+ : m_pDb( nullptr )
+ {
+ }
+ inline DatabaseTransaction::DatabaseTransaction( Database* pDb, bool bRollback )
+ : m_pDb(pDb) {
+ if( m_pDb ) {
+ m_pDb->beginTransaction( bRollback );
+ }
+ }
+ inline DatabaseTransaction::~DatabaseTransaction() {
+ if( m_pDb ) {
+ m_pDb->endTransaction( );
+ m_pDb = nullptr;
+ }
+ }
+ inline DatabaseTransaction::DatabaseTransaction( DatabaseTransaction& o ) {
+ m_pDb = o.m_pDb;
+ const_cast< DatabaseTransaction& >( o ).m_pDb = nullptr;
+ }
+ inline DatabaseTransaction& DatabaseTransaction::operator=( DatabaseTransaction& o ) {
+ m_pDb = o.m_pDb;
+ const_cast< DatabaseTransaction& >(o).m_pDb = nullptr;
+ return *this;
+ }
+
+ bool DatabaseTransaction::isValid() const {
+ return m_pDb != nullptr;
+ }
+
+ inline void Database::beginTransaction( bool bRollback ){
+ ++m_nOutTransactionNum;
+ if( m_nOutTransactionNum == 1 ) {
+ if( bRollback ) {
+ try {
+ Database::dbExecQuery( this->con, "ROLLBACK TRANSACTION;" );
+ }
+ catch( ... ) {}
+ }
+ Database::dbExecQuery( this->con, "BEGIN TRANSACTION;" );
+ }
+ }
+
+ inline bool Database::shouldInsideUseTransaction() const{
+ if( m_nOutTransactionNum <= 0 ) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
+ inline void Database::endTransaction() {
+ --m_nOutTransactionNum;
+ if( m_nOutTransactionNum == 0 ) {
+ Database::dbExecQuery( this->con, "COMMIT TRANSACTION;" );
+ }
+
+ if( m_nOutTransactionNum < 0 )
+ m_nOutTransactionNum = 0;
+ }
+
+ inline DatabaseTransaction Database::transactionGuard( bool bRollback ) {
+ return DatabaseTransaction(this, bRollback );
+ }
+
template
-void Database::dbDelete(bean_key key, C& bean)
+void Database::dbDelete(bean_key key, C& bean, bool bUseTransaction )
{
- try{
- dbExecQuery(key.con,"ROLLBACK TRANSACTION;");
- }catch(...){}
- dbExecQuery(key.con,"BEGIN TRANSACTION;");
+ if( bUseTransaction )
+ {
+ try {
+ dbExecQuery( key.con, "ROLLBACK TRANSACTION;" );
+ }
+ catch( ... ) {}
+ dbExecQuery( key.con, "BEGIN TRANSACTION;" );
+
+ ChildKiller ck;
+ ck.killChildren( key, bean );
+ dbDeleteRows( key.con, Database::getClassName(), HIBERLITE_PRIMARY_KEY_COLUMN, key.id );
+
+ dbExecQuery( key.con, "COMMIT TRANSACTION;" );
+ }
+ else {
+ try {
+ //dbExecQuery( key.con, "ROLLBACK TRANSACTION;" );
+ }
+ catch( ... ) {}
+ //dbExecQuery( key.con, "BEGIN TRANSACTION;" );
ChildKiller ck;
- ck.killChildren(key,bean);
- dbDeleteRows(key.con, Database::getClassName(), HIBERLITE_PRIMARY_KEY_COLUMN, key.id);
+ ck.killChildren( key, bean );
+ dbDeleteRows( key.con, Database::getClassName(), HIBERLITE_PRIMARY_KEY_COLUMN, key.id );
- dbExecQuery(key.con,"COMMIT TRANSACTION;");
+ //dbExecQuery( key.con, "COMMIT TRANSACTION;" );
+ }
+
}
template
@@ -28,19 +112,37 @@ void Database::dbDeleteRows(shared_connection con, std::string table, std::strin
template
-void Database::dbUpdate(bean_key key, C& bean)
+void Database::dbUpdate(bean_key key, C& bean, bool bUseTransaction )
{
- try{
- dbExecQuery(key.con,"ROLLBACK TRANSACTION;");
- }catch(...){}
- dbExecQuery(key.con,"BEGIN TRANSACTION;");
+ if( bUseTransaction ) {
+ try { /** 这里是不是不对,应该执行事务后失败后才回滚吧*/
+ dbExecQuery( key.con, "ROLLBACK TRANSACTION;" );
+ }
+ catch( ... ) {}
+ dbExecQuery( key.con, "BEGIN TRANSACTION;" );
+
+ ChildKiller ck;
+ ck.killChildren( key, bean );
+ BeanUpdater u;
+ u.update( key, bean );
+
+ dbExecQuery( key.con, "COMMIT TRANSACTION;" );
+ }
+ else {
+ try {
+ //dbExecQuery( key.con, "ROLLBACK TRANSACTION;" );
+ }
+ catch( ... ) {}
+ //dbExecQuery( key.con, "BEGIN TRANSACTION;" );
ChildKiller ck;
- ck.killChildren(key,bean);
+ ck.killChildren( key, bean );
BeanUpdater u;
- u.update(key, bean);
+ u.update( key, bean );
- dbExecQuery(key.con,"COMMIT TRANSACTION;");
+ //dbExecQuery( key.con, "COMMIT TRANSACTION;" );
+ }
+
}
template
@@ -63,19 +165,28 @@ bean_ptr Database::copyBean(const C& c)
return manageBean( new C(c) );
}
+
+template
+void Database::copyBeanToDB( const C& c )
+{
+ sqlid_t id = allocId( Database::getClassName() );
+ bean_key key( con, id );
+ dbUpdate( key, const_cast< C& >(c), shouldInsideUseTransaction() );
+}
+
template
inline bean_ptr Database::manageBean(C* ptr)
{
sqlid_t id=allocId( Database::getClassName() );
bean_key key(con,id);
- dbUpdate(key,*ptr);
- return Registry::createBeanPtr(key,ptr);
+ dbUpdate(key,*ptr, shouldInsideUseTransaction() );
+ return Registry::createBeanPtr(this, key,ptr);
}
template
-inline bean_ptr Database::loadBean(sqlid_t id)
+inline bean_ptr Database::loadBean(sqlid_t id, ESavePolicy save )
{
- return Registry::get( bean_key(con,id) );
+ return Registry::get( this, bean_key(con,id), save );
}
template
@@ -85,14 +196,14 @@ std::vector Database::getBeanIds()
}
template
-std::vector< bean_ptr > Database::getAllBeans()
+std::vector< bean_ptr > Database::getAllBeans( ESavePolicy save )
{
std::vector ids=getBeanIds();
size_t N=ids.size();
std::vector< bean_ptr > ans;
ans.reserve(N);
for(size_t i=0;i(ids[i]) );
+ ans.push_back( loadBean(ids[i], save) );
return ans;
}
diff --git a/include/Registry.h b/include/Registry.h
index 24bcc49..e96951b 100644
--- a/include/Registry.h
+++ b/include/Registry.h
@@ -1,4 +1,4 @@
-#ifndef REGISTRY_H_INCLUDED
+#ifndef REGISTRY_H_INCLUDED
#define REGISTRY_H_INCLUDED
namespace hiberlite{
@@ -32,10 +32,10 @@ class Registry{
static void notifyRBDies(rb_pair* r);
public:
- static bean_ptr get(const bean_key key);
+ static bean_ptr get( Database* pDb, const bean_key key, ESavePolicy save = ESavePolicy_Default );
static bool has(const bean_key key);
- static bean_ptr createBeanPtr(bean_key key, C* obj);
+ static bean_ptr createBeanPtr( Database* pDb, bean_key key, C* obj, ESavePolicy save = ESavePolicy_Default );
};
template
diff --git a/include/Registry_impl.hpp b/include/Registry_impl.hpp
index d84234f..606f0eb 100644
--- a/include/Registry_impl.hpp
+++ b/include/Registry_impl.hpp
@@ -1,4 +1,4 @@
-namespace hiberlite{
+namespace hiberlite{
template
rb_pair::~rb_pair()
@@ -18,12 +18,13 @@ bean_key rb_pair::get_key()
}
template
-bean_ptr Registry::createBeanPtr(bean_key key, C* obj)
+bean_ptr Registry::createBeanPtr( Database* pDb, bean_key key, C* obj, ESavePolicy save )
{
if(key.id==Database::NULL_ID)
- return bean_ptr(key,NULL);
+ return bean_ptr( pDb, key,NULL);
- real_bean* rb=new real_bean(key,obj);
+ real_bean* rb=new real_bean( pDb, key,obj);
+ rb->setSavePolicy( save );
rb_pair* para=new rb_pair(rb);
if( rbpairs.find(key)!=rbpairs.end() )
@@ -31,19 +32,21 @@ bean_ptr Registry::createBeanPtr(bean_key key, C* obj)
rbpairs[key]=para;
- bean_ptr ans(key, para);
+ bean_ptr ans( pDb, key, para);
return ans;
}
template
-bean_ptr Registry::get(const bean_key key)
+bean_ptr Registry::get( Database* pDb, const bean_key key, ESavePolicy save )
{
typename std::map* >::iterator it;
it=rbpairs.find(key);
if(it==rbpairs.end())
- return createBeanPtr(key,NULL);
- else
- return bean_ptr(key, it->second);
+ return createBeanPtr( pDb, key,NULL, save );
+ else {
+ it->second->getRes()->setSavePolicy( save );
+ return bean_ptr( pDb, key, it->second );
+ }
}
template
diff --git a/include/bean_ptr.h b/include/bean_ptr.h
index 8e881ac..aa184e2 100644
--- a/include/bean_ptr.h
+++ b/include/bean_ptr.h
@@ -1,4 +1,4 @@
-#ifndef BEAN_PTR_H_INCLUDED
+#ifndef BEAN_PTR_H_INCLUDED
#define BEAN_PTR_H_INCLUDED
namespace hiberlite{
@@ -22,21 +22,31 @@ class real_bean : noncopyable {
bean_key get_key() const { return key; }
+ inline ESavePolicy getSavePolicy() const {
+ return m_eSavePolicy;
+ }
+ inline void setSavePolicy( ESavePolicy save ) { m_eSavePolicy = save; }
void save();
void destroy();
bool destroyed() const { return forgotten; }
+ Database* database() const {
+ return m_pDb;
+ }
+
+
protected:
inline void loadLazy();
+ Database* m_pDb = nullptr;
bean_key key;
C* obj;
bool forgotten;
-
+ ESavePolicy m_eSavePolicy = ESavePolicy_Default;
private:
friend class Registry;
- real_bean(const bean_key _key, C* _obj); //only Registry can create the real_bean
+ real_bean( Database* pDb, const bean_key _key, C* _obj); //only Registry can create the real_bean
};
template
@@ -47,12 +57,12 @@ class bean_ptr : public shared_res< real_bean >
void hibernate(Archive & ar);
friend class Registry;
- bean_ptr(bean_key k, rb_pair* rbpair);
+ bean_ptr( Database* pDb, bean_key k, rb_pair* rbpair);
sqlid_t tmp_id;
public:
- bean_ptr(bean_key k);
+ bean_ptr( Database* pDb, bean_key k);
bean_ptr();
@@ -61,6 +71,12 @@ class bean_ptr : public shared_res< real_bean >
bean_ptr(const bean_ptr& other);
bean_ptr& operator=(const bean_ptr& other);
+ inline ESavePolicy getSavePolicy() const {
+ return shared_res< real_bean >::get_object()->getSavePolicy();
+ }
+ inline void setSavePolicy( ESavePolicy save ) {
+ return shared_res< real_bean >::get_object()->setSavePolicy( save );
+ }
void save();
void destroy();
diff --git a/include/bean_ptr_impl.hpp b/include/bean_ptr_impl.hpp
index 1bd55aa..eedd7c2 100644
--- a/include/bean_ptr_impl.hpp
+++ b/include/bean_ptr_impl.hpp
@@ -1,13 +1,15 @@
-namespace hiberlite{
+namespace hiberlite{
template
-real_bean::real_bean(const bean_key _key, C* _obj) : key(_key), obj(_obj), forgotten(false)
+real_bean::real_bean( Database* pDb, const bean_key _key, C* _obj)
+ : key(_key), m_pDb( pDb ), obj(_obj), forgotten(false)
{}
template
real_bean::~real_bean()
{
- save();
+ if( getSavePolicy() == ESavePolicy_ExitSave )
+ save();
delete obj;
}
@@ -15,7 +17,7 @@ template
void real_bean::destroy() {
if(forgotten)
return;
- Database::dbDelete(key, *obj);
+ Database::dbDelete( key, *obj, m_pDb->shouldInsideUseTransaction() );
delete obj;
forgotten=true;
obj=NULL;
@@ -28,7 +30,7 @@ void real_bean::save() {
return;
if(!obj)
return;
- Database::dbUpdate(key, *obj);
+ Database::dbUpdate( key, *obj, m_pDb->shouldInsideUseTransaction() );
}
template
@@ -61,7 +63,7 @@ inline void real_bean::loadLazy()
}
template
-bean_ptr::bean_ptr(bean_key k, rb_pair* para)
+bean_ptr::bean_ptr( Database* pDb, bean_key k, rb_pair* para)
{
this->takeRes(para);
}
@@ -79,9 +81,10 @@ bean_ptr& bean_ptr::operator=(const bean_ptr& other)
}
template
-bean_ptr::bean_ptr(bean_key k)
+bean_ptr::bean_ptr( Database* pDb, bean_key k)
{
- *this=Registry::get(k);
+ m_pDb = pDb;
+ *this=Registry::get( pDb, k);
}
template
@@ -91,7 +94,7 @@ bean_ptr::bean_ptr()
template
bean_ptr::operator bool() const {
- return get_id()!=Database::NULL_ID;
+ return const_cast< bean_ptr* >(this)->get_id()!=Database::NULL_ID;
}
template template
@@ -105,7 +108,7 @@ void bean_ptr::hibernate(Archive & ar)
ar & hiberlite::sql_nvp< sqlid_t > ("id", tmp_id );
if(ar.is_loading())
- *this=Registry::get( bean_key(ar.getConnection(), tmp_id) );
+ *this=Registry::get( res->getRes()->database(), bean_key(ar.getConnection(), tmp_id) );
}
template
diff --git a/include/common.h b/include/common.h
index 1419b07..61337ca 100644
--- a/include/common.h
+++ b/include/common.h
@@ -1,4 +1,4 @@
-#ifndef COMMON_H_
+#ifndef COMMON_H_
#define COMMON_H_
#include
@@ -7,6 +7,8 @@
#include
#include
+#include
+
#include
#include
#include
@@ -15,6 +17,12 @@
namespace hiberlite{
+enum ESavePolicy {
+ ESavePolicy_Default,
+ ESavePolicy_ExitSave = ESavePolicy_Default,
+ ESavePolicy_ExitNoSave,
+};
+
class noncopyable
{
protected:
diff --git a/include/hiberdefs.h b/include/hiberdefs.h
index 1293ce9..366b31e 100644
--- a/include/hiberdefs.h
+++ b/include/hiberdefs.h
@@ -1,4 +1,4 @@
-#ifndef HIBERDEFS_H_INCLUDED
+#ifndef HIBERDEFS_H_INCLUDED
#define HIBERDEFS_H_INCLUDED
#if (defined _MSC_VER && _MSC_VER< 1600)
diff --git a/include/some_types.h b/include/some_types.h
index e5dbc70..361d34b 100644
--- a/include/some_types.h
+++ b/include/some_types.h
@@ -1,8 +1,24 @@
-#ifndef SOM_TYPES_H_INCLUDED
+#ifndef SOM_TYPES_H_INCLUDED
#define SOM_TYPES_H_INCLUDED
+
+#include
+#include
+
namespace hiberlite{
+ inline std::string wstringToUtf8( const std::wstring& str )
+ {
+ std::wstring_convert > strCnv;
+ return strCnv.to_bytes( str );
+ }
+
+ inline std::wstring utf8ToWstring( const std::string& str )
+ {
+ std::wstring_convert< std::codecvt_utf8 > strCnv;
+ return strCnv.from_bytes( str );
+ }
+
template
class stl_stream_adapter{
C& ct;
@@ -154,6 +170,29 @@ inline void db_atom::bindValue(sqlite3_stmt* stmt, int col) {
sqlite3_bind_text(stmt, col, val.c_str(), -1, SQLITE_TRANSIENT);
}
+
+// std::wstring -> TEXT type
+
+template
+void hibernate( A& ar, std::wstring& value, const unsigned int ) {
+ ar & db_atom( value );
+}
+
+template<> template
+void db_atom::loadValue( Stmt& res, Arg& arg ) {
+ val = utf8ToWstring( std::string( ( const char* )(res.get_text( arg )) ) );
+}
+
+template<>
+inline std::string db_atom::sqliteStorageClass() {
+ return "TEXT";
+}
+
+template<>
+inline void db_atom::bindValue( sqlite3_stmt* stmt, int col ) {
+ sqlite3_bind_text( stmt, col, wstringToUtf8(val).c_str(), -1, SQLITE_TRANSIENT );
+}
+
// std::vector -> BLOB type
template
diff --git a/sample.cpp b/sample.cpp
index 82b4f5d..a15dd5f 100644
--- a/sample.cpp
+++ b/sample.cpp
@@ -1,4 +1,4 @@
-#include "hiberlite.h"
+#include "hiberlite.h"
#include
#include
@@ -6,19 +6,45 @@
#include
using namespace std;
+#define TEST_OLD_DB 0
+
+class Id {
+ friend class hiberlite::access;
+
+ template
+ void hibernate( Archive & ar )
+ {
+ ar & HIBERLITE_NVP( m_id );
+ //ar & HIBERLITE_NVP( bio2 );
+ }
+public:
+ string m_id;
+};
+
+HIBERLITE_EXPORT_CLASS( Id )
+
class Person{
friend class hiberlite::access;
template
void hibernate(Archive & ar)
{
- ar & HIBERLITE_NVP(name);
+ ar & HIBERLITE_NVP( id );
+ ar & HIBERLITE_NVP( name );
+ ar & HIBERLITE_NVP( wname );
ar & HIBERLITE_NVP(age);
- ar & HIBERLITE_NVP(bio);
+ ar & HIBERLITE_NVP( bio );
+ //ar & HIBERLITE_NVP( bio2 );
}
public:
+ Person() {}
+ ~Person() {}
+
+ Id id;
string name;
+ wstring wname;
double age;
vector bio;
+ vector bio2;
};
HIBERLITE_EXPORT_CLASS(Person)
@@ -28,65 +54,183 @@ void createDB()
hiberlite::Database db("sample.db");
//register bean classes
db.registerBeanClass();
+
+#if TEST_OLD_DB
+ std::vector tableNames = db.checkModel();
+ db.checkCreateModel();
+#else
//drop all tables beans will use
db.dropModel();
//create those tables again with proper schema
db.createModel();
+#endif
const char* names[5]={"Stanley Marsh", "Kyle Broflovski", "Eric Theodore Cartman", "Kenneth McCormick", "Leopold Stotch"};
for(unsigned int i=0;i<5;i++) {
Person x;
x.name=names[i%5];
+ x.wname = hiberlite::utf8ToWstring( names[i % 5] );
x.age=14+i*0.1;
x.bio.push_back("Hello");
x.bio.push_back("world");
x.bio.push_back("!");
+ x.bio2.push_back( L"wHello" );
+ x.bio2.push_back( L"wworld" );
+ x.bio2.push_back( L"!" );
+
hiberlite::bean_ptr p=db.copyBean(x); //create a managed copy of the object
}
}
+/**数据量稍微一大,就慢的要命。
+https://blog.csdn.net/majiakun1/article/details/46607163
+加了外部使用事务的接口,能快一点
+*/
+void createDBMuch()
+{
+ hiberlite::Database db( "sample.db", hiberlite::EDBSynchronous_Normal );
+ //register bean classes
+ db.registerBeanClass();
+
+#if TEST_OLD_DB
+ std::vector tableNames = db.checkModel();
+ db.checkCreateModel();
+#else
+ //drop all tables beans will use
+ db.dropModel();
+ //create those tables again with proper schema
+ db.createModel();
+#endif
+
+ const char* names[5] = { "Stanley Marsh", "Kyle Broflovski", "Eric Theodore Cartman", "Kenneth McCormick", "Leopold Stotch" };
+
+ auto t = db.transactionGuard();
+ db.beginTransaction(false);
+
+ for( int j = 0; j < 500; ++j ) {
+ for( unsigned int i = 0; i < 5; i++ ) {
+ Person x;
+ x.name = names[i % 5] ;
+ x.name += " " + std::to_string( j );
+ x.id.m_id = x.name;
+ x.wname = hiberlite::utf8ToWstring( names[i % 5] );
+ x.age = 14 + i * 0.1;
+ x.bio.push_back( "Hello" );
+ x.bio.push_back( "world" );
+ x.bio.push_back( "!" );
+
+ x.bio2.push_back( L"wHello" );
+ x.bio2.push_back( L"wworld" );
+ x.bio2.push_back( L"!" );
+
+ db.copyBeanToDB( x );
+ //hiberlite::bean_ptr p = db.copyBean( x ); //create a managed copy of the object
+ }
+ }
+
+ db.endTransaction();
+}
+
void printDB()
{
- hiberlite::Database db("sample.db");
+ hiberlite::Database db("sample.db", hiberlite::EDBSynchronous_Normal );
db.registerBeanClass();
+ auto t = db.transactionGuard();
cout << string(15,'=')+"\nreading the DB\n";
- vector< hiberlite::bean_ptr > v=db.getAllBeans();
+ vector< hiberlite::bean_ptr > v=db.getAllBeans( hiberlite::ESavePolicy_ExitNoSave );
cout << "found " << v.size() << " persons in the database:\n";
for(size_t j=0;jname << "\t";
+ cout << j << "[name=" << v[j]->name << "\t";
+ cout << "wname=" << hiberlite::wstringToUtf8(v[j]->wname) << "\t";
cout << "age=" << v[j]->age << "\t";
cout << "bio={";
for(size_t i=0;ibio.size();i++)
i && cout << ", ", cout << v[j]->bio[i];
- cout << "}]\n";
+ cout << "}\t";
+
+ cout << "bio2={";
+ for( size_t i = 0; i < v[j]->bio2.size(); i++ )
+ i && cout << ", ", cout << hiberlite::wstringToUtf8( v[j]->bio2[i]);
+ cout << "}]\n";
}
}
void modifyDB()
{
+ cout << string( 15, '=' ) + "\nmodify the DB\n";
hiberlite::Database db("sample.db");
db.registerBeanClass();
vector< hiberlite::bean_ptr > v=db.getAllBeans();
- cout << v[0]->name << " will be deleted.\n";
- v[0].destroy();
- cout << v[1]->name << " becomes 1 year older.\n\n";
- v[1]->age+=1;
+
+ if( v.size() > 0 ) {
+ cout << v[0]->name << " will be deleted.\n";
+ v[0].destroy();
+
+ if( v[0] ) {
+ cout << "error: v[0] should be null!";
+ }
+ }
+
+ if( v.size() > 1 ) {
+ cout << v[1]->name << " becomes 1 year older.\n\n";
+ v[1]->age += 1;
+ }
+
+ vector< hiberlite::bean_ptr > v2 = db.getAllBeans();
+}
+
+
+void modifyDBMuch()
+{
+ cout << string( 15, '=' ) + "\nmodify the DB\n";
+ hiberlite::Database db( "sample.db", hiberlite::EDBSynchronous_Normal );
+ db.registerBeanClass();
+
+ auto t = db.transactionGuard();
+ vector< hiberlite::bean_ptr > v = db.getAllBeans();
+
+ cout << "every record becomes 1 year older.\n\n";
+ for( auto i: v ) {
+ i->age += 1;
+ }
+
+ cout << "every record becomes 1 year older.\n\n";
+ for( auto i : v ) {
+ i->age += 1;
+ }
+
+ if( v.size() > 0 ) {
+ cout << v[0]->name << " will be deleted.\n";
+ v[0].destroy();
+
+ if( v[0] ) {
+ cout << "error: v[0] should be null!";
+ }
+ }
+ //cout << "every record will be deleted.\n\n";
+ //for( auto i : v ) {
+ // i.destroy();
+ //}
+
+ vector< hiberlite::bean_ptr > v2 = db.getAllBeans( hiberlite::ESavePolicy_ExitNoSave );
}
int main()
{
- createDB();
- printDB();
- modifyDB();
+ //createDB();
+ createDBMuch();
printDB();
- modifyDB();
+ modifyDBMuch();
+ //modifyDB();
printDB();
+ //modifyDB();
+ //printDB();
return 0;
}
diff --git a/src/Database.cpp b/src/Database.cpp
index e876d25..b48a2f7 100644
--- a/src/Database.cpp
+++ b/src/Database.cpp
@@ -1,4 +1,4 @@
-
+
#include "hiberlite.h"
namespace hiberlite{
@@ -7,9 +7,9 @@ Database::Database() : mx(NULL)
{
}
-Database::Database(std::string fname) : mx(NULL)
+Database::Database(std::string fname, EDBSynchronous sync) : mx(NULL)
{
- open(fname);
+ open(fname, sync );
}
Database::~Database()
@@ -17,7 +17,7 @@ Database::~Database()
close();
}
-void Database::open(std::string fname)
+void Database::open(std::string fname, EDBSynchronous sync )
{
sqlite3* db=NULL;
@@ -28,6 +28,22 @@ void Database::open(std::string fname)
throw database_error( std::string("database error: ")+sqlite3_errmsg(db) );
con=shared_connection(new autoclosed_con(db));
+ switch( sync )
+ {
+ case hiberlite::EDBSynchronous_Default:
+ break;
+ case hiberlite::EDBSynchronous_Full: sqlite3_exec( db, "PRAGMA synchronous = full; ", 0, 0, 0 );
+ break;
+ case hiberlite::EDBSynchronous_Normal:
+ sqlite3_exec( db, "PRAGMA synchronous = normal; ", 0, 0, 0 );
+ break;
+ case hiberlite::EDBSynchronous_Off:
+ sqlite3_exec( db, "PRAGMA synchronous = OFF; ", 0, 0, 0 );
+ break;
+ default:
+ break;
+ }
+
}catch(std::runtime_error e){
if(db)
sqlite3_close(db);
@@ -45,8 +61,17 @@ void Database::close()
std::vector Database::checkModel()
{
+ if( !mx )
+ throw std::logic_error( "register bean classes first" );
+
//TODO checkModel
std::vector ans;
+ Model mdl = mx->getModel();
+ for( Model::iterator it = mdl.begin(); it != mdl.end(); it++ ) {
+ Table& t = it->second;
+ ans.push_back( t.name );
+ }
+
return ans;
}
@@ -87,6 +112,31 @@ void Database::createModel()
}
}
+void Database::checkCreateModel()
+{
+ if( !mx )
+ throw std::logic_error( "register bean classes first" );
+ Model mdl = mx->getModel();
+ for( Model::iterator it = mdl.begin(); it != mdl.end(); it++ ) {
+ Table& t = it->second;
+ std::string query = "CREATE TABLE IF NOT EXISTS " + t.name + " (";
+ bool needComma = false;
+ for( std::map::iterator c = t.columns.begin(); c != t.columns.end(); c++ ) {
+ if( needComma )
+ query += ", ";
+ needComma = true;
+ Column& col = c->second;
+ query += col.name + " ";
+ if( col.name == HIBERLITE_PRIMARY_KEY_COLUMN )
+ query += "INTEGER PRIMARY KEY AUTOINCREMENT";
+ else
+ query += col.storage_type;
+ }
+ query += ");";
+ dbExecQuery( query );
+ }
+}
+
sqlid_t Database::allocId(shared_connection c, std::string table)
{
//THREAD critical call