api | api | |||
---|---|---|---|---|
skipping to change at line 49 | skipping to change at line 49 | |||
namespace OpenDBX | namespace OpenDBX | |||
{ | { | |||
using std::string; | using std::string; | |||
class Lob; | class Lob; | |||
class Result; | class Result; | |||
class Stmt; | class Stmt; | |||
class Conn; | class Conn; | |||
/** | /** | |||
* Exception thrown by OpenDBX objects | * Exception thrown by OpenDBX objects. | |||
*/ | */ | |||
class Exception : public std::runtime_error | class Exception : public std::runtime_error | |||
{ | { | |||
protected: | protected: | |||
/** | /** | |||
* Error code (negative) | * Error code (negative). | |||
*/ | */ | |||
int m_error; | int m_error; | |||
/** | /** | |||
* Severity of error (negative: fatal, zero: success, positi ve: warning) | * Severity of error (negative: fatal, zero: success, positi ve: warning) | |||
*/ | */ | |||
int m_type; | int m_type; | |||
public: | public: | |||
/** | /** | |||
* Initializes exception object | * Initializes exception object. | |||
* | * | |||
* @param string Error message | * @param msg Error message | |||
* @param int Severity of error (negative: fatal, zero: succ | * @param err OpenDBX error code | |||
ess, positive: warning) | * @param type Severity of error (negative: fatal, zero: suc | |||
cess, positive: warning) | ||||
* @return Exception | * @return Exception | |||
*/ | */ | |||
Exception( string msg, int err, int type ); | Exception( string msg, int err, int type ); | |||
/** | /** | |||
* Returns code related to the error | * Returns the OpenDBX error code related to the error. | |||
* | * | |||
* @return Error code | * @return Error code | |||
*/ | */ | |||
int getCode(); | int getCode(); | |||
/** | /** | |||
* Returns severity indicator | * Returns severity indicator. | |||
* | * | |||
* @return Severity of error (negative: fatal, zero: success , positive: warning) | * @return Severity of error (negative: fatal, zero: success , positive: warning) | |||
*/ | */ | |||
int getType(); | int getType(); | |||
}; | }; | |||
/** | /** | |||
* Handling large objects if supported by the database | * Handling large objects if supported by the database. | |||
*/ | */ | |||
class Lob | class Lob | |||
{ | { | |||
protected: | protected: | |||
/** | /** | |||
* Private implementation of object | * Private implementation of object. | |||
*/ | */ | |||
Lob_Impl* m_impl; | Lob_Impl* m_impl; | |||
/** | /** | |||
* Reference counter of copies | * Reference counter of copies. | |||
*/ | */ | |||
int* m_ref; | int* m_ref; | |||
/** | /** | |||
* Default constructor | * Default constructor. | |||
* | * | |||
* @return Lob instance | * @return Lob instance | |||
*/ | */ | |||
Lob(); | Lob(); | |||
/** | /** | |||
* Create large object instance | * Create large object instance. | |||
* | * | |||
* @param Lob_Impl* Pointer to private implementation | * @param impl Pointer to private implementation | |||
* @return Lob instance | * @return Lob instance | |||
*/ | */ | |||
Lob( Lob_Impl* impl ); | Lob( Lob_Impl* impl ); | |||
friend class Result; | friend class Result; | |||
public: | public: | |||
/** | /** | |||
* Destroy large object instance if no other references exis t | * Destroy large object instance if no other references exis t. | |||
*/ | */ | |||
~Lob(); | ~Lob(); | |||
/** | /** | |||
* Assign large object instance to another one | * Assign large object instance to another one. | |||
* | * | |||
* @param const Lob& Large object instance | * @param ref Large object instance | |||
* @return Large object reference of this instance | * @return Large object reference of this instance | |||
*/ | */ | |||
Lob& operator=( const Lob& ref ); | Lob& operator=( const Lob& ref ); | |||
/** | /** | |||
* Close Lob and commit changes | * Close Lob and commit changes. | |||
*/ | */ | |||
void close(); | void close(); | |||
/** | /** | |||
* Reads content from large object into the buffer | * Reads content from large object into the buffer. | |||
* | * | |||
* @param void* Pointer to a byte array where the data shoul | * @param buffer Pointer to a byte array where the data shou | |||
d be written to | ld be written to | |||
* @param size_t Length of the given buffer in bytes | * @param buflen Length of the given buffer in bytes | |||
* @return Number of bytes written into the buffer | * @return Number of bytes written into the buffer | |||
*/ | */ | |||
ssize_t read( void* buffer, size_t buflen ); | ssize_t read( void* buffer, size_t buflen ); | |||
/** | /** | |||
* Writes data from the buffer into the large object | * Writes data from the buffer into the large object. | |||
* | * | |||
* @param void* Pointer to a byte array where the content is | * @param buffer Pointer to a byte array where the content i | |||
stored | s stored | |||
* @param size_t Length of the data in the buffer in bytes | * @param buflen Length of the data in the buffer in bytes | |||
* @return Number of bytes written into the large object | * @return Number of bytes written into the large object | |||
*/ | */ | |||
ssize_t write( void* buffer, size_t buflen ); | ssize_t write( void* buffer, size_t buflen ); | |||
}; | }; | |||
/** | ||||
* Provides result sets from the database. | ||||
*/ | ||||
class Result | class Result | |||
{ | { | |||
protected: | protected: | |||
/** | /** | |||
* Private implementation of object | * Private implementation of object. | |||
*/ | */ | |||
Result_Impl* m_impl; | Result_Impl* m_impl; | |||
/** | /** | |||
* Reference counter of copies | * Reference counter of copies. | |||
*/ | */ | |||
int* m_ref; | int* m_ref; | |||
/** | /** | |||
* Default constructor | * Default constructor. | |||
* | * | |||
* @return Result instance | * @return Result instance | |||
*/ | */ | |||
Result(); | Result(); | |||
/** | /** | |||
* Create Result instance | * Create Result instance. | |||
* | * | |||
* @param Result_Impl* Pointer to private implementation | * @param impl Pointer to private implementation | |||
* @return Result instance | * @return Result instance | |||
*/ | */ | |||
Result( Result_Impl* impl ); | Result( Result_Impl* impl ); | |||
friend class Stmt; | friend class Stmt; | |||
public: | public: | |||
/** | /** | |||
* Destroy Result instance if no other references exist | * Destroy Result instance if no other references exist. | |||
*/ | */ | |||
~Result(); | ~Result(); | |||
/** | /** | |||
* Assign Result instance to another one | * Assign Result instance to another one. | |||
* | * | |||
* @param const Result& Result instance | * @param ref Result instance | |||
* @return Result reference of this instance | * @return Result reference of this instance | |||
*/ | */ | |||
Result& operator=( const Result& ref ); | Result& operator=( const Result& ref ); | |||
/** | /** | |||
* Get unfetched rows and clean up the current result set | * Get unfetched rows and clean up the current result set. | |||
*/ | */ | |||
void finish(); | void finish(); | |||
/** | /** | |||
* Fetch one result set from the database server | * Fetch one result set from the database server. | |||
* | * | |||
* @param struct timeval* Pointer to a timeval struct specif | * @param timeout Pointer to a timeval struct specifying how | |||
ying how long to wait for a result set from the database server | long to wait for a result set from the database server | |||
* @param unsigned long Number of rows to fetch at once from | * @param chunk Number of rows to fetch at once from the dat | |||
the database server (zero means all rows at once) | abase server (zero means all rows at once) | |||
* @return Status or error code | * @return Status or error code | |||
* @see odbxres | ||||
*/ | */ | |||
odbxres getResult( struct timeval* timeout = NULL, unsigned long chunk = 0 ); | odbxres getResult( struct timeval* timeout = NULL, unsigned long chunk = 0 ); | |||
/** | /** | |||
* Makes data of next row available | * Makes data of next row available. | |||
* | * | |||
* @return Status or error code | * @return Status or error code | |||
*/ | */ | |||
odbxrow getRow(); | odbxrow getRow(); | |||
/** | /** | |||
* Returns the number of rows affected by DELETE, INSERT of UPDATE statements | * Returns the number of rows affected by DELETE, INSERT of UPDATE statements. | |||
* | * | |||
* @return Number of rows touched | * @return Number of rows touched | |||
*/ | */ | |||
uint64_t rowsAffected(); | uint64_t rowsAffected(); | |||
/** | /** | |||
* Returns the number of columns available in this result se t | * Returns the number of columns available in this result se t. | |||
* | * | |||
* @return Number of columns | * @return Number of columns | |||
*/ | */ | |||
unsigned long columnCount(); | unsigned long columnCount(); | |||
/** | /** | |||
* Maps the column name to the column number required by oth er methods | * Maps the column name to the column number required by oth er methods. | |||
* | * | |||
* @param name Name of the column in the result set | ||||
* @return Position of column in result set | * @return Position of column in result set | |||
*/ | */ | |||
unsigned long columnPos( const string& name ); | unsigned long columnPos( const string& name ); | |||
/** | /** | |||
* Returns the name of the column in the current result set | * Returns the name of the column in the current result set. | |||
* | * | |||
* @param unsigned long Position of column in result set | * @param pos Position of column in result set | |||
* @return Column name | * @return Column name | |||
*/ | */ | |||
string columnName( unsigned long pos ); | string columnName( unsigned long pos ); | |||
/** | /** | |||
* Returns the type of the column in the current result set | * Returns the type of the column in the current result set. | |||
* | * | |||
* @param unsigned long Position of column in result set | * @param pos Position of column in result set | |||
* @return Column type | * @return Column type | |||
* @see odbxtype | ||||
*/ | */ | |||
odbxtype columnType( unsigned long pos ); | odbxtype columnType( unsigned long pos ); | |||
/** | /** | |||
* Returns the size of the content in the current row at the specified postion | * Returns the size of the content in the current row at the specified postion. | |||
* | * | |||
* @param unsigned long Position of column in result set | * @param pos Position of column in result set | |||
* @return Size of the data in bytes | * @return Size of the data in bytes | |||
*/ | */ | |||
unsigned long fieldLength( unsigned long pos ); | unsigned long fieldLength( unsigned long pos ); | |||
/** | /** | |||
* Returns a pointer to the content in the current row at th e specified postion | * Returns a pointer to the content in the current row at th e specified postion. | |||
* | * | |||
* @param unsigned long Position of column in result set | * @param pos Position of column in result set | |||
* @return Pointer to the data | * @return Pointer to the data | |||
*/ | */ | |||
const char* fieldValue( unsigned long pos ); | const char* fieldValue( unsigned long pos ); | |||
/** | /** | |||
* Create a large object instance if supported by the databa se | * Create a large object instance if supported by the databa se. | |||
* | * | |||
* @param const char* Pointer to the content of a field retu rned by fieldValue() | * @param value Pointer to the content of a field returned b y fieldValue() | |||
* @return Large object instance | * @return Large object instance | |||
* @see Lob | ||||
*/ | */ | |||
Lob getLob( const char* value ); | Lob getLob( const char* value ); | |||
}; | }; | |||
/** | ||||
* Statement object. | ||||
*/ | ||||
class Stmt | class Stmt | |||
{ | { | |||
protected: | protected: | |||
/** | /** | |||
* Private implementation of object | * Private implementation of object. | |||
*/ | */ | |||
Stmt_Impl* m_impl; | Stmt_Impl* m_impl; | |||
/** | /** | |||
* Reference counter of copies | * Reference counter of copies. | |||
*/ | */ | |||
int* m_ref; | int* m_ref; | |||
/** | /** | |||
* Default constructor | * Default constructor. | |||
* | * | |||
* @return Statement instance | * @return Statement instance | |||
*/ | */ | |||
Stmt(); | Stmt(); | |||
/** | /** | |||
* Create statement instance | * Create statement instance. | |||
* | * | |||
* @param Stmt_Impl* Pointer to private implementation | * @param impl Pointer to private implementation | |||
* @return Statement instance | * @return Statement instance | |||
*/ | */ | |||
Stmt( Stmt_Impl* impl ); | Stmt( Stmt_Impl* impl ); | |||
friend class Conn; | friend class Conn; | |||
public: | public: | |||
/** | /** | |||
* Statement objects which can be created | * Statement objects which can be created. | |||
*/ | */ | |||
enum Type { Simple }; | enum Type { Simple }; | |||
/** | /** | |||
* Destroy statement instance if no other references exist | * Destroy statement instance if no other references exist. | |||
*/ | */ | |||
~Stmt(); | ~Stmt(); | |||
/** | /** | |||
* Assign statement instance to another one | * Assign statement instance to another one. | |||
* | * | |||
* @param const Stmt& Stmt instance | * @param ref Stmt instance | |||
* @return Statement reference of this instance | * @return Statement reference of this instance | |||
*/ | */ | |||
Stmt& operator=( const Stmt& ref ); | Stmt& operator=( const Stmt& ref ); | |||
/** | /** | |||
* Execute statement and return Result instance | * Execute statement and return Result instance. | |||
* | * | |||
* @return Result instance | * @return Result instance | |||
* @see Result | ||||
*/ | */ | |||
Result execute(); | Result execute(); | |||
}; | }; | |||
/** | ||||
* Handling a connection to a database. | ||||
*/ | ||||
class Conn | class Conn | |||
{ | { | |||
protected: | protected: | |||
/** | /** | |||
* Private implementation of object | * Private implementation of object. | |||
*/ | */ | |||
Conn_Impl* m_impl; | Conn_Impl* m_impl; | |||
/** | /** | |||
* Reference counter of copies | * Reference counter of copies. | |||
*/ | */ | |||
int* m_ref; | int* m_ref; | |||
public: | public: | |||
/** | /** | |||
* Default constructor | * Default constructor. | |||
* | * | |||
* @return Connection instance | * @return Connection instance | |||
*/ | */ | |||
Conn(); | Conn(); | |||
/** | /** | |||
* Build connection object using C string parameters | * Build connection object using C string parameters. | |||
* | * | |||
* @param const char* Name of the backend module to use | * @param backend Name of the backend module to use | |||
* @param const char* Name or IP address of the database ser | * @param host Name or IP address of the database server | |||
ver | * @param port Name or number of the port used by the databa | |||
* @param const char* Name or number of the port used by the | se server | |||
database server | ||||
* @return Connection instance | * @return Connection instance | |||
*/ | */ | |||
Conn( const char* backend, const char* host = "", const char * port = "" ); | Conn( const char* backend, const char* host = "", const char * port = "" ); | |||
/** | /** | |||
* Build connection object using C++ string parameters | * Build connection object using C++ string parameters. | |||
* | * | |||
* @param string Name of the backend module to use | * @param backend Name of the backend module to use | |||
* @param string Name or IP address of the database server | * @param host Name or IP address of the database server | |||
* @param string Name or number of the port used by the data | * @param port Name or number of the port used by the databa | |||
base server | se server | |||
* @return Connection instance | * @return Connection instance | |||
*/ | */ | |||
Conn( const string& backend, const string& host = "", const string& port = "" ); | Conn( const string& backend, const string& host = "", const string& port = "" ); | |||
/** | /** | |||
* Destroy connection instance if no other references exist | * Destroy connection instance if no other references exist. | |||
*/ | */ | |||
~Conn(); | ~Conn(); | |||
/** | /** | |||
* Assign connection instance to another one | * Assign connection instance to another one. | |||
* | * | |||
* @param const Conn& Connection instance | * @param ref Connection instance | |||
* @return Connection reference of this instance | * @return Connection reference of this instance | |||
*/ | */ | |||
Conn& operator=( const Conn& ref ); | Conn& operator=( const Conn& ref ); | |||
/** | /** | |||
* Log into database server and select database using C stri ng parameters | * Log into database server and select database using C stri ng parameters. | |||
* | * | |||
* @param const char* Name of the database managed by the da | * @param database Name of the database managed by the datab | |||
tabase server | ase server | |||
* @param const char* Name of the user account known by the | * @param who Name of the user account known by the database | |||
database server | server | |||
* @param const char* Necessary credential which belongs to | * @param cred Necessary credential which belongs to the use | |||
the user account | r account | |||
* @param odbxbind Method used for authentication | * @param method Method used for authentication | |||
*/ | */ | |||
void bind( const char* database, const char* who = "", const char* cred = "", odbxbind method = ODBX_BIND_SIMPLE ); | void bind( const char* database, const char* who = "", const char* cred = "", odbxbind method = ODBX_BIND_SIMPLE ); | |||
/** | /** | |||
* Log into database server and select database using C++ st ring parameters | * Log into database server and select database using C++ st ring parameters. | |||
* | * | |||
* @param const char* Name of the database managed by the da | * @param database Name of the database managed by the datab | |||
tabase server | ase server | |||
* @param const char* Name of the user account known by the | * @param who Name of the user account known by the database | |||
database server | server | |||
* @param const char* Necessary credential which belongs to | * @param cred Necessary credential which belongs to the use | |||
the user account | r account | |||
* @param odbxbind Method used for authentication | * @param method Method used for authentication | |||
*/ | */ | |||
void bind( const string& database, const string& who = "", c onst string& cred = "", odbxbind method = ODBX_BIND_SIMPLE ); | void bind( const string& database, const string& who = "", c onst string& cred = "", odbxbind method = ODBX_BIND_SIMPLE ); | |||
/** | /** | |||
* Close connection to the database server | * Close connection to the database server. | |||
*/ | */ | |||
void unbind(); | void unbind(); | |||
/** | /** | |||
* Clean up connection object | * Clean up connection object. | |||
*/ | */ | |||
void finish(); | void finish(); | |||
/** | /** | |||
* Test if the database driver module does understand certai n extensions | * Test if the database driver module does understand certai n extensions. | |||
* | * | |||
* @param odbxcap Constant of the capability | * @param cap Constant of the capability | |||
* @return True if supported, false if not | * @return True if supported, false if not | |||
*/ | */ | |||
bool getCapability( odbxcap cap ); | bool getCapability( odbxcap cap ); | |||
/** | /** | |||
* Get the value of certain options provided by the database driver module | * Get the value of certain options provided by the database driver module. | |||
* | * | |||
* @param odbxcap Constant of the option | * @param option Constant of the option | |||
* @param void* Pointer to memory where the result is stored | * @param value Pointer to memory where the result is stored | |||
*/ | */ | |||
void getOption( odbxopt option, void* value ); | void getOption( odbxopt option, void* value ); | |||
/** | /** | |||
* Set certain options provided by the database driver modul e | * Set certain options provided by the database driver modul e. | |||
* | * | |||
* @param odbxcap Constant of the option | * @param option Constant of the option | |||
* @param void* Pointer to memory which contains the new val | * @param value Pointer to memory which contains the new val | |||
ue | ue | |||
*/ | */ | |||
void setOption( odbxopt option, void* value ); | void setOption( odbxopt option, void* value ); | |||
/** | /** | |||
* Escape potentially dangerous characters in user input usi ng a C++ string parameter | * Escape potentially dangerous characters in user input usi ng a C++ string parameter. | |||
* | * | |||
* @param const string& Input string with which may contain | * @param from Input string with which may contain dangerous | |||
dangerous characters | characters | |||
* @param string& String instance where the escaped characte | * @param to String instance where the escaped characters sh | |||
rs should be written to | ould be written to | |||
* @return Reference to the second parameter containing the escaped characters | * @return Reference to the second parameter containing the escaped characters | |||
*/ | */ | |||
string& escape( const string& from, string& to ); | string& escape( const string& from, string& to ); | |||
/** | /** | |||
* Escape potentially dangerous characters in user input usi ng a C style buffer | * Escape potentially dangerous characters in user input usi ng a C style buffer. | |||
* | * | |||
* @param const char* Input string with which may contain da | * @param from Input string with which may contain dangerous | |||
ngerous characters | characters | |||
* @param unsigned long Size of the input string to escape i | * @param fromlen Size of the input string to escape in byte | |||
n bytes | s | |||
* @param string& String instance where the escaped characte | * @param to String instance where the escaped characters sh | |||
rs should be written to | ould be written to | |||
* @return Reference to the second parameter containing the escaped characters | * @return Reference to the second parameter containing the escaped characters | |||
*/ | */ | |||
string& escape( const char* from, unsigned long fromlen, str ing& to ); | string& escape( const char* from, unsigned long fromlen, str ing& to ); | |||
/** | /** | |||
* Create statement object from SQL text string using a C st yle buffer | * Create statement object from SQL text string using a C st yle buffer. | |||
* | * | |||
* @param const char* SQL text string containing a valid sta | * @param sql SQL text string containing a valid statement u | |||
tement understood by the database server | nderstood by the database server | |||
* @param unsigned long Size of the SQL text string in bytes | * @param size Size of the SQL text string in bytes | |||
* @param Stmt::Type Type of statements object that should b | * @param type Type of statements object that should be crea | |||
e created | ted | |||
* @return Statement instance | * @return Statement instance | |||
* @see Stmt | ||||
*/ | */ | |||
Stmt create( const char* sql, unsigned long size = 0, Stmt:: Type type = Stmt::Simple ); | Stmt create( const char* sql, unsigned long size = 0, Stmt:: Type type = Stmt::Simple ); | |||
/** | /** | |||
* Create statement object from SQL text string using a C++ string | * Create statement object from SQL text string using a C++ string. | |||
* | * | |||
* @param string SQL text string containing a valid statemen | * @param sql SQL text string containing a valid statement u | |||
t understood by the database server | nderstood by the database server | |||
* @param Stmt::Type Type of statements object that should b | * @param type Type of statements object that should be crea | |||
e created | ted | |||
* @return Statement instance | * @return Statement instance | |||
* @see Stmt | ||||
*/ | */ | |||
Stmt create( const string& sql, Stmt::Type type = Stmt::Simp le ); | Stmt create( const string& sql, Stmt::Type type = Stmt::Simp le ); | |||
}; | }; | |||
} // namespace OpenDBX | } // namespace OpenDBX | |||
} // extern C++ | } // extern C++ | |||
#endif | #endif | |||
End of changes. 95 change blocks. | ||||
131 lines changed or deleted | 147 lines changed or added | |||