IStatement.h
1/* Copyright (C) 2006-2026 by Tommi Maekitalo
2 Copyright (C) 2006-2026 by Marc Boris Duerner
3 SPDX-License-Identifier: LGPL-2.1-or-later WITH mif-exception
4*/
5
6#ifndef PT_DB_ISTATEMENT_H
7#define PT_DB_ISTATEMENT_H
8
9#include <Pt/RefCounted.h>
10#include <Pt/Db/Api.h>
11#include <Pt/Db/Blob.h>
12#include <Pt/Signal.h>
13#include <string>
14
15namespace Pt {
16
17class Date;
18class Time;
19class DateTime;
20
21namespace Db {
22
23class Result;
24class Row;
25class Value;
26class ICursor;
27class IConnection;
28
29
32class PT_DB_API IStatement : public RefCounted
33{
34 friend class IConnection;
35
36 public:
37 typedef std::size_t size_type;
38
42 { return _executeFinished; }
43
47 { return _selectFinished; }
48
51 long long lastInsertId() const
52 { return _lastInsertId; }
53
56 IConnection* connection()
57 { return _conn; }
58
61 virtual void clear() = 0;
62
65 virtual void setNull(const std::string& col) = 0;
66
69 virtual void setBool(const std::string& col, bool data) = 0;
70
73 virtual void setInt(const std::string& col, int data) = 0;
74
77 virtual void setUnsigned(const std::string& col, unsigned data) = 0;
78
81 virtual void setFloat(const std::string& col, float data) = 0;
82
85 virtual void setDouble(const std::string& col, double data) = 0;
86
89 virtual void setChar(const std::string& col, char data) = 0;
90
93 virtual void setString(const std::string& col, const std::string& data) = 0;
94
97 virtual void setBlob(const std::string& col, const Blob& data) = 0;
98
101 virtual void setDate(const std::string& col, const Date& data) = 0;
102
105 virtual void setTime(const std::string& col, const Time& data) = 0;
106
109 virtual void setDatetime(const std::string& col, const DateTime& data) = 0;
110
111 protected:
112 explicit IStatement(IConnection* conn)
113 : _conn(conn)
114 , _lastInsertId(0)
115 {}
116
117 protected:
118 virtual ICursor* onCreateCursor() = 0;
119
120 protected:
121 virtual size_type onExecute() = 0;
122
123 virtual void onBeginExec() = 0;
124
125 virtual size_type onEndExec() = 0;
126
127 protected:
128 virtual Result onSelect() = 0;
129
130 virtual Row onSelectRow() = 0;
131
132 virtual Value onSelectValue() = 0;
133
134 virtual void onBeginSelect() = 0;
135
136 virtual Result onEndSelect() = 0;
137
138 protected:
139 void setLastInsertId(long long id)
140 { _lastInsertId = id; }
141
142 private:
143 Signal<> _executeFinished;
144 Signal<> _selectFinished;
145 IConnection* _conn;
146 long long _lastInsertId;
147};
148
149} // namespace Db
150
151} // namespace Pt
152
153#endif // PT_DB_ISTATEMENT_H
Combined Date and Time value.
Definition DateTime.h:66
Date expressed in year, month, and day.
Definition Date.h:104
Copy-on-write binary large object.
Definition Blob.h:144
Database connection backend.
Definition IConnection.h:44
Batch-cursor backend.
Definition ICursor.h:26
virtual void setDate(const std::string &col, const Date &data)=0
Sets the host variable col to data.
virtual void setTime(const std::string &col, const Time &data)=0
Sets the host variable col to data.
long long lastInsertId() const
Returns the generated row id of the last insert.
Definition IStatement.h:51
virtual void setString(const std::string &col, const std::string &data)=0
Sets the host variable col to data.
virtual void clear()=0
Sets all host variables to NULL.
Signal & selectFinished()
Signal emitted when an asynchronous select completes.
Definition IStatement.h:46
virtual void setUnsigned(const std::string &col, unsigned data)=0
Sets the host variable col to data.
virtual void setBool(const std::string &col, bool data)=0
Sets the host variable col to data.
virtual void setNull(const std::string &col)=0
Sets the host variable col to NULL.
virtual void setDatetime(const std::string &col, const DateTime &data)=0
Sets the host variable col to data.
Signal & executeFinished()
Signal emitted when asynchronous execution completes.
Definition IStatement.h:41
virtual void setFloat(const std::string &col, float data)=0
Sets the host variable col to data.
virtual void setInt(const std::string &col, int data)=0
Sets the host variable col to data.
virtual void setBlob(const std::string &col, const Blob &data)=0
Sets the host variable col to data.
virtual void setDouble(const std::string &col, double data)=0
Sets the host variable col to data.
IConnection * connection()
Returns the connection that owns this statement.
Definition IStatement.h:56
virtual void setChar(const std::string &col, char data)=0
Sets the host variable col to data.
Buffered query result with random-access rows.
Definition Result.h:42
One row of a buffered query result.
Definition Row.h:34
One column value of a query result.
Definition Value.h:35
Multicast Signal to call multiple slots.
Definition Signal.h:190
Time expressed in hours, minutes, seconds and milliseconds.
Definition Time.h:98
Portable SQL database access.
Core module.
Definition Allocator.h:33