SqliteConnection

Search for usage in LXR

#include <SqliteConnection.h>

Inheritance diagram for SqliteConnection:

Public Member Functions

KDbCursorprepareQuery (const KDbEscapedString &sql, KDbCursor::Options options=KDbCursor::Option::None) override
 
KDbCursorprepareQuery (KDbQuerySchema *query, KDbCursor::Options options=KDbCursor::Option::None) override
 
KDbPreparedStatementInterfaceprepareStatementInternal () override
 
- Public Member Functions inherited from KDbConnection
 ~KDbConnection () override
 
tristate alterTable (KDbTableSchema *tableSchema, KDbTableSchema *newTableSchema)
 
bool alterTableName (KDbTableSchema *tableSchema, const QString &newName, AlterTableNameOptions options=AlterTableNameOption::Default)
 
virtual QString anyAvailableDatabaseName ()
 
bool autoCommit () const
 
KDbTransaction beginTransaction ()
 
void clearResult ()
 
bool closeDatabase ()
 
bool commitTransaction (KDbTransaction transaction=KDbTransaction(), KDbTransaction::CommitOptions options=KDbTransaction::CommitOptions())
 
bool connect ()
 
tristate containsTable (const QString &tableName)
 
bool copyDataBlock (int sourceObjectID, int destObjectID, const QString &dataID=QString())
 
KDbTableSchemacopyTable (const KDbTableSchema &tableSchema, const KDbObject &newData)
 
KDbTableSchemacopyTable (const QString &tableName, const KDbObject &newData)
 
bool createDatabase (const QString &dbName)
 
bool createTable (KDbTableSchema *tableSchema, CreateTableOptions options=CreateTableOption::Default)
 
QString currentDatabase () const
 
KDbConnectionData data () const
 
bool databaseExists (const QString &dbName, bool ignoreErrors=true)
 
QStringList databaseNames (bool also_system_db=false)
 
KDbProperties databaseProperties () const
 
KDbVersionInfo databaseVersion () const
 
KDbTransaction defaultTransaction () const
 
bool deleteCursor (KDbCursor *cursor)
 
bool disconnect ()
 
KDbDriverdriver () const
 
bool dropDatabase (const QString &dbName=QString())
 
bool dropQuery (const QString &queryName)
 
bool dropQuery (KDbQuerySchema *querySchema)
 
tristate dropTable (const QString &tableName)
 
tristate dropTable (KDbTableSchema *tableSchema)
 
virtual QString escapeIdentifier (const QString &id) const
 
virtual KDbEscapedString escapeString (const QString &str) const
 
KDbCursorexecuteQuery (const KDbEscapedString &sql, KDbCursor::Options options=KDbCursor::Option::None)
 
KDbCursorexecuteQuery (KDbQuerySchema *query, const QList< QVariant > &params, KDbCursor::Options options=KDbCursor::Option::None)
 
KDbCursorexecuteQuery (KDbQuerySchema *query, KDbCursor::Options options=KDbCursor::Option::None)
 
KDbCursorexecuteQuery (KDbTableSchema *table, KDbCursor::Options options=KDbCursor::Option::None)
 
bool executeSql (const KDbEscapedString &sql)
 
KDbFieldfindSystemFieldName (const KDbFieldList &fieldlist)
 
QSharedPointer< KDbSqlResultinsertRecord (KDbFieldList *fields, const QList< QVariant > &values)
 
QSharedPointer< KDbSqlResultinsertRecord (KDbTableSchema *tableSchema, const QList< QVariant > &values)
 
bool isConnected () const
 
bool isDatabaseUsed () const
 
tristate isEmpty (KDbTableSchema *table)
 
bool isInternalTableSchema (const QString &tableName)
 
tristate loadDataBlock (int objectID, QString *dataString, const QString &dataID=QString())
 
tristate loadObjectData (int type, const QString &name, KDbObject *object)
 
tristate loadObjectData (int type, int id, KDbObject *object)
 
