File: 2001_build-against-system-sqlite3.patch

package info (click to toggle)
td 1.8.38~git20250919.369ee92%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 22,316 kB
  • sloc: cpp: 361,703; ansic: 4,459; php: 1,776; javascript: 1,671; java: 890; python: 417; cs: 253; sh: 104; makefile: 54
file content (448 lines) | stat: -rw-r--r-- 15,721 bytes parent folder | download
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
Description: Use system's sqlcipher shared lib (rather then an old bundled copy).
Author: Mike Gabriel <mike.gabriel@das-netzwerkeam.de>
Forwarded: not needed, Debian-specific

Index: td/CMakeLists.txt
===================================================================
--- td.orig/CMakeLists.txt
+++ td/CMakeLists.txt
@@ -222,8 +222,7 @@ add_subdirectory(tdactor)
 set(TDNET_ENABLE_INSTALL ${TD_INSTALL_STATIC_LIBRARIES} CACHE BOOL "" FORCE)
 add_subdirectory(tdnet)
 
-set(TDSQLITE_ENABLE_INSTALL ${TD_INSTALL_STATIC_LIBRARIES} CACHE BOOL "" FORCE)
-add_subdirectory(sqlite)
+find_package(sqlcipher)
 
 set(TDDB_ENABLE_INSTALL ${TD_INSTALL_STATIC_LIBRARIES} CACHE BOOL "" FORCE)
 add_subdirectory(tddb)
@@ -1453,7 +1452,6 @@ if (TD_INSTALL_STATIC_LIBRARIES)
   generate_pkgconfig(tdactor "Telegram Library - Actor")
   generate_pkgconfig(tde2e "Telegram Library - E2E")
   generate_pkgconfig(tdnet "Telegram Library - Net")
-  generate_pkgconfig(tdsqlite "Telegram Library - SQLite")
   generate_pkgconfig(tddb "Telegram Library - Database")
   if (MEMPROF)
     # generate_pkgconfig(memprof "memprof - simple library for memory usage profiling")
