📄 ndboperation.hpp
字号:
/* Copyright (C) 2003 MySQL AB This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef NdbOperation_H#define NdbOperation_H#include <ndb_types.h>#include "ndbapi_limits.h"#include "NdbError.hpp"#include "NdbReceiver.hpp"#include "NdbDictionary.hpp"#include "Ndb.hpp"class Ndb;class NdbApiSignal;class NdbRecAttr;class NdbOperation;class NdbTransaction;class NdbColumnImpl;class NdbBlob;/** * @class NdbOperation * @brief Class of operations for use in transactions. */class NdbOperation{#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL friend class Ndb; friend class NdbTransaction; friend class NdbScanOperation; friend class NdbScanReceiver; friend class NdbScanFilter; friend class NdbScanFilterImpl; friend class NdbReceiver; friend class NdbBlob;#endifpublic: /** * @name Define Standard Operation Type * @{ */ /** * Different access types (supported by sub-classes of NdbOperation) */ enum Type { PrimaryKeyAccess ///< Read, insert, update, or delete using pk#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL = 0 // NdbOperation#endif ,UniqueIndexAccess ///< Read, update, or delete using unique index#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL = 1 // NdbIndexOperation#endif ,TableScan ///< Full table scan#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL = 2 // NdbScanOperation#endif ,OrderedIndexScan ///< Ordered index scan#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL = 3 // NdbIndexScanOperation#endif }; /** * Lock when performing read */ enum LockMode { LM_Read ///< Read with shared lock#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL = 0#endif ,LM_Exclusive ///< Read with exclusive lock#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL = 1#endif ,LM_CommittedRead ///< Ignore locks, read last committed value#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL = 2, LM_Dirty = 2#endif }; /** * Define the NdbOperation to be a standard operation of type insertTuple. * When calling NdbTransaction::execute, this operation * adds a new tuple to the table. * * @return 0 if successful otherwise -1. */ virtual int insertTuple(); /** * Define the NdbOperation to be a standard operation of type updateTuple. * When calling NdbTransaction::execute, this operation * updates a tuple in the table. * * @return 0 if successful otherwise -1. */ virtual int updateTuple(); /** * Define the NdbOperation to be a standard operation of type writeTuple. * When calling NdbTransaction::execute, this operation * writes a tuple to the table. * If the tuple exists, it updates it, otherwise an insert takes place. * * @return 0 if successful otherwise -1. */ virtual int writeTuple(); /** * Define the NdbOperation to be a standard operation of type deleteTuple. * When calling NdbTransaction::execute, this operation * delete a tuple. * * @return 0 if successful otherwise -1. */ virtual int deleteTuple(); /** * Define the NdbOperation to be a standard operation of type readTuple. * When calling NdbTransaction::execute, this operation * reads a tuple. * * @return 0 if successful otherwise -1. */ virtual int readTuple(LockMode);#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED /** * Define the NdbOperation to be a standard operation of type readTuple. * When calling NdbTransaction::execute, this operation * reads a tuple. * * @return 0 if successful otherwise -1. */ virtual int readTuple(); /** * Define the NdbOperation to be a standard operation of type * readTupleExclusive. * When calling NdbTransaction::execute, this operation * read a tuple using an exclusive lock. * * @return 0 if successful otherwise -1. */ virtual int readTupleExclusive(); /** * Define the NdbOperation to be a standard operation of type * simpleRead. * When calling NdbTransaction::execute, this operation * reads an existing tuple (using shared read lock), * but releases lock immediately after read. * * @note Using this operation twice in the same transaction * may produce different results (e.g. if there is another * transaction which updates the value between the * simple reads). * * Note that simpleRead can read the value from any database node while * standard read always read the value on the database node which is * primary for the record. * * @return 0 if successful otherwise -1. */ virtual int simpleRead(); /** * Define the NdbOperation to be a standard operation of type committedRead. * When calling NdbTransaction::execute, this operation * read latest committed value of the record. * * This means that if another transaction is updating the * record, then the current transaction will not wait. * It will instead use the latest committed value of the * record. * dirtyRead is a deprecated name for committedRead * * @return 0 if successful otherwise -1. * @depricated */ virtual int dirtyRead(); /** * Define the NdbOperation to be a standard operation of type committedRead. * When calling NdbTransaction::execute, this operation * read latest committed value of the record. * * This means that if another transaction is updating the * record, then the current transaction will not wait. * It will instead use the latest committed value of the * record. * * @return 0 if successful otherwise -1. */ virtual int committedRead(); /** * Define the NdbOperation to be a standard operation of type dirtyUpdate. * When calling NdbTransaction::execute, this operation * updates without two-phase commit. * * @return 0 if successful otherwise -1. */ virtual int dirtyUpdate(); /** * Define the NdbOperation to be a standard operation of type dirtyWrite. * When calling NdbTransaction::execute, this operation * writes without two-phase commit. * * @return 0 if successful otherwise -1. */ virtual int dirtyWrite();#endif#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** @} *********************************************************************/ /** * @name Define Interpreted Program Operation Type * @{ */ /** * Update a tuple using an interpreted program. * * @return 0 if successful otherwise -1. */ virtual int interpretedUpdateTuple(); /** * Delete a tuple using an interpreted program. * * @return 0 if successful otherwise -1. */ virtual int interpretedDeleteTuple();#endif /** @} *********************************************************************/ /** * @name Specify Search Conditions * @{ */ /** * Define a search condition with equality. * The condition is true if the attribute has the given value. * To set search conditions on multiple attributes, * use several equals (then all of them must be satisfied for the * tuple to be selected). * * @note For insertTuple() it is also allowed to define the * search key by using setValue(). * * @note There are 10 versions of equal() with * slightly different parameters. * * @note When using equal() with a string (char *) as * second argument, the string needs to be padded with * zeros in the following sense: * @code * // Equal needs strings to be padded with zeros * strncpy(buf, str, sizeof(buf)); * NdbOperation->equal("Attr1", buf); * @endcode * * * * @param anAttrName Attribute name * @param aValue Attribute value. * @param len Attribute length expressed in bytes. * @return -1 if unsuccessful. */ int equal(const char* anAttrName, const char* aValue, Uint32 len = 0); int equal(const char* anAttrName, Uint32 aValue); int equal(const char* anAttrName, Int32 aValue); int equal(const char* anAttrName, Int64 aValue); int equal(const char* anAttrName, Uint64 aValue); int equal(Uint32 anAttrId, const char* aValue, Uint32 len = 0); int equal(Uint32 anAttrId, Int32 aValue); int equal(Uint32 anAttrId, Uint32 aValue); int equal(Uint32 anAttrId, Int64 aValue); int equal(Uint32 anAttrId, Uint64 aValue); /** @} *********************************************************************/ /** * @name Specify Attribute Actions for Operations * @{ */ /** * Defines a retrieval operation of an attribute value. * The NDB API allocate memory for the NdbRecAttr object that * will hold the returned attribute value. * * @note Note that it is the applications responsibility * to allocate enough memory for aValue (if non-NULL). * The buffer aValue supplied by the application must be * aligned appropriately. The buffer is used directly * (avoiding a copy penalty) only if it is aligned on a * 4-byte boundary and the attribute size in bytes * (i.e. NdbRecAttr::attrSize times NdbRecAttr::arraySize is * a multiple of 4). * * @note There are two versions of NdbOperation::getValue with * slightly different parameters. * * @note This method does not fetch the attribute value from * the database! The NdbRecAttr object returned by this method * is <em>not</em> readable/printable before the * transaction has been executed with NdbTransaction::execute. * * @param anAttrName Attribute name * @param aValue If this is non-NULL, then the attribute value * will be returned in this parameter.<br> * If NULL, then the attribute value will only * be stored in the returned NdbRecAttr object. * @return An NdbRecAttr object to hold the value of * the attribute, or a NULL pointer * (indicating error). */ NdbRecAttr* getValue(const char* anAttrName, char* aValue = 0); NdbRecAttr* getValue(Uint32 anAttrId, char* aValue = 0); NdbRecAttr* getValue(const NdbDictionary::Column*, char* val = 0); /** * Define an attribute to set or update in query. * * To set a NULL value, use the following construct: * @code * setValue("ATTR_NAME", (char*)NULL); * @endcode * * There are a number of NdbOperation::setValue methods that * take a certain type as input * (pass by value rather than passing a pointer). * As the interface is currently implemented it is the responsibility * of the application programmer to use the correct types. * * The NDB API will however check that the application sends * a correct length to the interface as given in the length parameter. * The passing of char* as the value can contain any type or * any type of array. * If length is not provided or set to zero, * then the API will assume that the pointer * is correct and not bother with checking it. * * @note For insertTuple() the NDB API will automatically detect that * it is supposed to use equal() instead. * * @note For insertTuple() it is not necessary to use * setValue() on key attributes before other attributes. * * @note There are 14 versions of NdbOperation::setValue with * slightly different parameters. * * @param anAttrName Name (or Id) of attribute. * @param aValue Attribute value to set. * @param len Attribute length expressed in bytes. * @return -1 if unsuccessful. */ virtual int setValue(const char* anAttrName, const char* aValue, Uint32 len = 0); virtual int setValue(const char* anAttrName, Int32 aValue); virtual int setValue(const char* anAttrName, Uint32 aValue); virtual int setValue(const char* anAttrName, Uint64 aValue); virtual int setValue(const char* anAttrName, Int64 aValue); virtual int setValue(const char* anAttrName, float aValue); virtual int setValue(const char* anAttrName, double aValue); virtual int setValue(Uint32 anAttrId, const char* aValue, Uint32 len = 0); virtual int setValue(Uint32 anAttrId, Int32 aValue); virtual int setValue(Uint32 anAttrId, Uint32 aValue); virtual int setValue(Uint32 anAttrId, Uint64 aValue); virtual int setValue(Uint32 anAttrId, Int64 aValue); virtual int setValue(Uint32 anAttrId, float aValue); virtual int setValue(Uint32 anAttrId, double aValue); /** * This method replaces getValue/setValue for blobs. It creates * a blob handle NdbBlob. A second call with same argument returns * the previously created handle. The handle is linked to the * operation and is maintained automatically. * * See NdbBlob for details. */ virtual NdbBlob* getBlobHandle(const char* anAttrName); virtual NdbBlob* getBlobHandle(Uint32 anAttrId); #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL /** @} *********************************************************************/ /** * @name Specify Interpreted Program Instructions * @{ */ /** * Interpreted program instruction: Add a value to an attribute. * * @note Destroys the contents of registers 6 and 7. * (The instruction uses these registers for its operation.) * * @note There are four versions of NdbOperation::incValue with * slightly different parameters. * * @param anAttrName Attribute name. * @param aValue Value to add. * @return -1 if unsuccessful.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -