mirror of
https://github.com/sqlitebrowser/sqlitebrowser.git
synced 2026-01-20 11:00:44 -06:00
Use same data type as SQLite for primary keys
This improves commit c20c58595a to
definitely make sure the primary key values are stored and handled
correctly by simply using the same data type as SQLite itself does.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include "sqlitedb.h"
|
||||
#include "sqlitetablemodel.h"
|
||||
#include "sqlite.h"
|
||||
#include "CipherDialog.h"
|
||||
|
||||
#include <QFile>
|
||||
@@ -578,7 +577,7 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBBrowserDB::getRow(const QString& sTableName, long rowid, QList<QByteArray>& rowdata)
|
||||
bool DBBrowserDB::getRow(const QString& sTableName, sqlite3_int64 rowid, QList<QByteArray>& rowdata)
|
||||
{
|
||||
QString sQuery = QString("SELECT * FROM `%1` WHERE `%2`=%3;").arg(sTableName).arg(getObjectByName(sTableName).table.rowidColumn()).arg(rowid);
|
||||
QByteArray utf8Query = sQuery.toUtf8();
|
||||
@@ -625,7 +624,7 @@ int64_t DBBrowserDB::max(const sqlb::Table& t, sqlb::FieldPtr field) const
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString DBBrowserDB::emptyInsertStmt(const sqlb::Table& t, long pk_value) const
|
||||
QString DBBrowserDB::emptyInsertStmt(const sqlb::Table& t, sqlite3_int64 pk_value) const
|
||||
{
|
||||
QString stmt = QString("INSERT INTO `%1`").arg(t.name());
|
||||
|
||||
@@ -727,7 +726,7 @@ long DBBrowserDB::addRecord(const QString& sTableName)
|
||||
}
|
||||
}
|
||||
|
||||
bool DBBrowserDB::deleteRecord(const QString& table, long rowid)
|
||||
bool DBBrowserDB::deleteRecord(const QString& table, sqlite3_int64 rowid)
|
||||
{
|
||||
char * errmsg;
|
||||
if (!isOpen()) return false;
|
||||
@@ -750,7 +749,7 @@ bool DBBrowserDB::deleteRecord(const QString& table, long rowid)
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool DBBrowserDB::updateRecord(const QString& table, const QString& column, long row, const QByteArray& value)
|
||||
bool DBBrowserDB::updateRecord(const QString& table, const QString& column, sqlite3_int64 row, const QByteArray& value)
|
||||
{
|
||||
if (!isOpen()) return false;
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
#define SQLITEDB_H
|
||||
|
||||
#include "sqlitetypes.h"
|
||||
#include "sqlite.h"
|
||||
|
||||
#include <QStringList>
|
||||
#include <QMultiMap>
|
||||
#include <QByteArray>
|
||||
|
||||
class CipherDialog;
|
||||
class sqlite3;
|
||||
|
||||
enum
|
||||
{
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
* @param rowdata A list of QByteArray containing the row data.
|
||||
* @return true if statement execution was ok, else false.
|
||||
*/
|
||||
bool getRow(const QString& sTableName, long rowid, QList<QByteArray>& rowdata);
|
||||
bool getRow(const QString& sTableName, sqlite3_int64 rowid, QList<QByteArray>& rowdata);
|
||||
|
||||
/**
|
||||
* @brief max Queries the table t for the max value of field.
|
||||
@@ -84,9 +84,9 @@ public:
|
||||
* @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 sqlb::Table& t, long pk_value = -1) const;
|
||||
bool deleteRecord(const QString& table, long rowid);
|
||||
bool updateRecord(const QString& table, const QString& column, long row, const QByteArray& value);
|
||||
QString emptyInsertStmt(const sqlb::Table& t, sqlite3_int64 pk_value = -1) const;
|
||||
bool deleteRecord(const QString& table, sqlite3_int64 rowid);
|
||||
bool updateRecord(const QString& table, const QString& column, sqlite3_int64 row, const QByteArray& value);
|
||||
|
||||
bool createTable(const QString& name, const sqlb::FieldVector& structure);
|
||||
bool renameTable(const QString& from_table, const QString& to_table);
|
||||
|
||||
@@ -256,7 +256,7 @@ bool SqliteTableModel::setData(const QModelIndex& index, const QVariant& value,
|
||||
if(m_data.at(index.row()).at(index.column()) == value)
|
||||
return true;
|
||||
|
||||
if(m_db->updateRecord(m_sTable, m_headers.at(index.column()), m_data[index.row()].at(0).toLong(), value.toByteArray()))
|
||||
if(m_db->updateRecord(m_sTable, m_headers.at(index.column()), m_data[index.row()].at(0).toLongLong(), value.toByteArray()))
|
||||
{
|
||||
// Only update the cache if this row has already been read, if not there's no need to do any changes to the cache
|
||||
if(index.row() < m_data.size())
|
||||
@@ -351,7 +351,7 @@ bool SqliteTableModel::removeRows(int row, int count, const QModelIndex& parent)
|
||||
|
||||
for(int i=count-1;i>=0;i--)
|
||||
{
|
||||
m_db->deleteRecord(m_sTable, m_data.at(row + i).at(0).toLong());
|
||||
m_db->deleteRecord(m_sTable, m_data.at(row + i).at(0).toLongLong());
|
||||
m_data.removeAt(row + i);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user