Index: td/tddb/CMakeLists.txt
===================================================================
--- td.orig/tddb/CMakeLists.txt
+++ td/tddb/CMakeLists.txt
@@ -50,7 +50,7 @@ set(TDDB_SOURCE
 
 add_library(tddb STATIC ${TDDB_SOURCE})
 target_include_directories(tddb PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>)
-target_link_libraries(tddb PUBLIC tdactor tdutils PRIVATE tdsqlite)
+target_link_libraries(tddb PUBLIC tdactor tdutils PRIVATE sqlcipher)
 
 if (NOT CMAKE_CROSSCOMPILING)
   add_executable(binlog_dump td/db/binlog/binlog_dump.cpp)
Index: td/tddb/td/db/SqliteDb.cpp
===================================================================
--- td.orig/tddb/td/db/SqliteDb.cpp
+++ td/tddb/td/db/SqliteDb.cpp
@@ -16,7 +16,7 @@
 #include "td/utils/StringBuilder.h"
 #include "td/utils/Timer.h"
 
-#include "sqlite/sqlite3.h"
+#include <sqlcipher/sqlite3.h>
 
 namespace td {
 
@@ -84,16 +84,16 @@ Status SqliteDb::init(CSlice path, bool
     TRY_STATUS(destroy(path));
   }
 
-  tdsqlite3 *db;
-  CHECK(tdsqlite3_threadsafe() != 0);
+  sqlite3 *db;
+  CHECK(sqlite3_threadsafe() != 0);
   int rc =
-      tdsqlite3_open_v2(path.c_str(), &db, SQLITE_OPEN_READWRITE | (allow_creation ? SQLITE_OPEN_CREATE : 0), nullptr);
+      sqlite3_open_v2(path.c_str(), &db, SQLITE_OPEN_READWRITE | (allow_creation ? SQLITE_OPEN_CREATE : 0), nullptr);
   if (rc != SQLITE_OK) {
     auto res = detail::RawSqliteDb::last_error(db, path);
-    tdsqlite3_close(db);
+    sqlite3_close(db);
     return res;
   }
-  tdsqlite3_busy_timeout(db, 1000 * 5 /* 5 seconds */);
+  sqlite3_busy_timeout(db, 1000 * 5 /* 5 seconds */);
   raw_ = std::make_shared<detail::RawSqliteDb>(db, path.str());
   return Status::OK();
 }
@@ -108,14 +108,14 @@ static int trace_v2_callback(unsigned co
   if (x[0] == '-' && x[1] == '-') {
     trace_callback(ctx, x);
   } else {
-    trace_callback(ctx, tdsqlite3_expanded_sql(static_cast<tdsqlite3_stmt *>(p_raw)));
+    trace_callback(ctx, sqlite3_expanded_sql(static_cast<sqlite3_stmt *>(p_raw)));
   }
 
   return 0;
 }
 
 void SqliteDb::trace(bool flag) {
-  tdsqlite3_trace_v2(raw_->db(), SQLITE_TRACE_STMT, flag ? trace_v2_callback : nullptr, nullptr);
+  sqlite3_trace_v2(raw_->db(), SQLITE_TRACE_STMT, flag ? trace_v2_callback : nullptr, nullptr);
 }
 
 Status SqliteDb::exec(CSlice cmd) {
@@ -124,7 +124,7 @@ Status SqliteDb::exec(CSlice cmd) {
   if (enable_logging_) {
     VLOG(sqlite) << "Start exec " << tag("query", cmd) << tag("database", raw_->db());
   }
-  auto rc = tdsqlite3_exec(raw_->db(), cmd.c_str(), nullptr, nullptr, &msg);
+  auto rc = sqlite3_exec(raw_->db(), cmd.c_str(), nullptr, nullptr, &msg);
   if (rc != SQLITE_OK) {
     CHECK(msg != nullptr);
     if (enable_logging_) {
@@ -310,9 +310,9 @@ Status SqliteDb::destroy(Slice path) {
 }
 
 Result<SqliteStatement> SqliteDb::get_statement(CSlice statement) {
-  tdsqlite3_stmt *stmt = nullptr;
+  sqlite3_stmt *stmt = nullptr;
   auto rc =
-      tdsqlite3_prepare_v2(get_native(), statement.c_str(), static_cast<int>(statement.size()) + 1, &stmt, nullptr);
+      sqlite3_prepare_v2(get_native(), statement.c_str(), static_cast<int>(statement.size()) + 1, &stmt, nullptr);
   if (rc != SQLITE_OK) {
     return Status::Error(PSLICE() << "Failed to prepare SQLite " << tag("statement", statement) << raw_->last_error());
   }
Index: td/tddb/td/db/SqliteDb.h
===================================================================
--- td.orig/tddb/td/db/SqliteDb.h
+++ td/tddb/td/db/SqliteDb.h
@@ -17,8 +17,9 @@
 #include "td/utils/Status.h"
 
 #include <memory>
+#include <sqlcipher/sqlite3.h>
 
-struct tdsqlite3;
+struct sqlite3;
 
 namespace td {
 
@@ -64,7 +65,7 @@ class SqliteDb {
   static Result<SqliteDb> change_key(CSlice path, bool allow_creation, const DbKey &new_db_key,
                                      const DbKey &old_db_key);
 
-  tdsqlite3 *get_native() const {
+  sqlite3 *get_native() const {
     return raw_->db();
   }
 
Index: td/tddb/td/db/SqliteStatement.cpp
===================================================================
--- td.orig/tddb/td/db/SqliteStatement.cpp
+++ td/tddb/td/db/SqliteStatement.cpp
@@ -11,46 +11,46 @@
 #include "td/utils/StackAllocator.h"
 #include "td/utils/StringBuilder.h"
 
-#include "sqlite/sqlite3.h"
+#include <sqlcipher/sqlite3.h>
 
 namespace td {
 
 int VERBOSITY_NAME(sqlite) = VERBOSITY_NAME(DEBUG) + 10;
 
 namespace {
-int printExplainQueryPlan(StringBuilder &sb, tdsqlite3_stmt *pStmt) {
-  const char *zSql = tdsqlite3_sql(pStmt);
+int printExplainQueryPlan(StringBuilder &sb, sqlite3_stmt *pStmt) {
+  const char *zSql = sqlite3_sql(pStmt);
   if (zSql == nullptr) {
     return SQLITE_ERROR;
   }
 
   sb << "Explain query " << zSql;
-  char *zExplain = tdsqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql);
+  char *zExplain = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql);
   if (zExplain == nullptr) {
     return SQLITE_NOMEM;
   }
 
-  tdsqlite3_stmt *pExplain; /* Compiled EXPLAIN QUERY PLAN command */
-  int rc = tdsqlite3_prepare_v2(tdsqlite3_db_handle(pStmt), zExplain, -1, &pExplain, nullptr);
-  tdsqlite3_free(zExplain);
+  sqlite3_stmt *pExplain; /* Compiled EXPLAIN QUERY PLAN command */
+  int rc = sqlite3_prepare_v2(sqlite3_db_handle(pStmt), zExplain, -1, &pExplain, nullptr);
+  sqlite3_free(zExplain);
   if (rc != SQLITE_OK) {
     return rc;
   }
 
-  while (SQLITE_ROW == tdsqlite3_step(pExplain)) {
-    int iSelectid = tdsqlite3_column_int(pExplain, 0);
-    int iOrder = tdsqlite3_column_int(pExplain, 1);
-    int iFrom = tdsqlite3_column_int(pExplain, 2);
-    const char *zDetail = reinterpret_cast<const char *>(tdsqlite3_column_text(pExplain, 3));
+  while (SQLITE_ROW == sqlite3_step(pExplain)) {
+    int iSelectid = sqlite3_column_int(pExplain, 0);
+    int iOrder = sqlite3_column_int(pExplain, 1);
+    int iFrom = sqlite3_column_int(pExplain, 2);
+    const char *zDetail = reinterpret_cast<const char *>(sqlite3_column_text(pExplain, 3));
 
     sb << '\n' << iSelectid << ' ' << iOrder << ' ' << iFrom << ' ' << zDetail;
   }
 
-  return tdsqlite3_finalize(pExplain);
+  return sqlite3_finalize(pExplain);
 }
 }  // namespace
 
-SqliteStatement::SqliteStatement(tdsqlite3_stmt *stmt, std::shared_ptr<detail::RawSqliteDb> db)
+SqliteStatement::SqliteStatement(sqlite3_stmt *stmt, std::shared_ptr<detail::RawSqliteDb> db)
     : stmt_(stmt), db_(std::move(db)) {
   CHECK(stmt != nullptr);
 }
@@ -72,14 +72,14 @@ Result<string> SqliteStatement::explain(
   return sb.as_cslice().str();
 }
 Status SqliteStatement::bind_blob(int id, Slice blob) {
-  auto rc = tdsqlite3_bind_blob(stmt_.get(), id, blob.data(), static_cast<int>(blob.size()), nullptr);
+  auto rc = sqlite3_bind_blob(stmt_.get(), id, blob.data(), static_cast<int>(blob.size()), nullptr);
   if (rc != SQLITE_OK) {
     return last_error();
   }
   return Status::OK();
 }
 Status SqliteStatement::bind_string(int id, Slice str) {
-  auto rc = tdsqlite3_bind_text(stmt_.get(), id, str.data(), static_cast<int>(str.size()), nullptr);
+  auto rc = sqlite3_bind_text(stmt_.get(), id, str.data(), static_cast<int>(str.size()), nullptr);
   if (rc != SQLITE_OK) {
     return last_error();
   }
@@ -87,21 +87,21 @@ Status SqliteStatement::bind_string(int
 }
 
 Status SqliteStatement::bind_int32(int id, int32 value) {
-  auto rc = tdsqlite3_bind_int(stmt_.get(), id, value);
+  auto rc = sqlite3_bind_int(stmt_.get(), id, value);
   if (rc != SQLITE_OK) {
     return last_error();
   }
   return Status::OK();
 }
 Status SqliteStatement::bind_int64(int id, int64 value) {
-  auto rc = tdsqlite3_bind_int64(stmt_.get(), id, value);
+  auto rc = sqlite3_bind_int64(stmt_.get(), id, value);
   if (rc != SQLITE_OK) {
     return last_error();
   }
   return Status::OK();
 }
 Status SqliteStatement::bind_null(int id) {
-  auto rc = tdsqlite3_bind_null(stmt_.get(), id);
+  auto rc = sqlite3_bind_null(stmt_.get(), id);
   if (rc != SQLITE_OK) {
     return last_error();
   }
@@ -127,8 +127,8 @@ StringBuilder &operator<<(StringBuilder
 }
 Slice SqliteStatement::view_blob(int id) {
   LOG_IF(ERROR, view_datatype(id) != Datatype::Blob) << view_datatype(id);
-  auto *data = tdsqlite3_column_blob(stmt_.get(), id);
-  auto size = tdsqlite3_column_bytes(stmt_.get(), id);
+  auto *data = sqlite3_column_blob(stmt_.get(), id);
+  auto size = sqlite3_column_bytes(stmt_.get(), id);
   if (data == nullptr) {
     return Slice();
   }
@@ -136,8 +136,8 @@ Slice SqliteStatement::view_blob(int id)
 }
 Slice SqliteStatement::view_string(int id) {
   LOG_IF(ERROR, view_datatype(id) != Datatype::Text) << view_datatype(id);
-  auto *data = tdsqlite3_column_text(stmt_.get(), id);
-  auto size = tdsqlite3_column_bytes(stmt_.get(), id);
+  auto *data = sqlite3_column_text(stmt_.get(), id);
+  auto size = sqlite3_column_bytes(stmt_.get(), id);
   if (data == nullptr) {
     return Slice();
   }
@@ -145,14 +145,14 @@ Slice SqliteStatement::view_string(int i
 }
 int32 SqliteStatement::view_int32(int id) {
   LOG_IF(ERROR, view_datatype(id) != Datatype::Integer) << view_datatype(id);
-  return tdsqlite3_column_int(stmt_.get(), id);
+  return sqlite3_column_int(stmt_.get(), id);
 }
 int64 SqliteStatement::view_int64(int id) {
   LOG_IF(ERROR, view_datatype(id) != Datatype::Integer) << view_datatype(id);
-  return tdsqlite3_column_int64(stmt_.get(), id);
+  return sqlite3_column_int64(stmt_.get(), id);
 }
 SqliteStatement::Datatype SqliteStatement::view_datatype(int id) {
-  auto type = tdsqlite3_column_type(stmt_.get(), id);
+  auto type = sqlite3_column_type(stmt_.get(), id);
   switch (type) {
     case SQLITE_INTEGER:
       return Datatype::Integer;
@@ -170,7 +170,7 @@ SqliteStatement::Datatype SqliteStatemen
 }
 
 void SqliteStatement::reset() {
-  tdsqlite3_reset(stmt_.get());
+  sqlite3_reset(stmt_.get());
   state_ = State::Start;
 }
 
@@ -178,9 +178,9 @@ Status SqliteStatement::step() {
   if (state_ == State::Finish) {
     return Status::Error("One has to reset statement");
   }
-  VLOG(sqlite) << "Start step " << tag("query", tdsqlite3_sql(stmt_.get())) << tag("statement", stmt_.get())
+  VLOG(sqlite) << "Start step " << tag("query", sqlite3_sql(stmt_.get())) << tag("statement", stmt_.get())
                << tag("database", db_.get());
-  auto rc = tdsqlite3_step(stmt_.get());
+  auto rc = sqlite3_step(stmt_.get());
   VLOG(sqlite) << "Finish step with response " << (rc == SQLITE_ROW ? "ROW" : (rc == SQLITE_DONE ? "DONE" : "ERROR"));
   if (rc == SQLITE_ROW) {
     state_ = State::HaveRow;
@@ -194,8 +194,8 @@ Status SqliteStatement::step() {
   return last_error();
 }
 
-void SqliteStatement::StmtDeleter::operator()(tdsqlite3_stmt *stmt) {
-  tdsqlite3_finalize(stmt);
+void SqliteStatement::StmtDeleter::operator()(sqlite3_stmt *stmt) {
+  sqlite3_finalize(stmt);
 }
 
 Status SqliteStatement::last_error() {
Index: td/tddb/td/db/detail/RawSqliteDb.cpp
===================================================================
--- td.orig/tddb/td/db/detail/RawSqliteDb.cpp
+++ td/tddb/td/db/detail/RawSqliteDb.cpp
@@ -6,8 +6,6 @@
 //
 #include "td/db/detail/RawSqliteDb.h"
 
-#include "sqlite/sqlite3.h"
-
 #include "td/utils/common.h"
 #include "td/utils/logging.h"
 #include "td/utils/misc.h"
@@ -15,14 +13,15 @@
 #include "td/utils/port/Stat.h"
 
 #include <atomic>
+#include <sqlcipher/sqlite3.h>
 
 namespace td {
 namespace detail {
 
 static std::atomic<bool> was_database_destroyed{false};
 
-Status RawSqliteDb::last_error(tdsqlite3 *db, CSlice path) {
-  return Status::Error(PSLICE() << Slice(tdsqlite3_errmsg(db)) << " for database \"" << path << '"');
+Status RawSqliteDb::last_error(sqlite3 *db, CSlice path) {
+  return Status::Error(PSLICE() << Slice(sqlite3_errmsg(db)) << " for database \"" << path << '"');
 }
 
 Status RawSqliteDb::destroy(Slice path) {
@@ -38,7 +37,7 @@ Status RawSqliteDb::destroy(Slice path)
 
 Status RawSqliteDb::last_error() {
   //If database was corrupted, try to delete it.
-  auto code = tdsqlite3_errcode(db_);
+  auto code = sqlite3_errcode(db_);
   if (code == SQLITE_CORRUPT) {
     was_database_destroyed.store(true, std::memory_order_relaxed);
     destroy(path_).ignore();
@@ -52,7 +51,7 @@ bool RawSqliteDb::was_any_database_destr
 }
 
 RawSqliteDb::~RawSqliteDb() {
-  auto rc = tdsqlite3_close(db_);
+  auto rc = sqlite3_close(db_);
   LOG_IF(FATAL, rc != SQLITE_OK) << last_error(db_, path());
 }
 
Index: td/tddb/td/db/detail/RawSqliteDb.h
===================================================================
--- td.orig/tddb/td/db/detail/RawSqliteDb.h
+++ td/tddb/td/db/detail/RawSqliteDb.h
@@ -11,14 +11,14 @@
 #include "td/utils/SliceBuilder.h"
 #include "td/utils/Status.h"
 
-struct tdsqlite3;
+struct sqlite3;
 
 namespace td {
 namespace detail {
 
 class RawSqliteDb {
  public:
-  RawSqliteDb(tdsqlite3 *db, std::string path) : db_(db), path_(std::move(path)) {
+  RawSqliteDb(sqlite3 *db, std::string path) : db_(db), path_(std::move(path)) {
   }
   RawSqliteDb(const RawSqliteDb &) = delete;
   RawSqliteDb(RawSqliteDb &&) = delete;
@@ -35,7 +35,7 @@ class RawSqliteDb {
   }
   static Status destroy(Slice path) TD_WARN_UNUSED_RESULT;
 
-  tdsqlite3 *db() {
+  sqlite3 *db() {
     return db_;
   }
   CSlice path() const {
@@ -43,7 +43,7 @@ class RawSqliteDb {
   }
 
   Status last_error();
-  static Status last_error(tdsqlite3 *db, CSlice path);
+  static Status last_error(sqlite3 *db, CSlice path);
 
   static bool was_any_database_destroyed();
 
@@ -68,7 +68,7 @@ class RawSqliteDb {
   }
 
  private:
-  tdsqlite3 *db_;
+  sqlite3 *db_;
   std::string path_;
   size_t begin_cnt_{0};
   optional<int32> cipher_version_;
Index: td/tddb/td/db/SqliteStatement.h
===================================================================
--- td.orig/tddb/td/db/SqliteStatement.h
+++ td/tddb/td/db/SqliteStatement.h
@@ -16,8 +16,8 @@
 
 #include <memory>
 
-struct tdsqlite3;
-struct tdsqlite3_stmt;
+struct sqlite3;
+struct sqlite3_stmt;
 
 namespace td {
 
@@ -69,17 +69,17 @@ class SqliteStatement {
 
  private:
   friend class SqliteDb;
-  SqliteStatement(tdsqlite3_stmt *stmt, std::shared_ptr<detail::RawSqliteDb> db);
+  SqliteStatement(sqlite3_stmt *stmt, std::shared_ptr<detail::RawSqliteDb> db);
 
   class StmtDeleter {
    public:
-    void operator()(tdsqlite3_stmt *stmt);
+    void operator()(sqlite3_stmt *stmt);
   };
 
   enum class State { Start, HaveRow, Finish };
   State state_ = State::Start;
 
-  std::unique_ptr<tdsqlite3_stmt, StmtDeleter> stmt_;
+  std::unique_ptr<sqlite3_stmt, StmtDeleter> stmt_;
   std::shared_ptr<detail::RawSqliteDb> db_;
 
   Status last_error();