LeechCraft 0.6.70-14794-g33744ae6ce
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
sqliteimpl.h
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#pragma once
10
11#include <util/sll/visitor.h>
12#include "oraltypes.h"
13#include "oraldetailfwd.h"
14#include "impldefs.h"
15
17{
18 using QSqlQuery_ptr = std::shared_ptr<QSqlQuery>;
19
21 {
22 const QSqlDatabase DB_;
23
24 std::array<QSqlQuery_ptr, InsertAction::StaticCount () + 1> Queries_;
25 const QString InsertSuffix_;
26 public:
27 InsertQueryBuilder (const QSqlDatabase& db, const CachedFieldsData& data)
28 : DB_ { db }
29 , InsertSuffix_ { " INTO " + data.Table_ +
30 " (" + data.Fields_.join (", ") + ") VALUES (" +
31 data.BoundFields_.join (", ") + ");" }
32 {
33 }
34
36 {
37 auto& query = Queries_ [action.Selector_.index ()];
38 if (!query)
39 {
40 query = std::make_shared<QSqlQuery> (DB_);
41 query->prepare (GetInsertPrefix (action) + InsertSuffix_);
42 }
43 return query;
44 }
45 private:
46 QString GetInsertPrefix (InsertAction action)
47 {
48 return Visit (action.Selector_,
49 [] (InsertAction::DefaultTag) { return "INSERT"; },
50 [] (InsertAction::IgnoreTag) { return "INSERT OR IGNORE"; },
51 [] (InsertAction::Replace) { return "INSERT OR REPLACE"; });
52 }
53 };
54
56 {
57 public:
58 struct TypeLits
59 {
60 inline static const QString IntAutoincrement { "INTEGER PRIMARY KEY AUTOINCREMENT" };
61 inline static const QString Binary { "BLOB" };
62 };
63
64 inline static const QString LimitNone { "-1" };
65
66 auto MakeInsertQueryBuilder (const QSqlDatabase& db, const CachedFieldsData& data) const
67 {
68 return std::make_unique<InsertQueryBuilder> (db, data);
69 }
70 };
71}
72
73namespace LC::Util::oral
74{
76}
auto MakeInsertQueryBuilder(const QSqlDatabase &db, const CachedFieldsData &data) const
Definition: sqliteimpl.h:66
InsertQueryBuilder(const QSqlDatabase &db, const CachedFieldsData &data)
Definition: sqliteimpl.h:27
QSqlQuery_ptr GetQuery(InsertAction action) override
Definition: sqliteimpl.h:35
Fields_t Fields_
std::shared_ptr< QSqlQuery > QSqlQuery_ptr
Definition: sqliteimpl.h:18
auto Visit(const Either< Left, Right > &either, Args &&... args)
Definition: either.h:200
ActionSelector_t Selector_
Definition: oraltypes.h:200
static constexpr auto StaticCount()
Definition: oraltypes.h:194