QList< int > objectIds (int objectType, bool *ok=nullptr)
 
QStringList objectNames (int objectType=KDb::AnyObjectType, bool *ok=nullptr)
 
KDbConnectionOptionsoptions ()
 
KDbCursorprepareQuery (KDbQuerySchema *query, const QList< QVariant > &params, KDbCursor::Options options=KDbCursor::Option::None)
 
KDbCursorprepareQuery (KDbTableSchema *table, KDbCursor::Options options=KDbCursor::Option::None)
 
QSharedPointer< KDbSqlResultprepareSql (const KDbEscapedString &sql)
 
KDbPreparedStatement prepareStatement (KDbPreparedStatement::Type type, KDbFieldList *fields, const QStringList &whereFieldNames=QStringList())
 
QList< int > queryIds (bool *ok=nullptr)
 
KDbQuerySchemaquerySchema (const QString &queryName)
 
KDbQuerySchemaquerySchema (int queryId)
 
tristate querySingleNumber (const KDbEscapedString &sql, int *number, int column=0, QueryRecordOptions options=QueryRecordOption::Default)
 
tristate querySingleNumber (KDbQuerySchema *query, int *number, const QList< QVariant > &params, int column=0, QueryRecordOptions options=QueryRecordOption::Default)
 
tristate querySingleNumber (KDbQuerySchema *query, int *number, int column=0, QueryRecordOptions options=QueryRecordOption::Default)
 
tristate querySingleRecord (const KDbEscapedString &sql, KDbRecordData *data, QueryRecordOptions options=QueryRecordOption::Default)
 
tristate querySingleRecord (KDbQuerySchema *query, KDbRecordData *data, const QList< QVariant > &params, QueryRecordOptions options=QueryRecordOption::Default)
 
tristate querySingleRecord (KDbQuerySchema *query, KDbRecordData *data, QueryRecordOptions options=QueryRecordOption::Default)
 
tristate querySingleString (const KDbEscapedString &sql, QString *value, int column=0, QueryRecordOptions options=QueryRecordOption::Default)
 
tristate querySingleString (KDbQuerySchema *query, QString *value, const QList< QVariant > &params, int column=0, QueryRecordOptions options=QueryRecordOption::Default)
 
tristate querySingleString (KDbQuerySchema *query, QString *value, int column=0, QueryRecordOptions options=QueryRecordOption::Default)
 
bool queryStringList (const KDbEscapedString &sql, QStringList *list, int column=0)
 
bool queryStringList (KDbQuerySchema *query, QStringList *list, const QList< QVariant > &params, int column=0)
 
bool queryStringList (KDbQuerySchema *query, QStringList *list, int column=0)
 
virtual KDbEscapedString recentSqlString () const
 
int recordCount (const KDbEscapedString &sql)
 
int recordCount (const KDbTableSchema &tableSchema)
 
int recordCount (KDbQuerySchema *querySchema, const QList< QVariant > &params=QList< QVariant >())
 
int recordCount (KDbTableOrQuerySchema *tableOrQuery, const QList< QVariant > &params=QList< QVariant >())
 
bool removeDataBlock (int objectID, const QString &dataID=QString())
 
bool removeObject (int objId)
 
tristate resultExists (const KDbEscapedString &sql, QueryRecordOptions options=QueryRecordOption::Default)
 
bool rollbackTransaction (KDbTransaction trans=KDbTransaction(), KDbTransaction::CommitOptions options=KDbTransaction::CommitOptions())
 
KDbServerVersionInfo serverVersion () const
 
bool setAutoCommit (bool on)
 
void setAvailableDatabaseName (const QString &dbName)
 
void setDefaultTransaction (const KDbTransaction &trans)
 
bool setQuerySchemaObsolete (const QString &queryName)
 
bool storeDataBlock (int objectID, const QString &dataString, const QString &dataID=QString())
 
bool storeNewObjectData (KDbObject *object)
 
bool storeObjectData (KDbObject *object)
 
