mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 15:35:50 +00:00
Add beast_sqdb module
This commit is contained in:
@@ -257,6 +257,29 @@
|
||||
<ClInclude Include="..\..\modules\beast_crypto\math\beast_UnsignedInteger.h" />
|
||||
<ClInclude Include="..\..\modules\beast_db\beast_db.h" />
|
||||
<ClInclude Include="..\..\modules\beast_db\keyvalue\beast_KeyvaDB.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\backend.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\blob.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\into.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\session.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\statement.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\transaction.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\type_conversion_traits.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\use.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\beast_sqdb.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\error_codes.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\exchange_traits.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\into_type.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\once_temp_type.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\prepare_temp_type.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\ref_counted_prepare_info.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\ref_counted_statement.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\statement_imp.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\type_conversion.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\type_ptr.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\use_type.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqlite\beast_sqlite.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqlite\sqlite\sqlite3.h" />
|
||||
<ClInclude Include="..\..\modules\beast_sqlite\sqlite\sqlite3ext.h" />
|
||||
<ClInclude Include="BeastConfig.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@@ -948,6 +971,86 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\beast_sqdb.cpp" />
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\blob.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\error_codes.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\into_type.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\once_temp_type.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\prepare_temp_type.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\ref_counted_prepare_info.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\ref_counted_statement.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\session.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\statement.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\statement_imp.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\transaction.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\use_type.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqlite\beast_sqlite.c" />
|
||||
<ClCompile Include="..\..\modules\beast_sqlite\sqlite\sqlite3.c">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\..\TODO.txt" />
|
||||
|
||||
@@ -134,6 +134,24 @@
|
||||
<Filter Include="beast_db\keyvalue">
|
||||
<UniqueIdentifier>{15a98fee-1b52-45eb-9480-514b8750d755}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="beast_sqlite">
|
||||
<UniqueIdentifier>{cbf5f5a3-5d66-4b6d-996d-20ed14b41793}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="beast_sqlite\sqlite">
|
||||
<UniqueIdentifier>{acd9ab9d-3ba8-4c60-bfb8-36799d9d7a06}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="beast_sqdb">
|
||||
<UniqueIdentifier>{67b47aab-8e6a-4acd-9291-d95a8795d6ad}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="beast_sqdb\api">
|
||||
<UniqueIdentifier>{e666952d-d490-40a2-aa05-2d63ea23284f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="beast_sqdb\detail">
|
||||
<UniqueIdentifier>{3f969218-0a32-41f1-8e05-9a47247cf494}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="beast_sqdb\source">
|
||||
<UniqueIdentifier>{10ef778f-6b81-437e-a6ef-558ff4163acc}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\modules\beast_core\beast_core.h">
|
||||
@@ -647,6 +665,75 @@
|
||||
<ClInclude Include="..\..\modules\beast_db\keyvalue\beast_KeyvaDB.h">
|
||||
<Filter>beast_db\keyvalue</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqlite\beast_sqlite.h">
|
||||
<Filter>beast_sqlite</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqlite\sqlite\sqlite3.h">
|
||||
<Filter>beast_sqlite\sqlite</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqlite\sqlite\sqlite3ext.h">
|
||||
<Filter>beast_sqlite\sqlite</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\beast_sqdb.h">
|
||||
<Filter>beast_sqdb</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\backend.h">
|
||||
<Filter>beast_sqdb\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\blob.h">
|
||||
<Filter>beast_sqdb\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\into.h">
|
||||
<Filter>beast_sqdb\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\session.h">
|
||||
<Filter>beast_sqdb\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\statement.h">
|
||||
<Filter>beast_sqdb\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\transaction.h">
|
||||
<Filter>beast_sqdb\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\type_conversion_traits.h">
|
||||
<Filter>beast_sqdb\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\api\use.h">
|
||||
<Filter>beast_sqdb\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\error_codes.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\exchange_traits.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\into_type.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\once_temp_type.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\prepare_temp_type.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\ref_counted_prepare_info.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\ref_counted_statement.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\statement_imp.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\type_conversion.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\type_ptr.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\modules\beast_sqdb\detail\use_type.h">
|
||||
<Filter>beast_sqdb\detail</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\modules\beast_core\beast_core.cpp">
|
||||
@@ -1003,6 +1090,51 @@
|
||||
<ClCompile Include="..\..\modules\beast_db\keyvalue\beast_KeyvaDB.cpp">
|
||||
<Filter>beast_db\keyvalue</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqlite\beast_sqlite.c">
|
||||
<Filter>beast_sqlite</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqlite\sqlite\sqlite3.c">
|
||||
<Filter>beast_sqlite\sqlite</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\beast_sqdb.cpp">
|
||||
<Filter>beast_sqdb</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\blob.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\error_codes.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\into_type.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\once_temp_type.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\prepare_temp_type.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\ref_counted_prepare_info.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\ref_counted_statement.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\session.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\statement.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\statement_imp.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\transaction.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\modules\beast_sqdb\source\use_type.cpp">
|
||||
<Filter>beast_sqdb\source</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\..\TODO.txt" />
|
||||
|
||||
111
modules/beast_sqdb/api/backend.h
Normal file
111
modules/beast_sqdb/api/backend.h
Normal file
@@ -0,0 +1,111 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_BACKEND_H_INCLUDED
|
||||
#define BEAST_SQDB_BACKEND_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// supported standard types for intos and uses
|
||||
enum exchange_type
|
||||
{
|
||||
x_null, // only for input variables
|
||||
|
||||
x_bool,
|
||||
|
||||
x_char, x_uchar,
|
||||
x_short, x_ushort,
|
||||
x_int, x_uint,
|
||||
x_long, x_ulong,
|
||||
x_int64, x_uint64,
|
||||
x_float, x_double,
|
||||
|
||||
x_cstring, // null terminated char*, only valid for use_type
|
||||
x_cwstring, // null terminated wchar*, only valid for use_type
|
||||
x_stdstring,
|
||||
x_stdwstring,
|
||||
x_beastString,
|
||||
|
||||
x_stdtm,
|
||||
|
||||
x_blob
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// the enum type for indicator variables
|
||||
enum indicator
|
||||
{
|
||||
i_ok,
|
||||
i_null,
|
||||
i_truncated
|
||||
};
|
||||
|
||||
// sqlite row id
|
||||
|
||||
//typedef sqlite3_int64 rowid;
|
||||
typedef int64 rowid;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
91
modules/beast_sqdb/api/blob.h
Normal file
91
modules/beast_sqdb/api/blob.h
Normal file
@@ -0,0 +1,91 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_BLOB_H_INCLUDED
|
||||
#define BEAST_SQDB_BLOB_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
// BLOB interface
|
||||
class blob
|
||||
{
|
||||
public:
|
||||
blob();
|
||||
~blob();
|
||||
|
||||
Error select(session& s,
|
||||
char const* zTable,
|
||||
char const* zColumn,
|
||||
rowid id,
|
||||
bool readAndWrite = false) noexcept;
|
||||
|
||||
std::size_t get_len();
|
||||
Error read(std::size_t offset, void* buf, std::size_t toRead);
|
||||
Error write(std::size_t offset, void const* buf, std::size_t toWrite);
|
||||
void close();
|
||||
|
||||
private:
|
||||
session* m_session;
|
||||
sqlite3_blob* m_blob;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
82
modules/beast_sqdb/api/into.h
Normal file
82
modules/beast_sqdb/api/into.h
Normal file
@@ -0,0 +1,82 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_INTO_H_INCLUDED
|
||||
#define BEAST_SQDB_INTO_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
detail::into_type_ptr into(T& t)
|
||||
{
|
||||
return detail::do_into(t,
|
||||
typename detail::exchange_traits<T>::type_family());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
detail::into_type_ptr into(T& t, indicator& ind)
|
||||
{
|
||||
return detail::do_into(t, ind,
|
||||
typename detail::exchange_traits<T>::type_family());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
150
modules/beast_sqdb/api/session.h
Normal file
150
modules/beast_sqdb/api/session.h
Normal file
@@ -0,0 +1,150 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_SESSION_H_INCLUDED
|
||||
#define BEAST_SQDB_SESSION_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
/*============================================================================*/
|
||||
/**
|
||||
@brief A session for the embedded database.
|
||||
|
||||
@ingroup vf_db
|
||||
*/
|
||||
class session
|
||||
{
|
||||
public:
|
||||
session();
|
||||
~session();
|
||||
|
||||
// DEPRECATED!
|
||||
// opens the deferred clone
|
||||
explicit session(session const& deferredClone);
|
||||
Error clone();
|
||||
|
||||
/**
|
||||
Open a database.
|
||||
|
||||
The database at the specified path is opened. The connection string is
|
||||
a set of "{key}={value}" pairs separated with the pipe symbol ('|').
|
||||
Choices for key and value are:
|
||||
|
||||
@code
|
||||
|
||||
timeout = (number) || "infinite"
|
||||
|
||||
mode = "read" || "write" || "create"
|
||||
|
||||
cache = "shared" || "private"
|
||||
|
||||
threads = "single" || "multi"
|
||||
|
||||
@endcode
|
||||
*/
|
||||
Error open(String fileName,
|
||||
std::string options = "timeout=infinite|mode=create|threads=multi");
|
||||
|
||||
void close();
|
||||
|
||||
void begin();
|
||||
Error commit();
|
||||
void rollback();
|
||||
|
||||
bool in_transaction()
|
||||
{
|
||||
return m_bInTransaction;
|
||||
}
|
||||
|
||||
detail::once_type once(Error& error);
|
||||
detail::prepare_type prepare;
|
||||
|
||||
rowid last_insert_rowid();
|
||||
|
||||
std::ostringstream& get_query_stream();
|
||||
|
||||
void log_query(std::string const& query);
|
||||
|
||||
void set_got_data(bool bGotData);
|
||||
bool got_data() const;
|
||||
|
||||
sqlite3* get_connection()
|
||||
{
|
||||
return m_connection;
|
||||
}
|
||||
|
||||
private:
|
||||
Error hard_exec(std::string const& query);
|
||||
|
||||
private:
|
||||
class Sqlite3;
|
||||
SharedObjectPtr <Sqlite3> m_instance;
|
||||
bool m_bInTransaction;
|
||||
sqlite3* m_connection;
|
||||
String m_fileName;
|
||||
std::string m_connectString;
|
||||
|
||||
std::ostringstream m_query_stream;
|
||||
bool m_bGotData;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
103
modules/beast_sqdb/api/statement.h
Normal file
103
modules/beast_sqdb/api/statement.h
Normal file
@@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_STATEMENT_H_INCLUDED
|
||||
#define BEAST_SQDB_STATEMENT_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
//
|
||||
// Lightweight copyable handle to a statement. This
|
||||
// is just a wrapper around the actual statement implementation.
|
||||
//
|
||||
class statement
|
||||
{
|
||||
public:
|
||||
statement(session& s);
|
||||
statement(detail::prepare_temp_type const& prep);
|
||||
~statement();
|
||||
|
||||
statement(statement const& o);
|
||||
void operator= (statement const& o);
|
||||
|
||||
void exchange(detail::into_type_ptr const& i);
|
||||
void exchange(detail::use_type_ptr const& u);
|
||||
|
||||
void prepare(std::string const& query, bool bRepeatable = true);
|
||||
|
||||
Error execute();
|
||||
bool execute_and_fetch(Error& error);
|
||||
bool fetch(Error& error);
|
||||
|
||||
bool got_data() const;
|
||||
rowid last_insert_rowid();
|
||||
|
||||
private:
|
||||
friend class detail::ref_counted_statement;
|
||||
|
||||
void clean_up();
|
||||
|
||||
private:
|
||||
SharedObjectPtr <detail::statement_imp> m_imp;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
82
modules/beast_sqdb/api/transaction.h
Normal file
82
modules/beast_sqdb/api/transaction.h
Normal file
@@ -0,0 +1,82 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_TRANSACTION_H_INCLUDED
|
||||
#define BEAST_SQDB_TRANSACTION_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
class transaction : Uncopyable
|
||||
{
|
||||
public:
|
||||
explicit transaction(session& s);
|
||||
~transaction();
|
||||
|
||||
Error commit();
|
||||
void rollback();
|
||||
|
||||
private:
|
||||
session& m_session;
|
||||
bool m_bHandled;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
117
modules/beast_sqdb/api/type_conversion_traits.h
Normal file
117
modules/beast_sqdb/api/type_conversion_traits.h
Normal file
@@ -0,0 +1,117 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_TYPE_CONVERSION_TRAITS_H_INCLUDED
|
||||
#define BEAST_SQDB_TYPE_CONVERSION_TRAITS_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
// default conversion (copy in to out)
|
||||
template<typename T>
|
||||
struct type_conversion
|
||||
{
|
||||
typedef T base_type;
|
||||
|
||||
static void from_base(base_type const& in, indicator ind, T& out)
|
||||
{
|
||||
// null not allowed
|
||||
if (ind == i_null)
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
|
||||
out = in;
|
||||
}
|
||||
|
||||
static void to_base(T const& in, base_type& out, indicator& ind)
|
||||
{
|
||||
out = in;
|
||||
ind = i_ok;
|
||||
}
|
||||
};
|
||||
|
||||
// Time
|
||||
template <>
|
||||
struct type_conversion <Time>
|
||||
{
|
||||
//typedef sqlite3_int64 base_type;
|
||||
typedef int64 base_type;
|
||||
|
||||
static void from_base(const base_type v, indicator ind, Time& result)
|
||||
{
|
||||
if (ind == i_null)
|
||||
{
|
||||
// jassertfalse
|
||||
result = Time(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Time(v);
|
||||
}
|
||||
}
|
||||
|
||||
static void to_base(const Time& v, base_type& result, indicator& ind)
|
||||
{
|
||||
result = v.toMilliseconds();
|
||||
ind = i_ok;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
94
modules/beast_sqdb/api/use.h
Normal file
94
modules/beast_sqdb/api/use.h
Normal file
@@ -0,0 +1,94 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_USE_H_INCLUDED
|
||||
#define BEAST_SQDB_USE_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
inline detail::use_type_ptr use_null()
|
||||
{
|
||||
return detail::do_use_null();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
detail::use_type_ptr use(T& t)
|
||||
{
|
||||
return detail::do_use(t,
|
||||
typename detail::exchange_traits<T>::type_family());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
detail::use_type_ptr use(T const& t)
|
||||
{
|
||||
return detail::do_use(t,
|
||||
typename detail::exchange_traits<T>::type_family());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
detail::use_type_ptr use(T& t, indicator& ind)
|
||||
{
|
||||
return detail::do_use(t, ind,
|
||||
typename detail::exchange_traits<T>::type_family());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
57
modules/beast_sqdb/beast_sqdb.cpp
Normal file
57
modules/beast_sqdb/beast_sqdb.cpp
Normal file
@@ -0,0 +1,57 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include "BeastConfig.h"
|
||||
|
||||
#include "beast_sqdb.h"
|
||||
|
||||
#include "../beast_sqlite/beast_sqlite.h"
|
||||
|
||||
#if BEAST_MSVC
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4100) // unreferenced formal parmaeter
|
||||
#pragma warning (disable: 4355) // 'this' used in base member
|
||||
#endif
|
||||
|
||||
namespace beast
|
||||
{
|
||||
// implementation headers
|
||||
#include "detail/error_codes.h"
|
||||
#include "detail/statement_imp.h"
|
||||
}
|
||||
|
||||
namespace beast
|
||||
{
|
||||
#include "source/blob.cpp"
|
||||
#include "source/error_codes.cpp"
|
||||
#include "source/into_type.cpp"
|
||||
#include "source/once_temp_type.cpp"
|
||||
#include "source/prepare_temp_type.cpp"
|
||||
#include "source/ref_counted_prepare_info.cpp"
|
||||
#include "source/ref_counted_statement.cpp"
|
||||
#include "source/session.cpp"
|
||||
#include "source/statement.cpp"
|
||||
#include "source/statement_imp.cpp"
|
||||
#include "source/transaction.cpp"
|
||||
#include "source/use_type.cpp"
|
||||
}
|
||||
|
||||
#if BEAST_MSVC
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
132
modules/beast_sqdb/beast_sqdb.h
Normal file
132
modules/beast_sqdb/beast_sqdb.h
Normal file
@@ -0,0 +1,132 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_H_INCLUDED
|
||||
#define BEAST_SQDB_H_INCLUDED
|
||||
|
||||
/** An embedded database wrapper with an intuitive, type-safe interface.
|
||||
|
||||
This collection of classes let's you access embedded SQLite databases
|
||||
using C++ syntax that is very similar to regular SQL.
|
||||
|
||||
This module requires the @ref beast_sqlite external module.
|
||||
*/
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "../beast_core/beast_core.h"
|
||||
|
||||
// forward declares
|
||||
struct sqlite3;
|
||||
struct sqlite3_blob;
|
||||
struct sqlite3_stmt;
|
||||
namespace beast {
|
||||
namespace sqdb {
|
||||
namespace detail {
|
||||
class prepare_temp_type;
|
||||
class ref_counted_statement; // statement.h
|
||||
class statement_imp; // into_type.h, use_type.h
|
||||
}
|
||||
class blob; // exchange_traits.h
|
||||
class session; // statement.h
|
||||
}
|
||||
}
|
||||
|
||||
#if BEAST_MSVC
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable: 4355) // 'this' : used in base member initializer list
|
||||
#endif
|
||||
|
||||
namespace beast
|
||||
{
|
||||
|
||||
#include "api/backend.h"
|
||||
#include "api/transaction.h"
|
||||
#include "detail/type_ptr.h"
|
||||
|
||||
#include "api/blob.h"
|
||||
#include "api/type_conversion_traits.h"
|
||||
|
||||
#include "detail/exchange_traits.h"
|
||||
|
||||
#include "detail/into_type.h"
|
||||
#include "detail/use_type.h"
|
||||
|
||||
#include "api/statement.h"
|
||||
#include "detail/type_conversion.h"
|
||||
|
||||
#include "detail/ref_counted_statement.h"
|
||||
|
||||
#include "api/into.h"
|
||||
#include "api/use.h"
|
||||
#include "detail/ref_counted_prepare_info.h"
|
||||
|
||||
#include "detail/prepare_temp_type.h"
|
||||
|
||||
#include "detail/once_temp_type.h"
|
||||
|
||||
#include "api/session.h"
|
||||
|
||||
}
|
||||
|
||||
#if BEAST_MSVC
|
||||
#pragma warning (pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
77
modules/beast_sqdb/detail/error_codes.h
Normal file
77
modules/beast_sqdb/detail/error_codes.h
Normal file
@@ -0,0 +1,77 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_ERROR_CODES_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_ERROR_CODES_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// Converts SQLITE error codes into an Error object
|
||||
extern const Error sqliteError(const char* sourceFileName,
|
||||
int lineNumber,
|
||||
int sqliteErrorCode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
224
modules/beast_sqdb/detail/exchange_traits.h
Normal file
224
modules/beast_sqdb/detail/exchange_traits.h
Normal file
@@ -0,0 +1,224 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_EXCHANGE_TRAITS_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_EXCHANGE_TRAITS_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
struct basic_type_tag {};
|
||||
struct user_type_tag {};
|
||||
|
||||
// converts a type to exchange_type
|
||||
template<typename T>
|
||||
struct exchange_traits
|
||||
{
|
||||
typedef user_type_tag type_family;
|
||||
|
||||
enum
|
||||
{
|
||||
x_type = exchange_traits<typename type_conversion<T>::base_type>::x_type
|
||||
};
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<bool>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_bool };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<char>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_char };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<short>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_short };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<int>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_int };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<long>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_long };
|
||||
};
|
||||
|
||||
//template<> struct exchange_traits<boost::int64>
|
||||
//template<> struct exchange_traits<sqlite3_int64>
|
||||
template<> struct exchange_traits<int64>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_int64 };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<unsigned char>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_uchar };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<unsigned short>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_ushort };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<unsigned int>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_uint };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<unsigned long>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_ulong };
|
||||
};
|
||||
|
||||
//template<> struct exchange_traits<boost::uint64>
|
||||
//template<> struct exchange_traits<sqlite3_uint64>
|
||||
template<> struct exchange_traits<uint64>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_uint64 };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<float>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_float };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<double>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_double };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<char*>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_cstring };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<char const*>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_cstring };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<wchar_t*>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_cwstring };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<wchar_t const*>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_cwstring };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<std::string>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_stdstring };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<std::wstring>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_stdwstring };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<String>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_beastString };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<std::tm>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_stdtm };
|
||||
};
|
||||
|
||||
template<> struct exchange_traits<blob>
|
||||
{
|
||||
typedef basic_type_tag type_family;
|
||||
enum { x_type = x_blob };
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
131
modules/beast_sqdb/detail/into_type.h
Normal file
131
modules/beast_sqdb/detail/into_type.h
Normal file
@@ -0,0 +1,131 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_INTO_TYPE_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_INTO_TYPE_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// base class for defining output data
|
||||
class into_type_base
|
||||
{
|
||||
public:
|
||||
virtual ~into_type_base() {}
|
||||
virtual void bind(statement_imp& st, int& iCol) = 0;
|
||||
virtual void do_into() = 0;
|
||||
};
|
||||
|
||||
typedef type_ptr<into_type_base> into_type_ptr;
|
||||
|
||||
// standard output types
|
||||
class standard_into_type : public into_type_base
|
||||
{
|
||||
public:
|
||||
standard_into_type(void* data, exchange_type type)
|
||||
: m_data(data), m_type(type), m_ind(0) {}
|
||||
standard_into_type(void* data, exchange_type type, indicator& ind)
|
||||
: m_data(data), m_type(type), m_ind(&ind) {}
|
||||
virtual ~standard_into_type();
|
||||
virtual void bind(statement_imp& st, int& iCol);
|
||||
virtual void do_into();
|
||||
|
||||
private:
|
||||
virtual void convert_from_base() {}
|
||||
|
||||
private:
|
||||
void* m_data;
|
||||
exchange_type m_type;
|
||||
indicator* m_ind;
|
||||
statement_imp* m_st;
|
||||
int m_iCol;
|
||||
};
|
||||
|
||||
// implementation for built-in types without conversions
|
||||
template<typename T>
|
||||
class into_type : public standard_into_type
|
||||
{
|
||||
public:
|
||||
into_type(T& t) : standard_into_type(&t,
|
||||
static_cast <exchange_type>(exchange_traits<T>::x_type)) {}
|
||||
|
||||
into_type(T& t, indicator& ind) : standard_into_type(&t,
|
||||
static_cast<exchange_type>(exchange_traits<T>::x_type), ind) {}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
into_type_ptr do_into(T& t, basic_type_tag)
|
||||
{
|
||||
return into_type_ptr(new into_type<T>(t));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
into_type_ptr do_into(T& t, indicator& ind, basic_type_tag)
|
||||
{
|
||||
return into_type_ptr(new into_type<T>(t, ind));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
116
modules/beast_sqdb/detail/once_temp_type.h
Normal file
116
modules/beast_sqdb/detail/once_temp_type.h
Normal file
@@ -0,0 +1,116 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_ONCE_TEMP_TYPE_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_ONCE_TEMP_TYPE_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class once_temp_type
|
||||
{
|
||||
public:
|
||||
once_temp_type(session& s, Error& error);
|
||||
once_temp_type(once_temp_type const& o);
|
||||
once_temp_type& operator=(once_temp_type const& o);
|
||||
~once_temp_type();
|
||||
|
||||
once_temp_type& operator, (into_type_ptr const& i);
|
||||
once_temp_type& operator, (use_type_ptr const& u);
|
||||
|
||||
template<typename T>
|
||||
once_temp_type& operator<<(T const& t)
|
||||
{
|
||||
m_rcst->accumulate(t);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
ref_counted_statement* m_rcst;
|
||||
};
|
||||
|
||||
class once_type
|
||||
{
|
||||
public:
|
||||
once_type(const once_type& other);
|
||||
once_type(session* s, Error& error);
|
||||
|
||||
template<typename T>
|
||||
once_temp_type operator<<(T const& t)
|
||||
{
|
||||
once_temp_type o(m_session, m_error);
|
||||
o << t;
|
||||
return o;
|
||||
}
|
||||
|
||||
private:
|
||||
once_type& operator= (const once_type&);
|
||||
|
||||
session& m_session;
|
||||
Error& m_error;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
119
modules/beast_sqdb/detail/prepare_temp_type.h
Normal file
119
modules/beast_sqdb/detail/prepare_temp_type.h
Normal file
@@ -0,0 +1,119 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_PREPARE_TEMP_TYPE_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_PREPARE_TEMP_TYPE_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// lightweight copyable wrapper around the prepare info
|
||||
class prepare_temp_type
|
||||
{
|
||||
public:
|
||||
prepare_temp_type(session& s);
|
||||
prepare_temp_type(prepare_temp_type const& o);
|
||||
prepare_temp_type& operator=(prepare_temp_type const& o);
|
||||
|
||||
~prepare_temp_type();
|
||||
|
||||
template<typename T>
|
||||
prepare_temp_type& operator<<(T const& t)
|
||||
{
|
||||
m_rcpi->accumulate(t);
|
||||
return *this;
|
||||
}
|
||||
|
||||
prepare_temp_type& operator, (into_type_ptr const& i);
|
||||
prepare_temp_type& operator, (use_type_ptr const& u);
|
||||
|
||||
ref_counted_prepare_info& get_prepare_info() const
|
||||
{
|
||||
return *m_rcpi;
|
||||
}
|
||||
|
||||
private:
|
||||
ref_counted_prepare_info* m_rcpi;
|
||||
};
|
||||
|
||||
class prepare_type
|
||||
{
|
||||
public:
|
||||
prepare_type() : m_session(NULL) {}
|
||||
prepare_type(session* s) : m_session(s) {}
|
||||
|
||||
template<typename T> prepare_temp_type operator<<(T const& t)
|
||||
{
|
||||
prepare_temp_type p(*m_session);
|
||||
p << t;
|
||||
return p;
|
||||
}
|
||||
|
||||
private:
|
||||
session* m_session;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
89
modules/beast_sqdb/detail/ref_counted_prepare_info.h
Normal file
89
modules/beast_sqdb/detail/ref_counted_prepare_info.h
Normal file
@@ -0,0 +1,89 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_REF_COUNTED_PREPARE_INFO_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_REF_COUNTED_PREPARE_INFO_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// helper that collects statement text and bindings to create the statement
|
||||
class ref_counted_prepare_info : public ref_counted_statement_base
|
||||
{
|
||||
public:
|
||||
ref_counted_prepare_info(session& s);
|
||||
void exchange(into_type_ptr const& i);
|
||||
void exchange(use_type_ptr const& u);
|
||||
virtual void final_action();
|
||||
|
||||
public:
|
||||
std::string get_query() const;
|
||||
|
||||
std::vector <into_type_base*> m_intos;
|
||||
std::vector <use_type_base*> m_uses;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
114
modules/beast_sqdb/detail/ref_counted_statement.h
Normal file
114
modules/beast_sqdb/detail/ref_counted_statement.h
Normal file
@@ -0,0 +1,114 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_REF_COUNTED_STATEMENT_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_REF_COUNTED_STATEMENT_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// used for "once" and "prepare"
|
||||
class ref_counted_statement_base : Uncopyable
|
||||
{
|
||||
public:
|
||||
ref_counted_statement_base(session& s);
|
||||
virtual ~ref_counted_statement_base();
|
||||
|
||||
virtual void final_action() = 0;
|
||||
|
||||
void addref();
|
||||
void release();
|
||||
|
||||
template<typename T> void accumulate(T const& t)
|
||||
{
|
||||
get_query_stream() << t;
|
||||
}
|
||||
|
||||
public:
|
||||
// break circular header dependency
|
||||
std::ostringstream& get_query_stream();
|
||||
|
||||
Error* m_perror;
|
||||
int m_refs;
|
||||
session& m_session;
|
||||
};
|
||||
|
||||
// used for "once"
|
||||
class ref_counted_statement : public ref_counted_statement_base
|
||||
{
|
||||
public:
|
||||
ref_counted_statement(session& s, Error& error);
|
||||
void exchange(into_type_ptr const& i);
|
||||
void exchange(use_type_ptr const& u);
|
||||
|
||||
void final_action();
|
||||
|
||||
private:
|
||||
Error& m_error;
|
||||
statement m_st;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
115
modules/beast_sqdb/detail/statement_imp.h
Normal file
115
modules/beast_sqdb/detail/statement_imp.h
Normal file
@@ -0,0 +1,115 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_STATEMENT_IMP_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_STATEMENT_IMP_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// statement implementation
|
||||
class statement_imp : public SharedObject
|
||||
{
|
||||
public:
|
||||
explicit statement_imp(session& s);
|
||||
explicit statement_imp(prepare_temp_type const& prep);
|
||||
~statement_imp();
|
||||
|
||||
void erase_bindings();
|
||||
void exchange(detail::into_type_ptr const& i);
|
||||
void exchange(detail::use_type_ptr const& u);
|
||||
void clean_up();
|
||||
|
||||
void prepare(std::string const& query, bool bRepeatable = true);
|
||||
Error execute();
|
||||
bool fetch(Error& error);
|
||||
bool got_data() const;
|
||||
|
||||
public:
|
||||
void do_intos();
|
||||
void pre_use();
|
||||
void do_uses();
|
||||
void post_use();
|
||||
void release_resources();
|
||||
rowid last_insert_rowid();
|
||||
|
||||
public:
|
||||
session& m_session;
|
||||
sqlite3_stmt* m_stmt;
|
||||
std::string m_query;
|
||||
bool m_bReady;
|
||||
bool m_bGotData;
|
||||
bool m_bFirstTime;
|
||||
rowid m_last_insert_rowid;
|
||||
|
||||
typedef std::vector <detail::into_type_base*> intos_t;
|
||||
typedef std::vector <detail::use_type_base*> uses_t;
|
||||
|
||||
intos_t m_intos;
|
||||
uses_t m_uses;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
195
modules/beast_sqdb/detail/type_conversion.h
Normal file
195
modules/beast_sqdb/detail/type_conversion.h
Normal file
@@ -0,0 +1,195 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_TYPE_CONVERSION_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_TYPE_CONVERSION_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// used to order into and uses that need conversions
|
||||
template<typename T>
|
||||
struct base_value_holder
|
||||
{
|
||||
typename type_conversion<T>::base_type m_value;
|
||||
};
|
||||
|
||||
// create into_type from type_conversion
|
||||
template <typename T>
|
||||
class conversion_into_type
|
||||
: private base_value_holder<T>
|
||||
, public into_type <typename type_conversion<T>::base_type>
|
||||
, Uncopyable
|
||||
{
|
||||
public:
|
||||
typedef typename type_conversion<T>::base_type BASE_TYPE;
|
||||
|
||||
conversion_into_type(T& value)
|
||||
: into_type<BASE_TYPE>(detail::base_value_holder<T>::m_value, m_own_ind)
|
||||
, m_value(value), m_ind(m_own_ind) {}
|
||||
|
||||
conversion_into_type(T& value, indicator& ind)
|
||||
: into_type<BASE_TYPE>(detail::base_value_holder<T>::m_value, ind)
|
||||
, m_value(value), m_ind(ind) {}
|
||||
|
||||
private:
|
||||
void convert_from_base()
|
||||
{
|
||||
type_conversion<T>::from_base(
|
||||
detail::base_value_holder<T>::m_value, m_ind, m_value);
|
||||
}
|
||||
|
||||
T& m_value;
|
||||
|
||||
indicator m_own_ind;
|
||||
indicator& m_ind;
|
||||
};
|
||||
|
||||
// used to create a use_type from a type_conversion
|
||||
template<typename T>
|
||||
class conversion_use_type
|
||||
: private base_value_holder<T>
|
||||
, public use_type<typename type_conversion<T>::base_type>
|
||||
, Uncopyable
|
||||
{
|
||||
public:
|
||||
typedef typename type_conversion<T>::base_type BASE_TYPE;
|
||||
|
||||
conversion_use_type(T& value)
|
||||
: use_type<BASE_TYPE>(detail::base_value_holder<T>::m_value, m_own_ind)
|
||||
, m_value(value), m_ind(m_own_ind), m_bReadOnly(false) {}
|
||||
|
||||
conversion_use_type(T const& value)
|
||||
: use_type<BASE_TYPE>(detail::base_value_holder<T>::m_value, m_own_ind)
|
||||
, m_value(const_cast<T&>(value)), m_ind(m_own_ind), m_bReadOnly(true) {}
|
||||
|
||||
conversion_use_type(T& value, indicator& ind)
|
||||
: use_type<BASE_TYPE>(detail::base_value_holder<T>::m_value, ind)
|
||||
, m_value(value), m_ind(ind), m_bReadOnly(false) {}
|
||||
|
||||
conversion_use_type(T const& value, indicator& ind)
|
||||
: use_type<BASE_TYPE>(detail::base_value_holder<T>::m_value, ind)
|
||||
, m_value(const_cast<T&>(value)), m_ind(ind), m_bReadOnly(true) {}
|
||||
|
||||
void convert_from_base()
|
||||
{
|
||||
if (!m_bReadOnly)
|
||||
{
|
||||
type_conversion<T>::from_base(
|
||||
detail::base_value_holder<T>::m_value, m_ind, m_value);
|
||||
}
|
||||
}
|
||||
|
||||
void convert_to_base()
|
||||
{
|
||||
type_conversion<T>::to_base(m_value,
|
||||
detail::base_value_holder<T>::m_value, m_ind);
|
||||
}
|
||||
|
||||
private:
|
||||
T& m_value;
|
||||
indicator m_own_ind;
|
||||
indicator& m_ind;
|
||||
bool m_bReadOnly;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
into_type_ptr do_into(T& t, user_type_tag)
|
||||
{
|
||||
return into_type_ptr(new conversion_into_type<T>(t));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
into_type_ptr do_into(T& t, indicator& ind, user_type_tag)
|
||||
{
|
||||
return into_type_ptr(new conversion_into_type<T>(t, ind));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
use_type_ptr do_use(T& t, user_type_tag)
|
||||
{
|
||||
return use_type_ptr(new conversion_use_type<T>(t));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
use_type_ptr do_use(T const& t, user_type_tag)
|
||||
{
|
||||
return use_type_ptr(new conversion_use_type<T>(t));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
use_type_ptr do_use(T& t, indicator& ind, user_type_tag)
|
||||
{
|
||||
return use_type_ptr(new conversion_use_type<T>(t, ind));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
use_type_ptr do_use(T const& t, indicator& ind, user_type_tag)
|
||||
{
|
||||
return use_type_ptr(new conversion_use_type<T>(t, ind));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
97
modules/beast_sqdb/detail/type_ptr.h
Normal file
97
modules/beast_sqdb/detail/type_ptr.h
Normal file
@@ -0,0 +1,97 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_TYPE_PTR_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_TYPE_PTR_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// helper for managing the lifetime of into and use objects
|
||||
template <typename T>
|
||||
class type_ptr
|
||||
{
|
||||
public:
|
||||
type_ptr(T* p) : m_p(p) { }
|
||||
~type_ptr()
|
||||
{
|
||||
delete m_p;
|
||||
}
|
||||
|
||||
T* get() const
|
||||
{
|
||||
return m_p;
|
||||
}
|
||||
void release() const
|
||||
{
|
||||
m_p = 0;
|
||||
}
|
||||
|
||||
private:
|
||||
mutable T* m_p;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
167
modules/beast_sqdb/detail/use_type.h
Normal file
167
modules/beast_sqdb/detail/use_type.h
Normal file
@@ -0,0 +1,167 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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 BEAST_SQDB_DETAIL_USE_TYPE_H_INCLUDED
|
||||
#define BEAST_SQDB_DETAIL_USE_TYPE_H_INCLUDED
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
// base class for defining input data
|
||||
class use_type_base
|
||||
{
|
||||
public:
|
||||
virtual ~use_type_base() {}
|
||||
virtual void bind(statement_imp& st, int& iParam) = 0;
|
||||
virtual void do_use() = 0;
|
||||
virtual void post_use() = 0;
|
||||
virtual void clean_up() = 0;
|
||||
};
|
||||
|
||||
typedef type_ptr<use_type_base> use_type_ptr;
|
||||
|
||||
// handles builtin types
|
||||
class standard_use_type : public use_type_base
|
||||
{
|
||||
public:
|
||||
standard_use_type(void* data, exchange_type type, bool bReadOnly)
|
||||
: m_data(data), m_type(type), m_ind(0), m_bReadOnly(bReadOnly) {}
|
||||
standard_use_type(void* data, exchange_type type, indicator& ind, bool bReadOnly)
|
||||
: m_data(data), m_type(type), m_ind(&ind), m_bReadOnly(bReadOnly) {}
|
||||
virtual ~standard_use_type();
|
||||
virtual void bind(statement_imp& st, int& iParam);
|
||||
virtual void do_use();
|
||||
virtual void post_use();
|
||||
virtual void clean_up();
|
||||
|
||||
virtual void convert_to_base() {}
|
||||
virtual void convert_from_base() {}
|
||||
|
||||
private:
|
||||
void clean_up_backend();
|
||||
|
||||
private:
|
||||
void* m_data;
|
||||
exchange_type m_type;
|
||||
indicator* m_ind;
|
||||
bool m_bReadOnly;
|
||||
statement_imp* m_st;
|
||||
int m_iParam;
|
||||
};
|
||||
|
||||
// worker for use
|
||||
template<typename T>
|
||||
class use_type : public standard_use_type
|
||||
{
|
||||
public:
|
||||
use_type(T& t)
|
||||
: standard_use_type(&t, static_cast<exchange_type>
|
||||
(exchange_traits<T>::x_type), false) {}
|
||||
|
||||
use_type(T const& t)
|
||||
: standard_use_type(const_cast<T*>(&t), static_cast<exchange_type>
|
||||
(exchange_traits<T>::x_type), true) {}
|
||||
|
||||
use_type(T& t, indicator& ind)
|
||||
: standard_use_type(&t, static_cast<exchange_type>
|
||||
(exchange_traits<T>::x_type), ind, false) {}
|
||||
|
||||
use_type(T const& t, indicator& ind)
|
||||
: standard_use_type(const_cast<T*>(&t), static_cast<exchange_type>
|
||||
(exchange_traits<T>::x_type), ind, true) {}
|
||||
};
|
||||
|
||||
// helpers for builtins
|
||||
inline use_type_ptr do_use_null()
|
||||
{
|
||||
return use_type_ptr(new standard_use_type(0, x_null, true));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
use_type_ptr do_use(T& t, basic_type_tag)
|
||||
{
|
||||
return use_type_ptr(new use_type<T>(t));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
use_type_ptr do_use(T const& t, basic_type_tag)
|
||||
{
|
||||
return use_type_ptr(new use_type<T>(t));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
use_type_ptr do_use(T& t, indicator& ind, basic_type_tag)
|
||||
{
|
||||
return use_type_ptr(new use_type<T>(t, ind));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
use_type_ptr do_use(T const& t, indicator& ind, basic_type_tag)
|
||||
{
|
||||
return use_type_ptr(new use_type<T>(t, ind));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
120
modules/beast_sqdb/source/blob.cpp
Normal file
120
modules/beast_sqdb/source/blob.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
blob::blob()
|
||||
: m_blob(0)
|
||||
{
|
||||
}
|
||||
|
||||
blob::~blob()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
Error blob::select(session& s,
|
||||
char const* zTable,
|
||||
char const* zColumn,
|
||||
rowid id,
|
||||
bool readAndWrite) noexcept
|
||||
{
|
||||
close();
|
||||
|
||||
m_session = &s;
|
||||
|
||||
int result = sqlite3_blob_open(s.get_connection(),
|
||||
"main",
|
||||
zTable,
|
||||
zColumn,
|
||||
id,
|
||||
readAndWrite ? 1 : 0,
|
||||
&m_blob);
|
||||
|
||||
return detail::sqliteError(__FILE__, __LINE__, result);
|
||||
}
|
||||
|
||||
std::size_t blob::get_len()
|
||||
{
|
||||
return sqlite3_blob_bytes(m_blob);
|
||||
}
|
||||
|
||||
Error blob::read(std::size_t offset, void* buf, std::size_t toRead)
|
||||
{
|
||||
return detail::sqliteError(__FILE__, __LINE__,
|
||||
sqlite3_blob_read(m_blob, static_cast<char*>(buf), toRead, offset));
|
||||
}
|
||||
|
||||
Error blob::write(std::size_t offset, void const* buf, std::size_t toWrite)
|
||||
{
|
||||
return detail::sqliteError(__FILE__, __LINE__,
|
||||
sqlite3_blob_write(m_blob, buf, toWrite, offset));
|
||||
}
|
||||
|
||||
void blob::close()
|
||||
{
|
||||
if (m_blob)
|
||||
{
|
||||
sqlite3_blob_close(m_blob);
|
||||
m_blob = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
232
modules/beast_sqdb/source/error_codes.cpp
Normal file
232
modules/beast_sqdb/source/error_codes.cpp
Normal file
@@ -0,0 +1,232 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
const Error sqliteError(const char* sourceFileName,
|
||||
int lineNumber,
|
||||
int sqliteErrorCode)
|
||||
{
|
||||
/*
|
||||
jassert (sqliteErrorCode != SQLITE_ROW &&
|
||||
sqliteErrorCode != SQLITE_DONE);
|
||||
*/
|
||||
|
||||
Error e;
|
||||
String s;
|
||||
Error::Code c;
|
||||
|
||||
switch (sqliteErrorCode)
|
||||
{
|
||||
// should never get these two here but include them just in case
|
||||
case SQLITE_ROW:
|
||||
case SQLITE_DONE:
|
||||
|
||||
case SQLITE_OK:
|
||||
// this is fine, and lets us avoid having to explicitly
|
||||
// check for SQLITE_OK and just deal in terms of the Error object.
|
||||
c = Error::success;
|
||||
break;
|
||||
|
||||
case SQLITE_ERROR:
|
||||
s = TRANS("an sqlite error or missing database was encountered");
|
||||
c = Error::general;
|
||||
break;
|
||||
|
||||
case SQLITE_INTERNAL:
|
||||
s = TRANS("sqlite encountered an internal logic error");
|
||||
c = Error::unexpected;
|
||||
break;
|
||||
|
||||
case SQLITE_PERM:
|
||||
s = TRANS("sqlite was denied file access permission");
|
||||
c = Error::fileNoPerm;
|
||||
break;
|
||||
|
||||
case SQLITE_ABORT:
|
||||
s = TRANS("the sqlite operation was canceled due to a callback");
|
||||
c = Error::canceled;
|
||||
break;
|
||||
|
||||
case SQLITE_BUSY:
|
||||
s = TRANS("the sqlite database file is locked");
|
||||
c = Error::fileInUse;
|
||||
break;
|
||||
|
||||
case SQLITE_LOCKED:
|
||||
s = TRANS("the sqlite database table was locked");
|
||||
c = Error::fileInUse;
|
||||
break;
|
||||
|
||||
case SQLITE_NOMEM:
|
||||
s = TRANS("sqlite ran out of memory");
|
||||
c = Error::noMemory;
|
||||
break;
|
||||
|
||||
case SQLITE_READONLY:
|
||||
s = TRANS("sqlite tried to write to a read-only database");
|
||||
c = Error::fileNoPerm;
|
||||
break;
|
||||
|
||||
case SQLITE_INTERRUPT:
|
||||
s = TRANS("the sqlite operation was interrupted");
|
||||
c = Error::canceled;
|
||||
break;
|
||||
|
||||
case SQLITE_IOERR:
|
||||
s = TRANS("sqlite encountered a device I/O error");
|
||||
c = Error::fileIOError;
|
||||
break;
|
||||
|
||||
case SQLITE_CORRUPT:
|
||||
s = TRANS("the sqlite database is corrupt");
|
||||
c = Error::invalidData;
|
||||
break;
|
||||
|
||||
case SQLITE_FULL:
|
||||
s = TRANS("the sqlite database is full");
|
||||
c = Error::fileNoSpace;
|
||||
break;
|
||||
|
||||
case SQLITE_CANTOPEN:
|
||||
s = TRANS("the sqlite database could not be opened");
|
||||
c = Error::fileNotFound;
|
||||
break;
|
||||
|
||||
case SQLITE_PROTOCOL:
|
||||
s = TRANS("sqlite encountered a lock protocol error");
|
||||
c = Error::badParameter;
|
||||
break;
|
||||
|
||||
case SQLITE_EMPTY:
|
||||
s = TRANS("the sqlite database is empty");
|
||||
c = Error::noMoreData;
|
||||
break;
|
||||
|
||||
case SQLITE_SCHEMA:
|
||||
s = TRANS("the sqlite database scheme was changed");
|
||||
c = Error::invalidData;
|
||||
break;
|
||||
|
||||
case SQLITE_TOOBIG:
|
||||
s = TRANS("the sqlite string or blob was too large");
|
||||
c = Error::fileNoSpace;
|
||||
break;
|
||||
|
||||
case SQLITE_CONSTRAINT:
|
||||
s = TRANS("the sqlite operation was aborted due to a constraint violation");
|
||||
c = Error::badParameter;
|
||||
break;
|
||||
|
||||
case SQLITE_MISMATCH:
|
||||
s = TRANS("the sqlite data was mismatched");
|
||||
c = Error::badParameter;
|
||||
break;
|
||||
|
||||
case SQLITE_MISUSE:
|
||||
s = TRANS("the sqlite library parameter was invalid");
|
||||
c = Error::badParameter;
|
||||
break;
|
||||
|
||||
case SQLITE_NOLFS:
|
||||
s = TRANS("the sqlite platform feature is unavailable");
|
||||
c = Error::badParameter;
|
||||
break;
|
||||
|
||||
case SQLITE_AUTH:
|
||||
s = TRANS("sqlite authorization was denied");
|
||||
c = Error::fileNoPerm;
|
||||
break;
|
||||
|
||||
case SQLITE_FORMAT:
|
||||
s = TRANS("the auxiliary sqlite database has an invalid format");
|
||||
c = Error::invalidData;
|
||||
break;
|
||||
|
||||
case SQLITE_RANGE:
|
||||
s = TRANS("the sqlite parameter was invalid");
|
||||
c = Error::badParameter;
|
||||
break;
|
||||
|
||||
case SQLITE_NOTADB:
|
||||
s = TRANS("the file is not a sqlite database");
|
||||
c = Error::invalidData;
|
||||
break;
|
||||
|
||||
default:
|
||||
s << TRANS("an unknown sqlite3 error code #")
|
||||
<< String(sqliteErrorCode)
|
||||
<< TRANS("was returned");
|
||||
c = Error::general;
|
||||
break;
|
||||
}
|
||||
|
||||
if (c != Error::success)
|
||||
e.fail(sourceFileName, lineNumber, s, c);
|
||||
|
||||
return e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
301
modules/beast_sqdb/source/into_type.cpp
Normal file
301
modules/beast_sqdb/source/into_type.cpp
Normal file
@@ -0,0 +1,301 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
inline T& as(void* data)
|
||||
{
|
||||
return *static_cast<T*>(data);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void integer_into(void* data, sqlite3_int64 v)
|
||||
{
|
||||
*(static_cast<T*>(data)) = T(v);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
standard_into_type::~standard_into_type()
|
||||
{
|
||||
}
|
||||
|
||||
void standard_into_type::bind(statement_imp& st, int& iCol)
|
||||
{
|
||||
m_st = &st;
|
||||
m_iCol = iCol++;
|
||||
}
|
||||
|
||||
void standard_into_type::do_into()
|
||||
{
|
||||
int colType = sqlite3_column_type(m_st->m_stmt, m_iCol);
|
||||
|
||||
if (colType == SQLITE_NULL)
|
||||
{
|
||||
// null encountered with no indicator
|
||||
if (!m_ind)
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
|
||||
*m_ind = i_null;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_ind)
|
||||
*m_ind = i_ok;
|
||||
|
||||
switch (colType)
|
||||
{
|
||||
case SQLITE_INTEGER:
|
||||
{
|
||||
sqlite3_int64 v = sqlite3_column_int64(m_st->m_stmt, m_iCol);
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case x_bool:
|
||||
as<bool>(m_data) = v != 0;
|
||||
break;
|
||||
|
||||
case x_char:
|
||||
integer_into<char>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_short:
|
||||
integer_into<short>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_int:
|
||||
integer_into<int>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_long:
|
||||
integer_into<long>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_int64:
|
||||
integer_into<int64>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_uchar:
|
||||
integer_into<unsigned char>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_ushort:
|
||||
integer_into<unsigned short>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_uint:
|
||||
integer_into<unsigned int>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_ulong:
|
||||
integer_into<unsigned long>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_uint64:
|
||||
integer_into<uint64>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_beastString:
|
||||
as <String> (m_data) = String(v);
|
||||
break;
|
||||
|
||||
default:
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SQLITE_FLOAT:
|
||||
{
|
||||
double v = sqlite3_column_double(m_st->m_stmt, m_iCol);
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case x_float:
|
||||
as<float>(m_data) = static_cast<float>(v);
|
||||
break;
|
||||
|
||||
case x_double:
|
||||
as<double>(m_data) = v;
|
||||
break;
|
||||
|
||||
case x_beastString:
|
||||
as <String> (m_data) = String(v);
|
||||
break;
|
||||
|
||||
default:
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case SQLITE_TEXT:
|
||||
{
|
||||
switch (m_type)
|
||||
{
|
||||
case x_stdstring:
|
||||
{
|
||||
// excludes terminator
|
||||
int bytes = sqlite3_column_bytes(m_st->m_stmt, m_iCol);
|
||||
unsigned char const* v = sqlite3_column_text(m_st->m_stmt, m_iCol);
|
||||
std::string& result = as<std::string>(m_data);
|
||||
result.assign(reinterpret_cast<char const*>(v), bytes);
|
||||
}
|
||||
break;
|
||||
|
||||
case x_stdwstring:
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
break;
|
||||
|
||||
case x_beastString:
|
||||
{
|
||||
// excludes terminator
|
||||
int bytes = sqlite3_column_bytes(m_st->m_stmt, m_iCol);
|
||||
|
||||
const CharPointer_UTF8::CharType* c = reinterpret_cast
|
||||
<const CharPointer_UTF8::CharType*>
|
||||
(sqlite3_column_text(m_st->m_stmt, m_iCol));
|
||||
|
||||
String& s = as <String> (m_data);
|
||||
s = String(CharPointer_UTF8(c), CharPointer_UTF8(c + bytes));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
sqlite3_int64 v = sqlite3_column_int64(m_st->m_stmt, m_iCol);
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case x_bool:
|
||||
as<bool>(m_data) = v != 0;
|
||||
break;
|
||||
|
||||
case x_char:
|
||||
integer_into<char>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_short:
|
||||
integer_into<short>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_int:
|
||||
integer_into<int>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_long:
|
||||
integer_into<long>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_int64:
|
||||
integer_into<int64>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_uchar:
|
||||
integer_into<unsigned char>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_ushort:
|
||||
integer_into<unsigned short>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_uint:
|
||||
integer_into<unsigned int>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_ulong:
|
||||
integer_into<unsigned long>(m_data, v);
|
||||
break;
|
||||
|
||||
case x_uint64:
|
||||
integer_into<uint64>(m_data, v);
|
||||
break;
|
||||
|
||||
default:
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case SQLITE_BLOB:
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
|
||||
default:
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
};
|
||||
}
|
||||
|
||||
convert_from_base();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
120
modules/beast_sqdb/source/once_temp_type.cpp
Normal file
120
modules/beast_sqdb/source/once_temp_type.cpp
Normal file
@@ -0,0 +1,120 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
once_type::once_type(const once_type& other)
|
||||
: m_session(other.m_session)
|
||||
, m_error(other.m_error)
|
||||
{
|
||||
}
|
||||
|
||||
once_temp_type::once_temp_type(session& s, Error& error)
|
||||
: m_rcst(new ref_counted_statement(s, error))
|
||||
{
|
||||
// new query
|
||||
s.get_query_stream().str("");
|
||||
}
|
||||
|
||||
once_temp_type::once_temp_type(once_temp_type const& o)
|
||||
: m_rcst(o.m_rcst)
|
||||
{
|
||||
m_rcst->addref();
|
||||
}
|
||||
|
||||
once_temp_type& once_temp_type::operator= (once_temp_type const& o)
|
||||
{
|
||||
o.m_rcst->addref();
|
||||
m_rcst->release();
|
||||
m_rcst = o.m_rcst;
|
||||
return *this;
|
||||
}
|
||||
|
||||
once_temp_type::~once_temp_type()
|
||||
{
|
||||
m_rcst->release();
|
||||
}
|
||||
|
||||
once_temp_type& once_temp_type::operator, (into_type_ptr const& i)
|
||||
{
|
||||
m_rcst->exchange(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
once_temp_type& once_temp_type::operator, (use_type_ptr const& u)
|
||||
{
|
||||
m_rcst->exchange(u);
|
||||
return *this;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
once_type::once_type(session* s, Error& error)
|
||||
: m_session(*s)
|
||||
, m_error(error)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
106
modules/beast_sqdb/source/prepare_temp_type.cpp
Normal file
106
modules/beast_sqdb/source/prepare_temp_type.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
prepare_temp_type::prepare_temp_type(session& s)
|
||||
: m_rcpi(new ref_counted_prepare_info(s))
|
||||
{
|
||||
// new query
|
||||
s.get_query_stream().str("");
|
||||
}
|
||||
|
||||
prepare_temp_type::prepare_temp_type(prepare_temp_type const& o)
|
||||
: m_rcpi(o.m_rcpi)
|
||||
{
|
||||
m_rcpi->addref();
|
||||
}
|
||||
|
||||
prepare_temp_type& prepare_temp_type::operator=(prepare_temp_type const& o)
|
||||
{
|
||||
o.m_rcpi->addref();
|
||||
m_rcpi->release();
|
||||
m_rcpi = o.m_rcpi;
|
||||
return *this;
|
||||
}
|
||||
|
||||
prepare_temp_type::~prepare_temp_type()
|
||||
{
|
||||
m_rcpi->release();
|
||||
}
|
||||
|
||||
prepare_temp_type& prepare_temp_type::operator, (into_type_ptr const& i)
|
||||
{
|
||||
m_rcpi->exchange(i);
|
||||
return *this;
|
||||
}
|
||||
|
||||
prepare_temp_type& prepare_temp_type::operator, (use_type_ptr const& u)
|
||||
{
|
||||
m_rcpi->exchange(u);
|
||||
return *this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
105
modules/beast_sqdb/source/ref_counted_prepare_info.cpp
Normal file
105
modules/beast_sqdb/source/ref_counted_prepare_info.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
ref_counted_prepare_info::ref_counted_prepare_info(session& s)
|
||||
: ref_counted_statement_base(s)
|
||||
{
|
||||
}
|
||||
|
||||
void ref_counted_prepare_info::exchange(into_type_ptr const& i)
|
||||
{
|
||||
m_intos.push_back(i.get());
|
||||
i.release();
|
||||
}
|
||||
|
||||
void ref_counted_prepare_info::exchange(use_type_ptr const& u)
|
||||
{
|
||||
m_uses.push_back(u.get());
|
||||
u.release();
|
||||
}
|
||||
|
||||
void ref_counted_prepare_info::final_action()
|
||||
{
|
||||
for (std::size_t i = m_intos.size(); i > 0; --i)
|
||||
{
|
||||
delete m_intos[i - 1];
|
||||
m_intos.resize(i - 1);
|
||||
}
|
||||
|
||||
for (std::size_t i = m_uses.size(); i > 0; --i)
|
||||
{
|
||||
delete m_uses[i - 1];
|
||||
m_uses.resize(i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
std::string ref_counted_prepare_info::get_query() const
|
||||
{
|
||||
return m_session.get_query_stream().str();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
127
modules/beast_sqdb/source/ref_counted_statement.cpp
Normal file
127
modules/beast_sqdb/source/ref_counted_statement.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
ref_counted_statement_base::ref_counted_statement_base(session& s)
|
||||
: m_refs(1)
|
||||
, m_session(s)
|
||||
{
|
||||
}
|
||||
|
||||
ref_counted_statement_base ::~ref_counted_statement_base()
|
||||
{
|
||||
}
|
||||
|
||||
void ref_counted_statement_base::addref()
|
||||
{
|
||||
++m_refs;
|
||||
}
|
||||
|
||||
void ref_counted_statement_base::release()
|
||||
{
|
||||
if (--m_refs == 0)
|
||||
{
|
||||
final_action();
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
|
||||
std::ostringstream& ref_counted_statement_base::get_query_stream()
|
||||
{
|
||||
return m_session.get_query_stream();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
ref_counted_statement::ref_counted_statement(session& s, Error& error)
|
||||
: ref_counted_statement_base(s)
|
||||
, m_error(error)
|
||||
, m_st(s)
|
||||
{
|
||||
}
|
||||
|
||||
void ref_counted_statement::exchange(into_type_ptr const& i)
|
||||
{
|
||||
m_st.exchange(i);
|
||||
}
|
||||
|
||||
void ref_counted_statement::exchange(use_type_ptr const& u)
|
||||
{
|
||||
m_st.exchange(u);
|
||||
}
|
||||
|
||||
void ref_counted_statement::final_action()
|
||||
{
|
||||
m_st.prepare(m_session.get_query_stream().str(), false);
|
||||
|
||||
Error error;
|
||||
m_st.execute_and_fetch(error);
|
||||
m_error = error;
|
||||
|
||||
m_st.clean_up();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
397
modules/beast_sqdb/source/session.cpp
Normal file
397
modules/beast_sqdb/source/session.cpp
Normal file
@@ -0,0 +1,397 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
class session::Sqlite3 : public SharedSingleton <Sqlite3>
|
||||
{
|
||||
private:
|
||||
friend class SharedSingleton <Sqlite3>;
|
||||
|
||||
Sqlite3() : SharedSingleton <Sqlite3> (SingletonLifetime::persistAfterCreation)
|
||||
{
|
||||
int threadSafe = sqlite3_threadsafe();
|
||||
|
||||
if (threadSafe == 0)
|
||||
Throw(Error().fail(__FILE__, __LINE__, Error::assertFailed));
|
||||
|
||||
int result = sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
|
||||
|
||||
if (result != SQLITE_OK)
|
||||
Throw(Error().fail(__FILE__, __LINE__, Error::assertFailed));
|
||||
|
||||
sqlite3_initialize();
|
||||
}
|
||||
|
||||
~Sqlite3()
|
||||
{
|
||||
sqlite3_shutdown();
|
||||
}
|
||||
|
||||
static Sqlite3* createInstance()
|
||||
{
|
||||
return new Sqlite3;
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
session::session()
|
||||
: prepare(this)
|
||||
, m_instance(Sqlite3::getInstance())
|
||||
, m_bInTransaction(false)
|
||||
, m_connection(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
session::session(const session& deferredClone)
|
||||
: prepare(this)
|
||||
, m_instance(Sqlite3::getInstance())
|
||||
, m_bInTransaction(false)
|
||||
, m_connection(nullptr)
|
||||
, m_fileName(deferredClone.m_fileName)
|
||||
, m_connectString(deferredClone.m_connectString)
|
||||
{
|
||||
// shouldn't be needed since deferredClone did it
|
||||
//Sqlite::initialize();
|
||||
}
|
||||
|
||||
session::~session()
|
||||
{
|
||||
close();
|
||||
}
|
||||
|
||||
Error session::clone()
|
||||
{
|
||||
if (m_connection)
|
||||
Throw(Error().fail(__FILE__, __LINE__)); // already open
|
||||
|
||||
return open(m_fileName, m_connectString);
|
||||
}
|
||||
|
||||
/*
|
||||
static int infiniteBusyHandler (void* data, int tries)
|
||||
{
|
||||
boost::this_thread::sleep (boost::posix_time::seconds(1));
|
||||
return 1; // try again
|
||||
}
|
||||
*/
|
||||
|
||||
Error session::open(String fileName, std::string options)
|
||||
{
|
||||
Error err;
|
||||
|
||||
// can't open twice
|
||||
if (m_connection)
|
||||
Throw(err.fail(__FILE__, __LINE__, Error::fileInUse));
|
||||
|
||||
int mode = 0;
|
||||
int flags = 0;
|
||||
int timeout = 0;
|
||||
|
||||
std::stringstream ssconn(options);
|
||||
|
||||
while (!err && !ssconn.eof() && ssconn.str().find('=') >= 0)
|
||||
{
|
||||
std::string key, val;
|
||||
std::getline(ssconn, key, '=');
|
||||
std::getline(ssconn, val, '|');
|
||||
|
||||
if ("timeout" == key)
|
||||
{
|
||||
if ("infinite" == val)
|
||||
{
|
||||
//timeout = -1;
|
||||
timeout = 0x7fffffff;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::istringstream converter(val);
|
||||
converter >> timeout;
|
||||
|
||||
if (timeout < 1)
|
||||
timeout = 1;
|
||||
}
|
||||
}
|
||||
else if ("mode" == key)
|
||||
{
|
||||
if (!(mode & (SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)))
|
||||
{
|
||||
if ("read" == val)
|
||||
{
|
||||
mode = SQLITE_OPEN_READONLY;
|
||||
}
|
||||
else if ("write" == val)
|
||||
{
|
||||
mode = SQLITE_OPEN_READWRITE;
|
||||
}
|
||||
else if ("create" == val)
|
||||
{
|
||||
mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// duplicate
|
||||
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
|
||||
}
|
||||
}
|
||||
|
||||
/* Most native SQLite libraries don't have these experimental features.
|
||||
*/
|
||||
#if ! VF_USE_NATIVE_SQLITE
|
||||
else if ("cache" == key)
|
||||
{
|
||||
if (!(flags & (SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_PRIVATECACHE)))
|
||||
{
|
||||
if ("shared" == val)
|
||||
{
|
||||
flags |= SQLITE_OPEN_SHAREDCACHE;
|
||||
}
|
||||
else if ("private" == val)
|
||||
{
|
||||
flags |= SQLITE_OPEN_PRIVATECACHE;
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// duplicate
|
||||
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
else if ("threads" == key)
|
||||
{
|
||||
if (!(flags & (SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_FULLMUTEX)))
|
||||
{
|
||||
if ("single" == val)
|
||||
{
|
||||
flags |= SQLITE_OPEN_FULLMUTEX;
|
||||
}
|
||||
else if ("multi" == val)
|
||||
{
|
||||
flags |= SQLITE_OPEN_NOMUTEX;
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// duplicate
|
||||
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// unknown option
|
||||
Throw(err.fail(__FILE__, __LINE__, Error::badParameter));
|
||||
}
|
||||
}
|
||||
|
||||
if (!err)
|
||||
{
|
||||
if (! mode)
|
||||
mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE;
|
||||
|
||||
flags |= mode;
|
||||
|
||||
err = detail::sqliteError(__FILE__, __LINE__,
|
||||
sqlite3_open_v2(fileName.toUTF8(), &m_connection, flags, 0));
|
||||
|
||||
if (!err)
|
||||
{
|
||||
if (timeout > 0)
|
||||
{
|
||||
err = detail::sqliteError(__FILE__, __LINE__,
|
||||
sqlite3_busy_timeout(m_connection, timeout));
|
||||
}
|
||||
|
||||
/*
|
||||
else
|
||||
{
|
||||
err = detail::sqliteError (__FILE__, __LINE__,
|
||||
sqlite3_busy_handler(m_connection, infiniteBusyHandler, 0));
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (!err)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
m_connectString = options;
|
||||
}
|
||||
|
||||
if (err)
|
||||
{
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void session::close()
|
||||
{
|
||||
if (m_connection)
|
||||
{
|
||||
sqlite3_close(m_connection);
|
||||
m_connection = 0;
|
||||
m_fileName = String::empty;
|
||||
m_connectString = "";
|
||||
}
|
||||
}
|
||||
|
||||
void session::begin()
|
||||
{
|
||||
bassert(!m_bInTransaction);
|
||||
m_bInTransaction = true;
|
||||
|
||||
//Error error = hard_exec("BEGIN EXCLUSIVE");
|
||||
Error error = hard_exec("BEGIN");
|
||||
|
||||
if (error)
|
||||
Throw(error);
|
||||
}
|
||||
|
||||
Error session::commit()
|
||||
{
|
||||
bassert(m_bInTransaction);
|
||||
m_bInTransaction = false;
|
||||
return hard_exec("COMMIT");
|
||||
}
|
||||
|
||||
void session::rollback()
|
||||
{
|
||||
bassert(m_bInTransaction);
|
||||
m_bInTransaction = false;
|
||||
Error error = hard_exec("ROLLBACK");
|
||||
|
||||
if (error)
|
||||
Throw(error);
|
||||
}
|
||||
|
||||
detail::once_type session::once(Error& error)
|
||||
{
|
||||
return detail::once_type(this, error);
|
||||
}
|
||||
|
||||
rowid session::last_insert_rowid()
|
||||
{
|
||||
return sqlite3_last_insert_rowid(m_connection);
|
||||
}
|
||||
|
||||
std::ostringstream& session::get_query_stream()
|
||||
{
|
||||
return m_query_stream;
|
||||
}
|
||||
|
||||
void session::log_query(std::string const& query)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
||||
void session::set_got_data(bool bGotData)
|
||||
{
|
||||
m_bGotData = bGotData;
|
||||
}
|
||||
|
||||
bool session::got_data() const
|
||||
{
|
||||
return m_bGotData;
|
||||
}
|
||||
|
||||
Error session::hard_exec(std::string const& query)
|
||||
{
|
||||
Error error;
|
||||
sqlite3_stmt* stmt;
|
||||
char const* tail = 0;
|
||||
|
||||
int result = sqlite3_prepare_v2(
|
||||
m_connection,
|
||||
query.c_str(),
|
||||
static_cast<int>(query.size()),
|
||||
&stmt,
|
||||
&tail);
|
||||
|
||||
if (result == SQLITE_OK)
|
||||
{
|
||||
result = sqlite3_step(stmt);
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
if (result != SQLITE_DONE)
|
||||
error = detail::sqliteError(__FILE__, __LINE__, result);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
}
|
||||
139
modules/beast_sqdb/source/statement.cpp
Normal file
139
modules/beast_sqdb/source/statement.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
statement::statement(session& s)
|
||||
: m_imp(new detail::statement_imp(s))
|
||||
{
|
||||
}
|
||||
|
||||
statement::statement(detail::prepare_temp_type const& prep)
|
||||
: m_imp(new detail::statement_imp(prep))
|
||||
{
|
||||
}
|
||||
|
||||
statement::~statement()
|
||||
{
|
||||
}
|
||||
|
||||
statement::statement(statement const& o)
|
||||
: m_imp(o.m_imp)
|
||||
{
|
||||
}
|
||||
|
||||
void statement::operator= (statement const& o)
|
||||
{
|
||||
m_imp = o.m_imp;
|
||||
}
|
||||
|
||||
void statement::exchange(detail::into_type_ptr const& i)
|
||||
{
|
||||
m_imp->exchange(i);
|
||||
}
|
||||
|
||||
void statement::exchange(detail::use_type_ptr const& u)
|
||||
{
|
||||
m_imp->exchange(u);
|
||||
}
|
||||
|
||||
void statement::prepare(std::string const& query, bool bRepeatable)
|
||||
{
|
||||
m_imp->prepare(query, bRepeatable);
|
||||
}
|
||||
|
||||
Error statement::execute()
|
||||
{
|
||||
return m_imp->execute();
|
||||
}
|
||||
|
||||
bool statement::execute_and_fetch(Error& error)
|
||||
{
|
||||
bool gotData = false;
|
||||
|
||||
error = m_imp->execute();
|
||||
|
||||
if (!error)
|
||||
gotData = fetch(error);
|
||||
|
||||
return gotData;
|
||||
}
|
||||
|
||||
bool statement::fetch(Error& error)
|
||||
{
|
||||
return m_imp->fetch(error);
|
||||
}
|
||||
|
||||
bool statement::got_data() const
|
||||
{
|
||||
return m_imp->got_data();
|
||||
}
|
||||
|
||||
rowid statement::last_insert_rowid()
|
||||
{
|
||||
return m_imp->last_insert_rowid();
|
||||
}
|
||||
|
||||
void statement::clean_up()
|
||||
{
|
||||
m_imp->clean_up();
|
||||
}
|
||||
|
||||
}
|
||||
311
modules/beast_sqdb/source/statement_imp.cpp
Normal file
311
modules/beast_sqdb/source/statement_imp.cpp
Normal file
@@ -0,0 +1,311 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
Running a new prepared statement:
|
||||
|
||||
sqlite3_prepare() // create prepared statement
|
||||
sqlite3_bind() // define input variables
|
||||
sqlite3_step() // retrieve next row
|
||||
sqlite3_column() // extract output value
|
||||
sqlite3_finalize() // destroy prepared statement
|
||||
|
||||
Re-using an existing prepared statement
|
||||
|
||||
sqlite3_reset() // reset the statement (input bindings are not cleared)
|
||||
sqlite3_clear_bindings() // set all input variables to NULL
|
||||
AND/OR
|
||||
sqlite3_bind() // define input variables
|
||||
sqlite3_step() // retrieve next row
|
||||
sqlite3_column() // extract output value
|
||||
|
||||
*/
|
||||
|
||||
statement_imp::statement_imp(session& s)
|
||||
: m_session(s)
|
||||
, m_stmt(0)
|
||||
, m_bReady(false)
|
||||
, m_bGotData(false)
|
||||
, m_last_insert_rowid(0)
|
||||
{
|
||||
}
|
||||
|
||||
statement_imp::statement_imp(prepare_temp_type const& prep)
|
||||
: m_session(prep.get_prepare_info().m_session)
|
||||
, m_stmt(0)
|
||||
, m_bReady(false)
|
||||
, m_bGotData(false)
|
||||
{
|
||||
ref_counted_prepare_info& rcpi = prep.get_prepare_info();
|
||||
|
||||
m_intos.swap(rcpi.m_intos);
|
||||
m_uses.swap(rcpi.m_uses);
|
||||
|
||||
prepare(rcpi.get_query());
|
||||
}
|
||||
|
||||
statement_imp::~statement_imp()
|
||||
{
|
||||
clean_up();
|
||||
}
|
||||
|
||||
void statement_imp::erase_bindings()
|
||||
{
|
||||
// delete intos
|
||||
for (std::size_t i = m_intos.size(); i != 0; --i)
|
||||
{
|
||||
into_type_base* p = m_intos[i - 1];
|
||||
delete p;
|
||||
m_intos.resize(i - 1);
|
||||
}
|
||||
|
||||
// delete uses
|
||||
for (std::size_t i = m_uses.size(); i != 0; --i)
|
||||
{
|
||||
use_type_base* p = m_uses[i - 1];
|
||||
p->clean_up();
|
||||
delete p;
|
||||
m_uses.resize(i - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void statement_imp::exchange(detail::into_type_ptr const& i)
|
||||
{
|
||||
m_intos.push_back(i.get());
|
||||
i.release();
|
||||
}
|
||||
|
||||
void statement_imp::exchange(detail::use_type_ptr const& u)
|
||||
{
|
||||
m_uses.push_back(u.get());
|
||||
u.release();
|
||||
}
|
||||
|
||||
void statement_imp::clean_up()
|
||||
{
|
||||
erase_bindings();
|
||||
release_resources();
|
||||
}
|
||||
|
||||
void statement_imp::prepare(std::string const& query, bool bRepeatable)
|
||||
{
|
||||
m_query = query;
|
||||
m_session.log_query(query);
|
||||
m_last_insert_rowid = 0;
|
||||
|
||||
release_resources();
|
||||
|
||||
char const* tail = 0;
|
||||
int result = sqlite3_prepare_v2(
|
||||
m_session.get_connection(),
|
||||
query.c_str(),
|
||||
static_cast<int>(query.size()),
|
||||
&m_stmt,
|
||||
&tail);
|
||||
|
||||
if (result == SQLITE_OK)
|
||||
{
|
||||
m_bReady = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Throw(detail::sqliteError(__FILE__, __LINE__, result));
|
||||
}
|
||||
}
|
||||
|
||||
Error statement_imp::execute()
|
||||
{
|
||||
Error error;
|
||||
|
||||
if (!m_stmt)
|
||||
Throw(Error().fail(__FILE__, __LINE__, Error::badParameter));
|
||||
|
||||
// ???
|
||||
m_bGotData = false;
|
||||
m_session.set_got_data(m_bGotData);
|
||||
|
||||
// binds
|
||||
|
||||
int iCol = 0;
|
||||
|
||||
for (intos_t::iterator iter = m_intos.begin(); iter != m_intos.end(); ++iter)
|
||||
(*iter)->bind(*this, iCol);
|
||||
|
||||
int iParam = 1;
|
||||
|
||||
for (uses_t::iterator iter = m_uses.begin(); iter != m_uses.end(); ++iter)
|
||||
(*iter)->bind(*this, iParam);
|
||||
|
||||
// reset
|
||||
error = detail::sqliteError(__FILE__, __LINE__, sqlite3_reset(m_stmt));
|
||||
|
||||
if (!error)
|
||||
{
|
||||
// set input variables
|
||||
do_uses();
|
||||
|
||||
m_bReady = true;
|
||||
m_bFirstTime = true;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
bool statement_imp::fetch(Error& error)
|
||||
{
|
||||
int result = sqlite3_step(m_stmt);
|
||||
|
||||
if (result == SQLITE_ROW ||
|
||||
result == SQLITE_DONE)
|
||||
{
|
||||
if (m_bFirstTime)
|
||||
{
|
||||
m_last_insert_rowid = m_session.last_insert_rowid();
|
||||
m_bFirstTime = false;
|
||||
}
|
||||
|
||||
if (result == SQLITE_ROW)
|
||||
{
|
||||
m_bGotData = true;
|
||||
m_session.set_got_data(m_bGotData);
|
||||
|
||||
do_intos();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_bGotData = false;
|
||||
m_session.set_got_data(m_bGotData);
|
||||
|
||||
if (result == SQLITE_DONE)
|
||||
{
|
||||
m_bReady = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (result != SQLITE_OK)
|
||||
{
|
||||
m_bGotData = false;
|
||||
error = detail::sqliteError(__FILE__, __LINE__, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
// should never get SQLITE_OK here
|
||||
Throw(Error().fail(__FILE__, __LINE__, Error::assertFailed));
|
||||
}
|
||||
|
||||
return m_bGotData;
|
||||
}
|
||||
|
||||
bool statement_imp::got_data() const
|
||||
{
|
||||
return m_bGotData;
|
||||
}
|
||||
|
||||
void statement_imp::do_intos()
|
||||
{
|
||||
for (intos_t::iterator iter = m_intos.begin(); iter != m_intos.end(); ++iter)
|
||||
(*iter)->do_into();
|
||||
}
|
||||
|
||||
void statement_imp::do_uses()
|
||||
{
|
||||
Error error = detail::sqliteError(__FILE__, __LINE__,
|
||||
sqlite3_clear_bindings(m_stmt));
|
||||
|
||||
if (error)
|
||||
Throw(error);
|
||||
|
||||
for (uses_t::iterator iter = m_uses.begin(); iter != m_uses.end(); ++iter)
|
||||
(*iter)->do_use();
|
||||
}
|
||||
|
||||
void statement_imp::post_use()
|
||||
{
|
||||
// reverse order
|
||||
for (uses_t::reverse_iterator iter = m_uses.rbegin(); iter != m_uses.rend(); ++iter)
|
||||
(*iter)->post_use();
|
||||
}
|
||||
|
||||
void statement_imp::release_resources()
|
||||
{
|
||||
if (m_stmt)
|
||||
{
|
||||
sqlite3_finalize(m_stmt);
|
||||
m_stmt = 0;
|
||||
}
|
||||
|
||||
m_bReady = false;
|
||||
m_bGotData = false;
|
||||
}
|
||||
|
||||
rowid statement_imp::last_insert_rowid()
|
||||
{
|
||||
return m_last_insert_rowid;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
103
modules/beast_sqdb/source/transaction.cpp
Normal file
103
modules/beast_sqdb/source/transaction.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
transaction::transaction(session& s)
|
||||
: m_session(s), m_bHandled(false)
|
||||
{
|
||||
m_session.begin();
|
||||
}
|
||||
|
||||
transaction::~transaction()
|
||||
{
|
||||
if (!m_bHandled)
|
||||
rollback();
|
||||
}
|
||||
|
||||
Error transaction::commit()
|
||||
{
|
||||
Error error;
|
||||
|
||||
// already handled
|
||||
if (m_bHandled)
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
|
||||
// if commit() throws, m_bHandled will remain false
|
||||
// and the destructor will attempt a rollback.
|
||||
|
||||
m_bHandled = true;
|
||||
|
||||
error = m_session.commit();
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void transaction::rollback()
|
||||
{
|
||||
// already handled
|
||||
if (m_bHandled)
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
|
||||
m_session.rollback();
|
||||
m_bHandled = true;
|
||||
}
|
||||
|
||||
}
|
||||
224
modules/beast_sqdb/source/use_type.cpp
Normal file
224
modules/beast_sqdb/source/use_type.cpp
Normal file
@@ -0,0 +1,224 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of Beast: https://github.com/vinniefalco/Beast
|
||||
Copyright 2013, Vinnie Falco <vinnie.falco@gmail.com>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
Portions based on SOCI - The C++ Database Access Library:
|
||||
|
||||
SOCI: http://soci.sourceforge.net/
|
||||
|
||||
This file incorporates work covered by the following copyright
|
||||
and permission notice:
|
||||
|
||||
Copyright (C) 2004 Maciej Sobczak, Stephen Hutton, Mateusz Loskot,
|
||||
Pawel Aleksander Fedorynski, David Courtney, Rafal Bobrowski,
|
||||
Julian Taylor, Henning Basold, Ilia Barahovski, Denis Arnaud,
|
||||
Daniel Lidstr<74>m, Matthieu Kermagoret, Artyom Beilis, Cory Bennett,
|
||||
Chris Weed, Michael Davidsaver, Jakub Stachowski, Alex Ott, Rainer Bauer,
|
||||
Martin Muenstermann, Philip Pemberton, Eli Green, Frederic Chateau,
|
||||
Artyom Tonkikh, Roger Orr, Robert Massaioli, Sergey Nikulov,
|
||||
Shridhar Daithankar, S<>ren Meyer-Eppler, Mario Valesco.
|
||||
|
||||
Boost Software License - Version 1.0, August 17th, 2003
|
||||
|
||||
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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
namespace sqdb
|
||||
{
|
||||
|
||||
namespace detail
|
||||
{
|
||||
|
||||
standard_use_type::~standard_use_type()
|
||||
{
|
||||
}
|
||||
|
||||
void standard_use_type::bind(statement_imp& st, int& iParam)
|
||||
{
|
||||
m_st = &st;
|
||||
m_iParam = iParam++;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
inline T const& as(void const* v)
|
||||
{
|
||||
return *static_cast <T const*>(v);
|
||||
}
|
||||
|
||||
template<typename T, typename L>
|
||||
inline T const& as(void const* v)
|
||||
{
|
||||
T const& val = *static_cast <T const*>(v);
|
||||
|
||||
if (val > T(std::numeric_limits<L>::max()))
|
||||
Throw(Error().fail(__FILE__, __LINE__));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void standard_use_type::do_use()
|
||||
{
|
||||
int result = SQLITE_OK;
|
||||
|
||||
convert_to_base();
|
||||
|
||||
switch (m_type)
|
||||
{
|
||||
case x_null:
|
||||
result = sqlite3_bind_null(m_st->m_stmt, m_iParam);
|
||||
break;
|
||||
|
||||
case x_bool:
|
||||
result = sqlite3_bind_int(m_st->m_stmt, m_iParam, as <bool> (m_data) ? 1 : 0);
|
||||
break;
|
||||
|
||||
case x_char:
|
||||
result = sqlite3_bind_int(m_st->m_stmt, m_iParam, as <char> (m_data));
|
||||
break;
|
||||
|
||||
case x_short:
|
||||
result = sqlite3_bind_int(m_st->m_stmt, m_iParam, as <short> (m_data));
|
||||
break;
|
||||
|
||||
case x_int:
|
||||
result = sqlite3_bind_int(m_st->m_stmt, m_iParam, as <int> (m_data));
|
||||
break;
|
||||
|
||||
case x_long:
|
||||
result = sqlite3_bind_int(m_st->m_stmt, m_iParam, as <long> (m_data));
|
||||
break;
|
||||
|
||||
case x_int64:
|
||||
result = sqlite3_bind_int64(m_st->m_stmt, m_iParam, as <int64> (m_data));
|
||||
break;
|
||||
|
||||
case x_uchar:
|
||||
result = sqlite3_bind_int(m_st->m_stmt, m_iParam, as <unsigned char> (m_data));
|
||||
break;
|
||||
|
||||
case x_ushort:
|
||||
result = sqlite3_bind_int(m_st->m_stmt, m_iParam, as <unsigned short> (m_data));
|
||||
break;
|
||||
|
||||
case x_uint:
|
||||
result = sqlite3_bind_int64(m_st->m_stmt, m_iParam, as <unsigned int> (m_data));
|
||||
break;
|
||||
|
||||
case x_ulong:
|
||||
result = sqlite3_bind_int64(m_st->m_stmt, m_iParam, as <unsigned long> (m_data));
|
||||
break;
|
||||
|
||||
case x_uint64:
|
||||
result = sqlite3_bind_int64(m_st->m_stmt, m_iParam, as <sqlite3_uint64, sqlite3_int64> (m_data));
|
||||
break;
|
||||
|
||||
case x_float:
|
||||
result = sqlite3_bind_double(m_st->m_stmt, m_iParam, as <float> (m_data));
|
||||
break;
|
||||
|
||||
case x_double:
|
||||
result = sqlite3_bind_double(m_st->m_stmt, m_iParam, as <double> (m_data));
|
||||
break;
|
||||
|
||||
case x_cstring:
|
||||
result = sqlite3_bind_text(m_st->m_stmt, m_iParam, as <char*> (m_data), -1, SQLITE_STATIC);
|
||||
break;
|
||||
|
||||
case x_cwstring:
|
||||
result = sqlite3_bind_text16(m_st->m_stmt, m_iParam, as <wchar_t*> (m_data), -1, SQLITE_STATIC);
|
||||
break;
|
||||
|
||||
case x_stdstring:
|
||||
{
|
||||
std::string const& s = as <std::string> (m_data);
|
||||
result = sqlite3_bind_text(m_st->m_stmt,
|
||||
m_iParam,
|
||||
s.c_str(),
|
||||
s.size() * sizeof(s[0]),
|
||||
SQLITE_STATIC);
|
||||
}
|
||||
break;
|
||||
|
||||
case x_stdwstring:
|
||||
{
|
||||
std::wstring const& s = as <std::wstring> (m_data);
|
||||
result = sqlite3_bind_text16(m_st->m_stmt,
|
||||
m_iParam,
|
||||
s.c_str(),
|
||||
s.size() * sizeof(s[0]),
|
||||
SQLITE_STATIC);
|
||||
}
|
||||
break;
|
||||
|
||||
case x_beastString:
|
||||
{
|
||||
String const& s = as <String> (m_data);
|
||||
result = sqlite3_bind_text(m_st->m_stmt,
|
||||
m_iParam,
|
||||
s.toUTF8(),
|
||||
-1,
|
||||
SQLITE_STATIC);
|
||||
}
|
||||
break;
|
||||
|
||||
case x_stdtm:
|
||||
case x_blob:
|
||||
default:
|
||||
Throw(Error().fail(__FILE__, __LINE__, Error::badParameter));
|
||||
}
|
||||
|
||||
if (result != SQLITE_OK)
|
||||
Throw(detail::sqliteError(__FILE__, __LINE__, result));
|
||||
}
|
||||
|
||||
void standard_use_type::post_use()
|
||||
{
|
||||
convert_from_base();
|
||||
}
|
||||
|
||||
void standard_use_type::clean_up()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user