From ece44f5886b6359f5603ec48dc1e790791e622ae Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Wed, 24 Jul 2013 03:07:50 -0700 Subject: [PATCH] Add beast_sqdb module --- SConstruct | 2 + .../Builds/VisualStudio2012/beast.vcxproj | 103 +++++ .../VisualStudio2012/beast.vcxproj.filters | 132 ++++++ .../beast/modules/beast_sqdb/api/backend.h | 111 +++++ Subtrees/beast/modules/beast_sqdb/api/blob.h | 91 ++++ Subtrees/beast/modules/beast_sqdb/api/into.h | 82 ++++ .../beast/modules/beast_sqdb/api/session.h | 150 +++++++ .../beast/modules/beast_sqdb/api/statement.h | 103 +++++ .../modules/beast_sqdb/api/transaction.h | 82 ++++ .../beast_sqdb/api/type_conversion_traits.h | 117 ++++++ Subtrees/beast/modules/beast_sqdb/api/use.h | 94 +++++ .../beast/modules/beast_sqdb/beast_sqdb.cpp | 57 +++ .../beast/modules/beast_sqdb/beast_sqdb.h | 132 ++++++ .../modules/beast_sqdb/detail/error_codes.h | 77 ++++ .../beast_sqdb/detail/exchange_traits.h | 224 ++++++++++ .../modules/beast_sqdb/detail/into_type.h | 131 ++++++ .../beast_sqdb/detail/once_temp_type.h | 116 +++++ .../beast_sqdb/detail/prepare_temp_type.h | 119 ++++++ .../detail/ref_counted_prepare_info.h | 89 ++++ .../beast_sqdb/detail/ref_counted_statement.h | 114 +++++ .../modules/beast_sqdb/detail/statement_imp.h | 115 +++++ .../beast_sqdb/detail/type_conversion.h | 195 +++++++++ .../modules/beast_sqdb/detail/type_ptr.h | 97 +++++ .../modules/beast_sqdb/detail/use_type.h | 167 ++++++++ .../beast/modules/beast_sqdb/source/blob.cpp | 120 ++++++ .../modules/beast_sqdb/source/error_codes.cpp | 232 ++++++++++ .../modules/beast_sqdb/source/into_type.cpp | 301 +++++++++++++ .../beast_sqdb/source/once_temp_type.cpp | 120 ++++++ .../beast_sqdb/source/prepare_temp_type.cpp | 106 +++++ .../source/ref_counted_prepare_info.cpp | 105 +++++ .../source/ref_counted_statement.cpp | 127 ++++++ .../modules/beast_sqdb/source/session.cpp | 397 ++++++++++++++++++ .../modules/beast_sqdb/source/statement.cpp | 139 ++++++ .../beast_sqdb/source/statement_imp.cpp | 311 ++++++++++++++ .../modules/beast_sqdb/source/transaction.cpp | 103 +++++ .../modules/beast_sqdb/source/use_type.cpp | 224 ++++++++++ 36 files changed, 4985 insertions(+) create mode 100644 Subtrees/beast/modules/beast_sqdb/api/backend.h create mode 100644 Subtrees/beast/modules/beast_sqdb/api/blob.h create mode 100644 Subtrees/beast/modules/beast_sqdb/api/into.h create mode 100644 Subtrees/beast/modules/beast_sqdb/api/session.h create mode 100644 Subtrees/beast/modules/beast_sqdb/api/statement.h create mode 100644 Subtrees/beast/modules/beast_sqdb/api/transaction.h create mode 100644 Subtrees/beast/modules/beast_sqdb/api/type_conversion_traits.h create mode 100644 Subtrees/beast/modules/beast_sqdb/api/use.h create mode 100644 Subtrees/beast/modules/beast_sqdb/beast_sqdb.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/beast_sqdb.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/error_codes.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/exchange_traits.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/into_type.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/once_temp_type.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/prepare_temp_type.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/ref_counted_prepare_info.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/ref_counted_statement.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/statement_imp.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/type_conversion.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/type_ptr.h create mode 100644 Subtrees/beast/modules/beast_sqdb/detail/use_type.h create mode 100644 Subtrees/beast/modules/beast_sqdb/source/blob.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/error_codes.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/into_type.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/once_temp_type.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/prepare_temp_type.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/ref_counted_prepare_info.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/ref_counted_statement.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/session.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/statement.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/statement_imp.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/transaction.cpp create mode 100644 Subtrees/beast/modules/beast_sqdb/source/use_type.cpp diff --git a/SConstruct b/SConstruct index 6ada71a71b..ae2888e804 100644 --- a/SConstruct +++ b/SConstruct @@ -122,6 +122,8 @@ COMPILED_FILES = [ 'Subtrees/beast/modules/beast_core/beast_core.cpp', 'Subtrees/beast/modules/beast_crypto/beast_crypto.cpp', 'Subtrees/beast/modules/beast_db/beast_db.cpp', + 'Subtrees/beast/modules/beast_sqdb/beast_sqdb.cpp', + 'Subtrees/beast/modules/beast_sqlite/beast_sqlite.c', 'modules/ripple_app/ripple_app_pt1.cpp', 'modules/ripple_app/ripple_app_pt2.cpp', 'modules/ripple_app/ripple_app_pt3.cpp', diff --git a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj index 99c88c4500..4d97ef0b3d 100644 --- a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj +++ b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj @@ -257,6 +257,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -948,6 +971,86 @@ true true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + true + true + true + true + + + + true + true + true + true + diff --git a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters index 7f02acb998..b649d0e21e 100644 --- a/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters +++ b/Subtrees/beast/Builds/VisualStudio2012/beast.vcxproj.filters @@ -134,6 +134,24 @@ {15a98fee-1b52-45eb-9480-514b8750d755} + + {cbf5f5a3-5d66-4b6d-996d-20ed14b41793} + + + {acd9ab9d-3ba8-4c60-bfb8-36799d9d7a06} + + + {67b47aab-8e6a-4acd-9291-d95a8795d6ad} + + + {e666952d-d490-40a2-aa05-2d63ea23284f} + + + {3f969218-0a32-41f1-8e05-9a47247cf494} + + + {10ef778f-6b81-437e-a6ef-558ff4163acc} + @@ -647,6 +665,75 @@ beast_db\keyvalue + + beast_sqlite + + + beast_sqlite\sqlite + + + beast_sqlite\sqlite + + + beast_sqdb + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\api + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + + + beast_sqdb\detail + @@ -1003,6 +1090,51 @@ beast_db\keyvalue + + beast_sqlite + + + beast_sqlite\sqlite + + + beast_sqdb + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + + + beast_sqdb\source + diff --git a/Subtrees/beast/modules/beast_sqdb/api/backend.h b/Subtrees/beast/modules/beast_sqdb/api/backend.h new file mode 100644 index 0000000000..d36063251c --- /dev/null +++ b/Subtrees/beast/modules/beast_sqdb/api/backend.h @@ -0,0 +1,111 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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ö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 diff --git a/Subtrees/beast/modules/beast_sqdb/api/blob.h b/Subtrees/beast/modules/beast_sqdb/api/blob.h new file mode 100644 index 0000000000..5e4642fd5a --- /dev/null +++ b/Subtrees/beast/modules/beast_sqdb/api/blob.h @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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ö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 diff --git a/Subtrees/beast/modules/beast_sqdb/api/into.h b/Subtrees/beast/modules/beast_sqdb/api/into.h new file mode 100644 index 0000000000..7cccd7fc2d --- /dev/null +++ b/Subtrees/beast/modules/beast_sqdb/api/into.h @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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ö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 +detail::into_type_ptr into(T& t) +{ + return detail::do_into(t, + typename detail::exchange_traits::type_family()); +} + +template +detail::into_type_ptr into(T& t, indicator& ind) +{ + return detail::do_into(t, ind, + typename detail::exchange_traits::type_family()); +} + +} + +#endif \ No newline at end of file diff --git a/Subtrees/beast/modules/beast_sqdb/api/session.h b/Subtrees/beast/modules/beast_sqdb/api/session.h new file mode 100644 index 0000000000..49c6970576 --- /dev/null +++ b/Subtrees/beast/modules/beast_sqdb/api/session.h @@ -0,0 +1,150 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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ö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 m_instance; + bool m_bInTransaction; + sqlite3* m_connection; + String m_fileName; + std::string m_connectString; + + std::ostringstream m_query_stream; + bool m_bGotData; +}; + +} + +#endif diff --git a/Subtrees/beast/modules/beast_sqdb/api/statement.h b/Subtrees/beast/modules/beast_sqdb/api/statement.h new file mode 100644 index 0000000000..b440277c96 --- /dev/null +++ b/Subtrees/beast/modules/beast_sqdb/api/statement.h @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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ö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 m_imp; +}; + +} + +#endif diff --git a/Subtrees/beast/modules/beast_sqdb/api/transaction.h b/Subtrees/beast/modules/beast_sqdb/api/transaction.h new file mode 100644 index 0000000000..08775ab84b --- /dev/null +++ b/Subtrees/beast/modules/beast_sqdb/api/transaction.h @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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ö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 diff --git a/Subtrees/beast/modules/beast_sqdb/api/type_conversion_traits.h b/Subtrees/beast/modules/beast_sqdb/api/type_conversion_traits.h new file mode 100644 index 0000000000..e81a7319d3 --- /dev/null +++ b/Subtrees/beast/modules/beast_sqdb/api/type_conversion_traits.h @@ -0,0 +1,117 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + 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ö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 +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