QList< int > tableIds (bool *ok=nullptr)
 
QStringList tableNames (bool alsoSystemTables=false, bool *ok=nullptr)
 
KDbTableSchematableSchema (const QString &tableName)
 
KDbTableSchematableSchema (int tableId)
 
QList< KDbTransactiontransactions ()
 
bool useDatabase (const QString &dbName=QString(), bool kexiCompatible=true, bool *cancelled=nullptr, KDbMessageHandler *msgHandler=nullptr)
 
bool useTemporaryDatabaseIfNeeded (QString *name)
 
- Public Member Functions inherited from KDbResultable
 KDbResultable (const KDbResultable &other)
 
void clearResult ()
 
KDbMessageHandlermessageHandler () const
 
KDbResultableoperator= (const KDbResultable &other)
 
KDbResult result () const
 
void setMessageHandler (KDbMessageHandler *handler)
 
void showMessage ()
 

Protected Member Functions

 SqliteConnection (KDbDriver *driver, const KDbConnectionData &connData, const KDbConnectionOptions &options)
 
tristate changeFieldType (KDbTableSchema *table, KDbField *field, KDbField::Type type)
 
tristate drv_changeFieldProperty (KDbTableSchema *table, KDbField *field, const QString &propertyName, const QVariant &value) override
 
bool drv_closeDatabase () override
 
bool drv_connect () override
 
tristate drv_containsTable (const QString &tableName) override
 
bool drv_createDatabase (const QString &dbName=QString()) override
 
bool drv_disconnect () override
 
bool drv_dropDatabase (const QString &dbName=QString()) override
 
bool drv_executeSql (const KDbEscapedString &sql) override
 
bool drv_getDatabasesList (QStringList *list) override
 
bool drv_getServerVersion (KDbServerVersionInfo *version) override
 
KDbSqlResultdrv_prepareSql (const KDbEscapedString &sql) override
 
bool drv_useDatabase (const QString &dbName=QString(), bool *cancelled=nullptr, KDbMessageHandler *msgHandler=nullptr) override
 
QString serverResultName () const override
 
void storeResult ()
 
- Protected Member Functions inherited from KDbConnection
 KDbConnection (KDbDriver *driver, const KDbConnectionData &connData, const KDbConnectionOptions &options)
 
void addCursor (KDbCursor *cursor)
 
bool beginAutoCommitTransaction (KDbTransactionGuard *tg)
 
bool checkConnected ()
 
bool checkIfColumnExists (KDbCursor *cursor, int column)
 
bool checkIsDatabaseUsed ()
 
bool commitAutoCommitTransaction (const KDbTransaction &trans)
 
bool deleteAllRecords (KDbQuerySchema *query)
 
bool deleteRecord (KDbQuerySchema *query, KDbRecordData *data, bool useRecordId=false)
 
void destroy ()
 
tristate dropTableInternal (KDbTableSchema *tableSchema, bool alsoRemoveSchema)
 
virtual bool drv_afterInsert (const QString &tableName, KDbFieldList *fields)
 
virtual bool drv_afterUpdate (const QString &tableName, KDbFieldList *fields)
 
virtual bool drv_alterTableName (KDbTableSchema *tableSchema, const QString &newName)
 
virtual bool drv_beforeInsert (const QString &tableName, KDbFieldList *fields)
 
virtual bool drv_beforeUpdate (const QString &tableName, KDbFieldList *fields)
 
virtual KDbTransactionDatadrv_beginTransaction ()
 
virtual bool drv_commitTransaction (KDbTransactionData *trans)
 
virtual bool drv_copyTableData (const KDbTableSchema &tableSchema, const KDbTableSchema &destinationTableSchema)
 
virtual bool drv_createTable (const KDbTableSchema &tableSchema)
 
virtual bool drv_createTable (const QString &tableName)
 
virtual bool drv_databaseExists (const QString &dbName, bool ignoreErrors=true)
 
