mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:35:08 +00:00
UI: SQLite: Use UTF8 only.
This commit is contained in:
parent
4c99c8c34e
commit
c9eba26915
6
src/ui/3rdparty/sqlite/sqlite.pri
vendored
6
src/ui/3rdparty/sqlite/sqlite.pri
vendored
@ -5,7 +5,10 @@ DEFINES += \
|
||||
SQLITE_DEFAULT_LOCKING_MODE=1 \
|
||||
SQLITE_DEFAULT_MEMSTATUS=0 \
|
||||
SQLITE_DEFAULT_WAL_SYNCHRONOUS=1 \
|
||||
SQLITE_DQS=0 \
|
||||
SQLITE_ENABLE_STAT4 \
|
||||
SQLITE_LIKE_DOESNT_MATCH_BLOBS \
|
||||
SQLITE_TEMP_STORE=2 \
|
||||
SQLITE_USE_ALLOCA \
|
||||
SQLITE_OMIT_AUTHORIZATION \
|
||||
SQLITE_OMIT_AUTOINIT \
|
||||
@ -26,7 +29,8 @@ DEFINES += \
|
||||
SQLITE_OMIT_SHARED_CACHE \
|
||||
SQLITE_OMIT_TCL_VARIABLE \
|
||||
SQLITE_OMIT_TEMPDB \
|
||||
SQLITE_OMIT_TRACE
|
||||
SQLITE_OMIT_TRACE \
|
||||
#SQLITE_OMIT_UTF16
|
||||
|
||||
SQLITE_DIR = $$PWD/../../../3rdparty/sqlite
|
||||
INCLUDEPATH += $$SQLITE_DIR
|
||||
|
19
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
19
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
@ -61,7 +61,9 @@ bool SqliteDb::open(const QString &filePath)
|
||||
m_filePath = filePath;
|
||||
}
|
||||
|
||||
return sqlite3_open16(m_filePath.utf16(), &m_db) == SQLITE_OK;
|
||||
const auto filePathUtf8 = m_filePath.toUtf8();
|
||||
|
||||
return sqlite3_open(filePathUtf8.data(), &m_db) == SQLITE_OK;
|
||||
}
|
||||
|
||||
void SqliteDb::close()
|
||||
@ -91,20 +93,11 @@ bool SqliteDb::execute(const char *sql)
|
||||
return sqlite3_exec(m_db, sql, nullptr, nullptr, nullptr) == SQLITE_OK;
|
||||
}
|
||||
|
||||
bool SqliteDb::execute16(const ushort *sql)
|
||||
{
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
int res = sqlite3_prepare16_v2(db(), sql, -1, &stmt, nullptr);
|
||||
if (stmt != nullptr) {
|
||||
res = sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool SqliteDb::executeStr(const QString &sql)
|
||||
{
|
||||
return execute16(sql.utf16());
|
||||
const auto sqlUtf8 = sql.toUtf8();
|
||||
|
||||
return execute(sqlUtf8.data());
|
||||
}
|
||||
|
||||
QVariant SqliteDb::executeEx(const char *sql,
|
||||
|
1
src/ui/3rdparty/sqlite/sqlitedb.h
vendored
1
src/ui/3rdparty/sqlite/sqlitedb.h
vendored
@ -32,7 +32,6 @@ public:
|
||||
bool detach(const QString &schemaName);
|
||||
|
||||
bool execute(const char *sql);
|
||||
bool execute16(const ushort *sql);
|
||||
bool executeStr(const QString &sql);
|
||||
|
||||
QVariant executeEx(const char *sql,
|
||||
|
21
src/ui/3rdparty/sqlite/sqlitestmt.cpp
vendored
21
src/ui/3rdparty/sqlite/sqlitestmt.cpp
vendored
@ -53,12 +53,13 @@ bool SqliteStmt::bindNull(int index)
|
||||
|
||||
bool SqliteStmt::bindText(int index, const QString &text)
|
||||
{
|
||||
const int bytesCount = text.size() * int(sizeof(wchar_t));
|
||||
const auto textUtf8 = text.toUtf8();
|
||||
const int bytesCount = textUtf8.size();
|
||||
|
||||
m_bindObjects.insert(index, text);
|
||||
m_bindObjects.insert(index, textUtf8);
|
||||
|
||||
return sqlite3_bind_text16(m_stmt, index, text.utf16(),
|
||||
bytesCount, SQLITE_STATIC) == SQLITE_OK;
|
||||
return sqlite3_bind_text(m_stmt, index, textUtf8.data(),
|
||||
bytesCount, SQLITE_STATIC) == SQLITE_OK;
|
||||
}
|
||||
|
||||
bool SqliteStmt::bindDateTime(int index, const QDateTime &dateTime)
|
||||
@ -188,8 +189,8 @@ int SqliteStmt::columnCount()
|
||||
|
||||
QString SqliteStmt::columnName(int column)
|
||||
{
|
||||
const auto name = sqlite3_column_name16(m_stmt, column);
|
||||
return QString::fromWCharArray((const wchar_t *) name);
|
||||
const char *name = sqlite3_column_name(m_stmt, column);
|
||||
return QString::fromUtf8(name);
|
||||
}
|
||||
|
||||
qint32 SqliteStmt::columnInt(int column)
|
||||
@ -214,16 +215,16 @@ bool SqliteStmt::columnBool(int column)
|
||||
|
||||
QString SqliteStmt::columnText(int column)
|
||||
{
|
||||
const ushort *p = static_cast<const ushort *>(
|
||||
sqlite3_column_text16(m_stmt, column));
|
||||
const char *p = reinterpret_cast<const char *>(
|
||||
sqlite3_column_text(m_stmt, column));
|
||||
if (p == nullptr || *p == '\0')
|
||||
return QString();
|
||||
|
||||
const int bytesCount = sqlite3_column_bytes16(m_stmt, column);
|
||||
const int bytesCount = sqlite3_column_bytes(m_stmt, column);
|
||||
if (bytesCount == 0)
|
||||
return QString();
|
||||
|
||||
return QString::fromUtf16(p, bytesCount / int(sizeof(wchar_t)));
|
||||
return QString::fromUtf8(p, bytesCount);
|
||||
}
|
||||
|
||||
QDateTime SqliteStmt::columnDateTime(int column)
|
||||
|
Loading…
Reference in New Issue
Block a user