Changeset View
Changeset View
Standalone View
Standalone View
src/KDbCursor.h
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | 35 | /*! | |||
---|---|---|---|---|---|
64 | - Do not use delete operator for KDbCursor objects - this will fail; use KDbConnection::deleteCursor() | 64 | - Do not use delete operator for KDbCursor objects - this will fail; use KDbConnection::deleteCursor() | ||
65 | instead. | 65 | instead. | ||
66 | - KDbQuerySchema object is not owned by KDbCursor object that uses it. | 66 | - KDbQuerySchema object is not owned by KDbCursor object that uses it. | ||
67 | */ | 67 | */ | ||
68 | class KDB_EXPORT KDbCursor: public KDbResultable | 68 | class KDB_EXPORT KDbCursor: public KDbResultable | ||
69 | { | 69 | { | ||
70 | Q_DECLARE_TR_FUNCTIONS(KDbCursor) | 70 | Q_DECLARE_TR_FUNCTIONS(KDbCursor) | ||
71 | public: | 71 | public: | ||
72 | //! KDbCursor options that describes its behavior | 72 | //! Options that describe behavior of database cursor | ||
73 | enum Options { | 73 | enum class Option { | ||
74 | NoOptions = 0, | 74 | None = 0, | ||
75 | Buffered = 1 | 75 | Buffered = 1 | ||
76 | }; | 76 | }; | ||
77 | Q_DECLARE_FLAGS(Options, Option) | ||||
77 | 78 | | |||
78 | /*! @return connection used for the cursor */ | 79 | /*! @return connection used for the cursor */ | ||
79 | KDbConnection* connection() const; | 80 | KDbConnection* connection() const; | ||
80 | 81 | | |||
81 | /*! Opens the cursor using data provided on creation. | 82 | /*! Opens the cursor using data provided on creation. | ||
82 | The data might be either KDbQuerySchema or a raw SQL statement. */ | 83 | The data might be either KDbQuerySchema or a raw SQL statement. */ | ||
83 | bool open(); | 84 | bool open(); | ||
84 | 85 | | |||
Show All 15 Lines | |||||
100 | 101 | | |||
101 | //! Sets query parameters @a params for this cursor. | 102 | //! Sets query parameters @a params for this cursor. | ||
102 | void setQueryParameters(const QList<QVariant>& params); | 103 | void setQueryParameters(const QList<QVariant>& params); | ||
103 | 104 | | |||
104 | /*! @return raw query statement used to define this cursor | 105 | /*! @return raw query statement used to define this cursor | ||
105 | or null string if raw statement instead (but KDbQuerySchema is defined instead). */ | 106 | or null string if raw statement instead (but KDbQuerySchema is defined instead). */ | ||
106 | KDbEscapedString rawSql() const; | 107 | KDbEscapedString rawSql() const; | ||
107 | 108 | | |||
108 | /*! @return logically or'd cursor's options, | 109 | /*! @return cursor options */ | ||
109 | selected from KDbCursor::Options enum. */ | 110 | Options options() const; | ||
110 | int options() const; | | |||
111 | 111 | | |||
112 | /*! @return true if the cursor is opened. */ | 112 | /*! @return true if the cursor is opened. */ | ||
113 | bool isOpened() const; | 113 | bool isOpened() const; | ||
114 | 114 | | |||
115 | /*! @return true if the cursor is buffered. */ | 115 | /*! @return true if the cursor is buffered. */ | ||
116 | bool isBuffered() const; | 116 | bool isBuffered() const; | ||
117 | 117 | | |||
118 | /*! Sets this cursor to buffered type or not. See description | 118 | /*! Sets this cursor to buffered type or not. See description | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | |||||
225 | bool insertRecord(KDbRecordData* data, KDbRecordEditBuffer* buf, bool getRecrordId = false); | 225 | bool insertRecord(KDbRecordData* data, KDbRecordEditBuffer* buf, bool getRecrordId = false); | ||
226 | 226 | | |||
227 | bool deleteRecord(KDbRecordData* data, bool useRecordId = false); | 227 | bool deleteRecord(KDbRecordData* data, bool useRecordId = false); | ||
228 | 228 | | |||
229 | bool deleteAllRecords(); | 229 | bool deleteAllRecords(); | ||
230 | 230 | | |||
231 | protected: | 231 | protected: | ||
232 | /*! Cursor will operate on @a conn, raw SQL statement @a sql will be used to execute query. */ | 232 | /*! Cursor will operate on @a conn, raw SQL statement @a sql will be used to execute query. */ | ||
233 | KDbCursor(KDbConnection* conn, const KDbEscapedString& sql, int options = NoOptions); | 233 | KDbCursor(KDbConnection* conn, const KDbEscapedString& sql, Options options = KDbCursor::Option::None); | ||
234 | 234 | | |||
235 | /*! Cursor will operate on @a conn, @a query schema will be used to execute query. */ | 235 | /*! Cursor will operate on @a conn, @a query schema will be used to execute query. */ | ||
236 | KDbCursor(KDbConnection* conn, KDbQuerySchema* query, int options = NoOptions); | 236 | KDbCursor(KDbConnection* conn, KDbQuerySchema* query, Options options = KDbCursor::Option::None); | ||
237 | 237 | | |||
238 | virtual ~KDbCursor(); | 238 | virtual ~KDbCursor(); | ||
239 | 239 | | |||
240 | void init(KDbConnection* conn); | 240 | void init(KDbConnection* conn); | ||
241 | 241 | | |||
242 | /*! Internal: cares about proper flag setting depending on result of drv_getNextRecord() | 242 | /*! Internal: cares about proper flag setting depending on result of drv_getNextRecord() | ||
243 | and depending on wherher a cursor is buffered. */ | 243 | and depending on wherher a cursor is buffered. */ | ||
244 | bool getNextRecord(); | 244 | bool getNextRecord(); | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | |||||
293 | KDbQuerySchema *m_query; | 293 | KDbQuerySchema *m_query; | ||
294 | bool m_afterLast; | 294 | bool m_afterLast; | ||
295 | qint64 m_at; | 295 | qint64 m_at; | ||
296 | int m_fieldCount; //!< cached field count information | 296 | int m_fieldCount; //!< cached field count information | ||
297 | int m_fieldsToStoreInRecord; //!< Used by storeCurrentRecord(), reimplement if needed | 297 | int m_fieldsToStoreInRecord; //!< Used by storeCurrentRecord(), reimplement if needed | ||
298 | //!< (e.g. PostgreSQL driver, when m_containsRecordIdInfo is true | 298 | //!< (e.g. PostgreSQL driver, when m_containsRecordIdInfo is true | ||
299 | //!< sets m_fieldCount+1 here) | 299 | //!< sets m_fieldCount+1 here) | ||
300 | int m_logicalFieldCount; //!< logical field count, i.e. without intrernal values like Record Id or lookup | 300 | int m_logicalFieldCount; //!< logical field count, i.e. without intrernal values like Record Id or lookup | ||
301 | int m_options; //!< cursor options that describes its behavior | 301 | KDbCursor::Options m_options; //!< cursor options that describes its behavior | ||
302 | 302 | | |||
303 | //! possible results of record fetching, used for m_fetchResult | 303 | //! possible results of record fetching, used for m_fetchResult | ||
304 | enum FetchResult { | 304 | enum FetchResult { | ||
305 | FetchInvalid, //!< used before starting the fetching, result is not known yet | 305 | FetchInvalid, //!< used before starting the fetching, result is not known yet | ||
306 | FetchError, //!< error of fetching | 306 | FetchError, //!< error of fetching | ||
307 | FetchOK, //!< the data is fetched | 307 | FetchOK, //!< the data is fetched | ||
308 | FetchEnd //!< at the end of data | 308 | FetchEnd //!< at the end of data | ||
309 | }; | 309 | }; | ||
Show All 15 Lines | 321 | private: | |||
325 | friend class CursorDeleter; | 325 | friend class CursorDeleter; | ||
326 | class Private; | 326 | class Private; | ||
327 | Private * const d; | 327 | Private * const d; | ||
328 | }; | 328 | }; | ||
329 | 329 | | |||
330 | //! Sends information about object @a cursor to debug output @a dbg. | 330 | //! Sends information about object @a cursor to debug output @a dbg. | ||
331 | KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbCursor& cursor); | 331 | KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbCursor& cursor); | ||
332 | 332 | | |||
333 | Q_DECLARE_OPERATORS_FOR_FLAGS(KDbCursor::Options) | ||||
334 | | ||||
333 | #endif | 335 | #endif |