virtual bool drv_dropTable (const QString &tableName)
 
virtual QStringList drv_getTableNames (bool *ok)
 
virtual bool drv_isDatabaseUsed () const
 
virtual bool drv_rollbackTransaction (KDbTransactionData *trans)
 
virtual bool drv_setAutoCommit (bool on)
 
KDbCursorexecuteQueryInternal (const KDbEscapedString &sql, KDbQuerySchema *query, const QList< QVariant > *params)
 
bool insertRecord (KDbQuerySchema *query, KDbRecordData *data, KDbRecordEditBuffer *buf, bool getRecordId=false)
 
QSharedPointer< KDbSqlResultinsertRecordInternal (const QString &tableSchemaName, KDbFieldList *fields, const KDbEscapedString &sql)
 
bool loadExtendedTableSchemaData (KDbTableSchema *tableSchema)
 
tristate querySingleNumberInternal (const KDbEscapedString *sql, int *number, KDbQuerySchema *query, const QList< QVariant > *params, int column, QueryRecordOptions options)
 
tristate querySingleRecordInternal (KDbRecordData *data, const KDbEscapedString *sql, KDbQuerySchema *query, const QList< QVariant > *params, QueryRecordOptions options)
 
tristate querySingleStringInternal (const KDbEscapedString *sql, QString *value, KDbQuerySchema *query, const QList< QVariant > *params, int column, QueryRecordOptions options)
 
bool queryStringListInternal (const KDbEscapedString *sql, QStringList *list, KDbQuerySchema *query, const QList< QVariant > *params, int column, bool(*filterFunction)(const QString &))
 
void removeMe (KDbTableSchema *ts)
 
bool rollbackAutoCommitTransaction (const KDbTransaction &trans)
 
KDbFieldsetupField (const KDbRecordData &data)
 
bool setupObjectData (const KDbRecordData &data, KDbObject *object)
 
bool storeExtendedTableSchemaData (KDbTableSchema *tableSchema)
 
bool storeMainFieldSchema (KDbField *field)
 
void takeCursor (KDbCursor *cursor)
 
bool updateRecord (KDbQuerySchema *query, KDbRecordData *data, KDbRecordEditBuffer *buf, bool useRecordId=false)
 

Protected Attributes

SqliteConnectionInternal * d
 
- Protected Attributes inherited from KDbResultable
Private *const d
 
KDbResult m_result
 

Additional Inherited Members

- Public Types inherited from KDbConnection
enum class  AlterTableNameOption { Default = 0 , DropDestination = 1 }
 
typedef QFlags< AlterTableNameOptionAlterTableNameOptions
 
enum class  CreateTableOption { Default = 0 , DropDestination = 1 }
 
typedef QFlags< CreateTableOptionCreateTableOptions
 
enum class  QueryRecordOption { AddLimitTo1 = 1 , Default = AddLimitTo1 }
 
typedef QFlags< QueryRecordOptionQueryRecordOptions
 
- Static Public Member Functions inherited from KDbConnection
static QStringList kdbSystemTableNames ()
 
- Public Attributes inherited from KDbConnection
 H_INS_REC_ALL
 

Detailed Description

SQLite-specific connection Following connection options are supported (see KDbConnectionOptions):

Definition at line 36 of file SqliteConnection.h.

Constructor & Destructor Documentation

◆ ~SqliteConnection()

SqliteConnection::~SqliteConnection ( )
override

Definition at line 52 of file SqliteConnection.cpp.

◆ SqliteConnection()

SqliteConnection::SqliteConnection ( KDbDriver * driver,
const KDbConnectionData & connData,
const KDbConnectionOptions & options )
protected

Used by driver

Definition at line 39 of file SqliteConnection.cpp.

Member Function Documentation

◆ changeFieldType()

tristate SqliteConnection::changeFieldType ( KDbTableSchema * table,
KDbField * field,
KDbField::Type type )
protected

for drv_changeFieldProperty()

