开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
forked from 陈炳煌/sqlitebrowser
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (16)
标签 (31)
master
coverity_scan
v3.11.x
issue1831_v1
qdarkstyle
no_savepoints_ro_db
v3.10.x
v3.9.x
v3.6.x
v3.5.x
v3.4.x
v3.3.x
utf8grammar
sqlb-3.2.x
sqlb-3.1.x
sqlb-3.x
continuous
v3.11.2
v3.11.1v2
v3.11.1
v3.11.0
v3.11.0-beta3
v3.11.0-beta2
v3.11.0-beta1
v3.11.0-alpha1
v3.10.1
v3.10.0
v3.10.0-beta2
v3.10.0-beta1
v3.9.1
v3.9.0
v3.9.0-beta1
v3.8.0
v3.7.0
v3.6.0
v3.5.1
master
分支 (16)
标签 (31)
master
coverity_scan
v3.11.x
issue1831_v1
qdarkstyle
no_savepoints_ro_db
v3.10.x
v3.9.x
v3.6.x
v3.5.x
v3.4.x
v3.3.x
utf8grammar
sqlb-3.2.x
sqlb-3.1.x
sqlb-3.x
continuous
v3.11.2
v3.11.1v2
v3.11.1
v3.11.0
v3.11.0-beta3
v3.11.0-beta2
v3.11.0-beta1
v3.11.0-alpha1
v3.10.1
v3.10.0
v3.10.0-beta2
v3.10.0-beta1
v3.9.1
v3.9.0
v3.9.0-beta1
v3.8.0
v3.7.0
v3.6.0
v3.5.1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (16)
标签 (31)
master
coverity_scan
v3.11.x
issue1831_v1
qdarkstyle
no_savepoints_ro_db
v3.10.x
v3.9.x
v3.6.x
v3.5.x
v3.4.x
v3.3.x
utf8grammar
sqlb-3.2.x
sqlb-3.1.x
sqlb-3.x
continuous
v3.11.2
v3.11.1v2
v3.11.1
v3.11.0
v3.11.0-beta3
v3.11.0-beta2
v3.11.0-beta1
v3.11.0-alpha1
v3.10.1
v3.10.0
v3.10.0-beta2
v3.10.0-beta1
v3.9.1
v3.9.0
v3.9.0-beta1
v3.8.0
v3.7.0
v3.6.0
v3.5.1
sqlitebrowser
/
src
/
sqlitedb.h
sqlitebrowser
/
src
/
sqlitedb.h
sqlitedb.h 11.24 KB
一键复制 编辑 原始数据 按行查看 历史
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
#ifndef SQLITEDB_H
#define SQLITEDB_H
#include "sql/ObjectIdentifier.h"
#include "sql/sqlitetypes.h"
#include <condition_variable>
#include <memory>
#include <mutex>
#include <functional>
#include <vector>
#include <map>
#include <QObject>
#include <QByteArray>
#include <QStringList>
struct sqlite3;
class CipherSettings;
enum LogMessageType
{
kLogMsg_User,
kLogMsg_App,
kLogMsg_ErrorLog
};
using objectMap = std::multimap<std::string, sqlb::ObjectPtr>; // Maps from object type (table, index, view, trigger) to a pointer to the object representation
using schemaMap = std::map<std::string, objectMap>; // Maps from the schema name (main, temp, attached schemas) to the object map for that schema
int collCompare(void* pArg, int sizeA, const void* sA, int sizeB, const void* sB);
namespace sqlb
{
QString escapeIdentifier(const QString& id);
}
/// represents a single SQLite database. except when noted otherwise,
/// all member functions are to be called from the main UI thread
/// only.
class DBBrowserDB : public QObject
{
Q_OBJECT
private:
/// custom unique_ptr deleter releases database for further use by others
struct DatabaseReleaser
{
explicit DatabaseReleaser(DBBrowserDB * pParent_ = nullptr) : pParent(pParent_) {}
DBBrowserDB * pParent;
void operator() (sqlite3 * db) const
{
if(!db || !pParent)
return;
std::unique_lock<std::mutex> lk(pParent->m);
pParent->db_used = false;
lk.unlock();
emit pParent->databaseInUseChanged(false, QString());
pParent->cv.notify_one();
}
};
public:
explicit DBBrowserDB();
~DBBrowserDB () override {}
bool open(const QString& db, bool readOnly = false);
bool attach(const QString& filename, QString attach_as = "");
bool create ( const QString & db);
bool close();
// This returns the SQLite version as well as the SQLCipher if DB4S is compiled with encryption support
static void getSqliteVersion(QString& sqlite, QString& sqlcipher);
using db_pointer_type = std::unique_ptr<sqlite3, DatabaseReleaser>;
/**
borrow exclusive address to the currently open database, until
releasing the returned unique_ptr.
the intended use case is that the main UI thread can call this
any time, and then optionally pass the obtained pointer to a
background worker, or release it after doing work immediately.
if database is currently used by somebody else, opens a dialog
box and gives user the opportunity to sqlite3_interrupt() the
operation of the current owner, then tries again.
\param user a string that identifies the new user, and which
can be displayed in the dialog box.
\param force_wait if set to true we won't ask the user to cancel
the running query but just wait until it is done.
\returns a unique_ptr containing the SQLite database handle, or
nullptr in case no database is open.
**/
db_pointer_type get (const QString& user, bool force_wait = false);
bool setSavepoint(const QString& pointname = "RESTOREPOINT");
bool releaseSavepoint(const QString& pointname = "RESTOREPOINT");
bool revertToSavepoint(const QString& pointname = "RESTOREPOINT");
bool releaseAllSavepoints();
bool revertAll();
bool dump(const QString& filename, const QStringList& tablesToDump, bool insertColNames, bool insertNew, bool exportSchema, bool exportData, bool keepOldSchema);
enum ChoiceOnUse
{
Ask,
Wait,
CancelOther
};
// Callback to get results from executeSQL(). It is invoked for
// each result row coming out of the evaluated SQL statements. If
// a callback returns true (abort), the executeSQL() method
// returns false (error) without invoking the callback again and
// without running any subsequent SQL statements. The 1st argument
// is the number of columns in the result. The 2nd argument to the
// callback is the text representation of the values, one for each
// column. The 3rd argument is a list of strings where each entry
// represents the name of corresponding result column.
using execCallback = std::function<bool(int, QStringList, QStringList)>;
bool executeSQL(QString statement, bool dirtyDB = true, bool logsql = true, execCallback callback = nullptr);
bool executeMultiSQL(QByteArray query, bool dirty = true, bool log = false);
QByteArray querySingleValueFromDb(const QString& sql, bool log = true, ChoiceOnUse choice = Ask);
const QString& lastError() const { return lastErrorMessage; }
/**
* @brief getRow Executes a sqlite statement to get the rowdata(columns)
* for the given rowid.
* @param schemaName Name of the database schema.
* @param sTableName Table to query.
* @param rowid The rowid to fetch.
* @param rowdata A list of QByteArray containing the row data.
* @return true if statement execution was ok, else false.
*/
bool getRow(const sqlb::ObjectIdentifier& table, const QString& rowid, std::vector<QByteArray>& rowdata);
/**
* @brief Interrupts the currenty running statement as soon as possible.
*/
void interruptQuery();
private:
/**
* @brief max Queries the table t for the max value of field.
* @param tableName Table to query
* @param field Field to get the max value
* @return the max value of the field or 0 on error
*/
QString max(const sqlb::ObjectIdentifier& tableName, const sqlb::Field& field) const;
static int callbackWrapper (void* callback, int numberColumns, char** values, char** columnNames);
public:
void updateSchema();
private:
/**
* @brief Creates an empty insert statement.
* @param schemaName The name of the database schema in which to find the table
* @param pk_value This optional parameter can be used to manually set a specific value for the primary key column
* @return An sqlite conform INSERT INTO statement with empty values. (NULL,'',0)
*/
QString emptyInsertStmt(const std::string& schemaName, const sqlb::Table& t, const QString& pk_value = QString()) const;
public:
QString addRecord(const sqlb::ObjectIdentifier& tablename);
bool deleteRecords(const sqlb::ObjectIdentifier& table, const QStringList& rowids, const sqlb::StringVector& pseudo_pk = {});
bool updateRecord(const sqlb::ObjectIdentifier& table, const std::string& column, const QString& rowid, const QByteArray& value, bool itsBlob, const sqlb::StringVector& pseudo_pk = {});
bool createTable(const sqlb::ObjectIdentifier& name, const sqlb::FieldVector& structure);
bool renameTable(const std::string& schema, const std::string& from_table, const std::string& to_table);
bool addColumn(const sqlb::ObjectIdentifier& tablename, const sqlb::Field& field);
/**
* @brief This type maps from old column names to new column names. Given the old and the new table definition, this suffices to
* track fields between the two.
* USE CASES:
* 1) Don't specify a column at all or specify equal column names: Keep its name as-is.
* 2) Specify different column names: Rename the field.
* 3) Map from an existing column name to a Null string: Delete the column.
* 4) Map from a Null column name to a new column name: Add the column.
*/
using AlterTableTrackColumns = std::map<QString, QString>;
/**
* @brief alterTable Can be used to rename, modify or drop existing columns of a given table
* @param tablename Specifies the schema and name of the table to edit
* @param new_table Specifies the new table schema. This is exactly how the new table is going to look like.
* @param track_columns Maps old column names to new column names. This is used to copy the data from the old table to the new one.
* @param newSchema Set this to a non-empty string to move the table to a new schema
* @return true if renaming was successful, false if not. In the latter case also lastErrorMessage is set
*/
bool alterTable(const sqlb::ObjectIdentifier& tablename, const sqlb::Table& new_table, AlterTableTrackColumns track_columns, std::string newSchemaName = "");
objectMap getBrowsableObjects(const std::string& schema) const;
template<typename T = sqlb::Object>
const std::shared_ptr<T> getObjectByName(const sqlb::ObjectIdentifier& name) const
{
for(auto& it : schemata.at(name.schema()))
{
if(it.second->name() == name.name())
return std::dynamic_pointer_cast<T>(it.second);
}
return std::shared_ptr<T>();
}
bool isOpen() const;
bool encrypted() const { return isEncrypted; }
bool readOnly() const { return isReadOnly; }
bool getDirty() const;
QString currentFile() const { return curDBFilename; }
/// log an SQL statement [thread-safe]
void logSQL(QString statement, LogMessageType msgtype);
QString getPragma(const QString& pragma);
bool setPragma(const QString& pragma, const QString& value);
bool setPragma(const QString& pragma, const QString& value, QString& originalvalue);
bool setPragma(const QString& pragma, int value, int& originalvalue);
bool loadExtension(const QString& filename);
void loadExtensionsFromSettings();
static QStringList Datatypes;
private:
std::vector<std::pair<std::string, std::string> > queryColumnInformation(const std::string& schema_name, const std::string& object_name);
public:
QString generateSavepointName(const QString& identifier = QString()) const;
// This function generates the name for a temporary table. It guarantees that there is no table with this name yet
std::string generateTemporaryTableName(const std::string& schema) const;
schemaMap schemata;
signals:
void sqlExecuted(QString sql, int msgtype);
void dbChanged(bool dirty);
void structureUpdated();
void requestCollation(QString name, int eTextRep);
void databaseInUseChanged(bool busy, QString user);
private:
/// external code needs to go through get() to obtain access to the database
sqlite3 * _db;
std::mutex m;
std::condition_variable cv;
bool db_used;
QString db_user;
/// wait for release of the DB locked through a previous get(),
/// giving users the option to discard running task through a
/// message box.
void waitForDbRelease(ChoiceOnUse choice = Ask);
QString curDBFilename;
QString lastErrorMessage;
QStringList savepointList;
bool isEncrypted;
bool isReadOnly;
sqlb::StringVector primaryKeyForEditing(const sqlb::ObjectIdentifier& table, const sqlb::StringVector& pseudo_pk) const;
// SQLite Callbacks
void collationNeeded(void* pData, sqlite3* db, int eTextRep, const char* sCollationName);
void errorLogCallback(void* user_data, int error_code, const char* message);
bool tryEncryptionSettings(const QString& filename, bool* encrypted, CipherSettings*& cipherSettings);
bool dontCheckForStructureUpdates;
class NoStructureUpdateChecks
{
public:
explicit NoStructureUpdateChecks(DBBrowserDB& db) : m_db(db) { m_db.dontCheckForStructureUpdates = true; }
~NoStructureUpdateChecks() { m_db.dontCheckForStructureUpdates = false; }
private:
DBBrowserDB& m_db;
};
};
#endif
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Official home of the DB Browser for SQLite (DB4S) project. Previously known as "SQLite Database Browser" and "Database Browser for SQLite". Website at:
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/my_open_source_software/sqlitebrowser.git
git@gitee.com:my_open_source_software/sqlitebrowser.git
my_open_source_software
sqlitebrowser
sqlitebrowser
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /