blob: 4695dfd74344cf7dcb55dd74316fe0887fa1507c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
/*
* Copyright (C) 2004, Leo Seib, Hannover
*
* Project:SQLiteDataset C++ Dynamic Library
* Module: SQLiteDataset class header file
* Author: Leo Seib E-Mail: leoseib@web.de
* Begin: 5/04/2002
*
* SPDX-License-Identifier: MIT
* See LICENSES/README.md for more information.
*/
#pragma once
#include "dataset.h"
#include <stdio.h>
#include <sqlite3.h>
namespace dbiplus
{
/***************** Class SqliteDatabase definition ******************
class 'SqliteDatabase' connects with Sqlite-server
******************************************************************/
class SqliteDatabase : public Database
{
protected:
/* connect descriptor */
sqlite3* conn;
bool _in_transaction;
int last_err;
public:
/* default constructor */
SqliteDatabase();
/* destructor */
~SqliteDatabase() override;
Dataset* CreateDataset() const override;
/* func. returns connection handle with SQLite-server */
sqlite3* getHandle() { return conn; }
/* func. returns current status about SQLite-server connection */
int status() override;
int setErr(int err_code, const char* qry) override;
/* func. returns error message if error occurs */
const char* getErrorMsg() override;
/* sets a new host name */
void setHostName(const char* newHost) override;
/* sets a database name */
void setDatabase(const char* newDb) override;
/* func. connects to database-server */
int connect(bool create) override;
/* func. disconnects from database-server */
void disconnect() override;
/* func. creates new database */
int create() override;
/* func. deletes database */
int drop() override;
/* check if database exists (ie has tables/views defined) */
bool exists() override;
/* \brief copy database */
int copy(const char* backup_name) override;
/* \brief drop all extra analytics from database */
int drop_analytics(void) override;
long nextid(const char* seq_name) override;
/* virtual methods for transaction */
void start_transaction() override;
void commit_transaction() override;
void rollback_transaction() override;
/* virtual methods for formatting */
std::string vprepare(const char* format, va_list args) override;
bool in_transaction() override { return _in_transaction; }
};
/***************** Class SqliteDataset definition *******************
class 'SqliteDataset' does a query to SQLite-server
******************************************************************/
class SqliteDataset : public Dataset
{
protected:
sqlite3* handle();
/* Makes direct queries to database */
virtual void make_query(StringList& _sql);
/* Makes direct inserts into database */
void make_insert() override;
/* Edit SQL */
void make_edit() override;
/* Delete SQL */
void make_deletion() override;
//static int sqlite_callback(void* res_ptr,int ncol, char** result, char** cols);
/* This function works only with MySQL database
Filling the fields information from select statement */
void fill_fields() override;
/* Changing field values during dataset navigation */
virtual void free_row(); // free the memory allocated for the current row
public:
/* constructor */
SqliteDataset();
explicit SqliteDataset(SqliteDatabase* newDb);
/* destructor */
~SqliteDataset() override;
/* set autorefresh boolean value (if true - refresh the data after edit()
or insert() operations default = false) */
void set_autorefresh(bool val);
/* opens a query & then sets a query results */
void open() override;
void open(const std::string& sql) override;
/* func. executes a query without results to return */
int exec() override;
int exec(const std::string& sql) override;
const void* getExecRes() override;
/* as open, but with our query exec Sql */
bool query(const std::string& query) override;
/* func. closes a query */
void close(void) override;
/* Cancel changes, made in insert or edit states of dataset */
void cancel() override;
/* last inserted id */
int64_t lastinsertid() override;
/* sequence numbers */
long nextid(const char* seq_name) override;
/* sequence numbers */
int num_rows() override;
/* interrupt any pending database operation */
void interrupt() override;
bool bof() override;
bool eof() override;
void first() override;
void last() override;
void prev() override;
void next() override;
/* Go to record No (starting with 0) */
bool seek(int pos = 0) override;
bool dropIndex(const char* table, const char* index) override;
};
} // namespace dbiplus
|