From https://sqlite.org/datatype3.html : Version 3 enhances provides the ability to store integer and real numbers in a more compact format and the capability to store BLOB data.

Each value stored in an SQLite database (or manipulated by the database engine) has one of the following storage classes: NULL. The value is a NULL value. INTEGER. The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value. REAL. The value is a floating point value, stored as an 8-byte IEEE floating point number. TEXT. The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16-LE). BLOB. The value is a blob of data, stored exactly as it was input.

Column Affinity In SQLite version 3, the type of a value is associated with the value itself, not with the column or variable in which the value is stored. .The type affinity of a column is the recommended type for data stored in that column.

See alter_table_type_conversions.ods for details.

Definition at line 98 of file SqliteAlter.cpp.

◆ drv_changeFieldProperty()

tristate SqliteConnection::drv_changeFieldProperty ( KDbTableSchema * table,
KDbField * field,
const QString & propertyName,
const QVariant & value )
overrideprotectedvirtual

This is a part of alter table interface implementing lower-level operations used to perform table schema altering. Used by KDbAlterTableHandler.

Changes value of field property.

Returns
true on success, false on failure, cancelled if the action has been cancelled.

Note for driver developers: implement this if the driver has to supprot the altering.

Todo
msg

Reimplemented from KDbConnection.

Definition at line 61 of file SqliteAlter.cpp.

◆ drv_closeDatabase()

bool SqliteConnection::drv_closeDatabase ( )
overrideprotectedvirtual

For implementation: closes previously opened database using connection.

Implements KDbConnection.

Definition at line 247 of file SqliteConnection.cpp.

◆ drv_connect()

bool SqliteConnection::drv_connect ( )
overrideprotectedvirtual

For implementation: connects to database.

Returns
true on success.

Implements KDbConnection.

Definition at line 63 of file SqliteConnection.cpp.

◆ drv_containsTable()

tristate SqliteConnection::drv_containsTable ( const QString & tableName)
overrideprotectedvirtual
Todo
move this somewhere to low level class (MIGRATION?)

Implements KDbConnection.

Definition at line 93 of file SqliteConnection.cpp.

◆ drv_createDatabase()

bool SqliteConnection::drv_createDatabase ( const QString & dbName = QString())
overrideprotectedvirtual

Creates new database using connection. Note: Do not pass dbName arg because for file-based engine (that has one database per connection) it is defined during connection.

Implements KDbConnection.

Definition at line 121 of file SqliteConnection.cpp.

◆ drv_disconnect()

bool SqliteConnection::drv_disconnect ( )
overrideprotectedvirtual

For implementation: disconnects database

Returns
true on success.

Implements KDbConnection.

Definition at line 81 of file SqliteConnection.cpp.

◆ drv_dropDatabase()

bool SqliteConnection::drv_dropDatabase ( const QString & dbName = QString())
overrideprotectedvirtual

Drops database from the server using connection. After drop, database shouldn't be accessible anymore, so database file is just removed. See note from drv_useDatabase().

Implements KDbConnection.

Definition at line 267 of file SqliteConnection.cpp.

◆ drv_executeSql()

bool SqliteConnection::drv_executeSql ( const KDbEscapedString & sql)
overrideprotectedvirtual

Executes query for a raw SQL statement sql without returning resulting records.

It is useful mostly for INSERT queries but it is possible to execute SELECT queries when returned records can be ignored. The @sql should be is valid and properly escaped.

Note
Only use this method if you really need.
See also
executeSql

Implements KDbConnection.

Definition at line 321 of file SqliteConnection.cpp.

◆ drv_getDatabasesList()

bool SqliteConnection::drv_getDatabasesList ( QStringList * list)
overrideprotectedvirtual

For reimplementation: loads list of databases' names available for this connection and adds these names to list. If your server is not able to offer such a list, consider reimplementing drv_databaseExists() instead. The method should return true only if there was no error on getting database names list from the server. Default implementation puts empty list into list and returns true.

See also
databaseNames

