20#include "SqlitePreparedStatement.h"
21#include "KDbPreparedStatement.h"
22#include "sqlite_debug.h"
24SqlitePreparedStatement::SqlitePreparedStatement(SqliteConnectionInternal* conn)
26 , SqliteConnectionInternal(conn->connection)
32SqlitePreparedStatement::~SqlitePreparedStatement()
38 m_sqlResult = connection->prepareSql(sql);
39 m_result = connection->result();
40 return m_sqlResult && !m_result.
isError();
47 int res = sqlite3_bind_null(sqlResult()->prepared_st, par);
48 if (res != SQLITE_OK) {
50 storeResult(&m_result);
58 int res = sqlite3_bind_text(sqlResult()->prepared_st, par,
60 if (res != SQLITE_OK) {
62 storeResult(&m_result);
68 switch (field->
type()) {
74 const int intValue = value.
toInt(&ok);
76 int res = sqlite3_bind_int(sqlResult()->prepared_st, par, intValue);
77 if (res != SQLITE_OK) {
79 storeResult(&m_result);
83 int res = sqlite3_bind_null(sqlResult()->prepared_st, par);
84 if (res != SQLITE_OK) {
86 storeResult(&m_result);
94 int res = sqlite3_bind_double(sqlResult()->prepared_st, par, value.
toDouble());
95 if (res != SQLITE_OK) {
97 storeResult(&m_result);
105 const qint64 int64Value = value.
toLongLong(&ok);
107 int res = sqlite3_bind_int64(sqlResult()->prepared_st, par, int64Value);
108 if (res != SQLITE_OK) {
110 storeResult(&m_result);
114 int res = sqlite3_bind_null(sqlResult()->prepared_st, par);
115 if (res != SQLITE_OK) {
117 storeResult(&m_result);
124 int res = sqlite3_bind_text(sqlResult()->prepared_st, par, value.
toBool() ?
"1" :
"0",
125 1, SQLITE_TRANSIENT );
126 if (res != SQLITE_OK) {
128 storeResult(&m_result);
133 case KDbField::Time: {
134 int res = sqlite3_bind_text(sqlResult()->prepared_st, par,
135 qPrintable(KDbUtils::toISODateStringWithMs(value.
toTime())),
137 if (res != SQLITE_OK) {
139 storeResult(&m_result);
144 case KDbField::Date: {
145 int res = sqlite3_bind_text(sqlResult()->prepared_st, par,
148 if (res != SQLITE_OK) {
150 storeResult(&m_result);
155 case KDbField::DateTime: {
156 int res = sqlite3_bind_text(sqlResult()->prepared_st, par,
157 qPrintable(KDbUtils::toISODateStringWithMs(value.
toDateTime())),
158 QLatin1String(
"YYYY-MM-DDTHH:MM:SS").size(), SQLITE_TRANSIENT );
159 if (res != SQLITE_OK) {
161 storeResult(&m_result);
168 int res = sqlite3_bind_blob(sqlResult()->prepared_st, par,
170 if (res != SQLITE_OK) {
172 storeResult(&m_result);
178 sqliteWarning() <<
"unsupported field type:"
179 << field->
type() <<
"- NULL value bound to column #" << par;
180 int res = sqlite3_bind_null(sqlResult()->prepared_st, par);
181 if (res != SQLITE_OK) {
183 storeResult(&m_result);
197 Q_UNUSED(insertFieldList);
198 if (!sqlResult()->prepared_st) {
205 itFields != selectFieldList.
constEnd();
206 it += (it == parameters.
constEnd() ? 0 : 1), ++itFields, par++)
213 const int res = sqlite3_step(sqlResult()->prepared_st);
215 const bool ok = res == SQLITE_DONE;
220 storeResult(&m_result);
223 (void)sqlite3_reset(sqlResult()->prepared_st);
228 const bool ok = res == SQLITE_ROW;
229 storeResult(&m_result);
234 storeResult(&m_result);
237 (void)sqlite3_reset(sqlResult()->prepared_st);
Specialized string for escaping.
QList< KDbField * >::ConstIterator ListIterator
iterator for list of fields
Prepared statement interface for backend-dependent implementations.
Type
Defines type of the prepared statement.
@ InsertStatement
INSERT statement will be prepared end executed.
@ SelectStatement
SELECT statement will be prepared end executed.
void setServerErrorCode(int errorCode)
Sets an implementation-specific error code of server-side operation.
QSharedPointer< KDbSqlResult > execute(KDbPreparedStatement::Type type, const KDbField::List &selectFieldList, KDbFieldList *insertFieldList, const KDbPreparedStatementParameters ¶meters) override
For implementation, executes the prepared statement Type of statement is specified by the type parame...
bool prepare(const KDbEscapedString &sql) override
bool bindValue(KDbField *field, const QVariant &value, int arg)
const char * constData() const const
qsizetype length() const const
qsizetype size() const const
QString toString(QStringView format, QCalendar cal) const const
const_iterator constBegin() const const
const_iterator constEnd() const const
QString fromLatin1(QByteArrayView str)
QByteArray toUtf8() const const
bool isNull() const const
bool toBool() const const
QByteArray toByteArray() const const
QDate toDate() const const
QDateTime toDateTime() const const
double toDouble(bool *ok) const const
int toInt(bool *ok) const const
qlonglong toLongLong(bool *ok) const const
QString toString() const const
QTime toTime() const const