Reimplemented from KDbConnection.

Definition at line 86 of file SqliteConnection.cpp.

◆ drv_getServerVersion()

bool SqliteConnection::drv_getServerVersion ( KDbServerVersionInfo * version)
overrideprotectedvirtual

For implementation: Sets version to real server's version. Depending on backend type this method is called after (if KDbDriverBehavior::USING_DATABASE_REQUIRED_TO_CONNECT is true) or before database is used (if KDbDriverBehavior::USING_DATABASE_REQUIRED_TO_CONNECT is false), i.e. for PostgreSQL it is called after. In any case it is called after successful drv_connect().

Returns
true on success.

Implements KDbConnection.

Definition at line 68 of file SqliteConnection.cpp.

◆ drv_prepareSql()

KDbSqlResult * SqliteConnection::drv_prepareSql ( const KDbEscapedString & sql)
overrideprotectedvirtual

Prepares query for a raw SQL statement sql with possibility of returning records.

It is useful mostly for SELECT queries. While INSERT queries do not return records, the KDbSqlResult object offers KDbSqlResult::lastInsertRecordId(). The @sql should be is valid and properly escaped. Only use this method if you really need. For low-level access to the results (without cursors). The result may be not stored (not buffered) yet. Use KDbSqlResult::fetchRecord() to fetch each record.

Returns
Null pointer if there is no proper result or error. Ownership of the returned object is passed to the caller.
See also
prepareSql

Implements KDbConnection.

Definition at line 292 of file SqliteConnection.cpp.

◆ drv_useDatabase()

bool SqliteConnection::drv_useDatabase ( const QString & dbName = QString(),
bool * cancelled = nullptr,
KDbMessageHandler * msgHandler = nullptr )
overrideprotectedvirtual

Opens existing database using connection. Do not pass dbName arg because for file-based engine (that has one database per connection) it is defined during connection. If you pass it, database file name will be changed.

Implements KDbConnection.

Definition at line 127 of file SqliteConnection.cpp.

◆ prepareQuery() [1/2]

KDbCursor * SqliteConnection::prepareQuery ( const KDbEscapedString & sql,
KDbCursor::Options options = KDbCursor::Option::None )
overridevirtual

Prepares SELECT query described by a raw statement sql.

Returns
opened cursor created for results of this query or nullptr if there was any error. Ownership of the returned object is passed to the caller. KDbCursor can have optionally applied options (one of more selected from KDbCursor::Options). Preparation means that returned cursor is created but not opened. Open this when you would like to do it with KDbCursor::open().

Note for driver developers: you should initialize cursor engine-specific resources and return KDbCursor subclass' object (passing sql and options to its constructor).

Implements KDbConnection.

Definition at line 282 of file SqliteConnection.cpp.

◆ prepareQuery() [2/2]

KDbCursor * SqliteConnection::prepareQuery ( KDbQuerySchema * query,
KDbCursor::Options options = KDbCursor::Option::None )
overridevirtual

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Prepares query described by query schema without parameters.

Implements KDbConnection.

Definition at line 287 of file SqliteConnection.cpp.

◆ prepareStatementInternal()

KDbPreparedStatementInterface * SqliteConnection::prepareStatementInternal ( )
overridevirtual

Prepare an SQL statement and return a KDbPreparedStatementInterface-derived object. Ownership of the returned object is passed to the caller.

Implements KDbConnection.

Definition at line 356 of file SqliteConnection.cpp.

◆ serverResultName()

QString SqliteConnection::serverResultName ( ) const
overrideprotectedvirtual

Implemented for KDbResultable.

Reimplemented from KDbResultable.

Definition at line 351 of file SqliteConnection.cpp.

◆ storeResult()

void SqliteConnection::storeResult ( )
protected

Definition at line 58 of file SqliteConnection.cpp.

Member Data Documentation

◆ d

SqliteConnectionInternal* SqliteConnection::d
protected

Definition at line 103 of file SqliteConnection.h.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.