Made to Order Software Corporation Logo

odbcpp: odbcpp::record_base Class Reference

The record base class, used mainly internally. More...

#include <record.h>

Inheritance diagram for odbcpp::record_base:
Collaboration diagram for odbcpp::record_base:

List of all members.

Public Member Functions

virtual void bind (statement &stmt)
 Binds a record to a statement.

virtual void finalize ()
 Called after each call to SQLFetch().

bool is_bound () const
 Bound was applied?

virtual bool is_dynamic () const =0
 Bound all the columns to variables automatically?

record_baseoperator= (const record_base &base)
 Copy a record in another.

 record_base (const record_base &base)
 Initialize a record from another.

 record_base ()
 Initialize a record base object.

void unbind ()
 Unbinds a record from its statement.

virtual ~record_base ()
 Ensure proper functioning of the virtual tables.

Protected Attributes

smartptr< statementf_statement
 A link back to the statement that generated this record.

Private Member Functions

virtual void bind_impl ()=0
 Proceed with binding the variables.


Detailed Description

The record base class, used mainly internally.

This is a base class used to create records used to fetch data from a database.

You are not supposed to derive directly from the record_base. Instead, use the record or the dynamic_record classes.

See also:
odbcpp::record
odbcpp::dynamic_record

Definition at line 93 of file record.h.


Constructor & Destructor Documentation

odbcpp::record_base::record_base (  ) 

Initialize a record base object.

This function initializes a record.

Definition at line 57 of file record.cpp.

odbcpp::record_base::record_base ( const record_base rec  ) 

Initialize a record from another.

This function copies a record in another.

The new record base f_statement field will remain set to NULL. Thus, one can copy a record base, but the new record looks unbound.

Parameters:
[in] rec The record to be copied.

Definition at line 72 of file record.cpp.

odbcpp::record_base::~record_base (  )  [inline, virtual]

Ensure proper functioning of the virtual tables.

Definition at line 98 of file record.h.


Member Function Documentation

void odbcpp::record_base::bind ( statement stmt  )  [virtual]

Binds a record to a statement.

This function binds this record to the specified statement.

Note that one record cannot be bound more than once and especially not to two different statements unless unbound first. Call the record_base::unbind() function to unbind a record from a statement.

Parameters:
[in] stmt The statement to which this record is to be bound
See also:
bind_impl()

Definition at line 154 of file record.cpp.

References bind_impl(), f_statement, and odbcpp::odbcpp_error::ODBCPP_INCORRECT_USE.

Referenced by odbcpp::statement::fetch().

odbcpp::record_base::bind_impl (  )  [private, pure virtual]

Proceed with binding the variables.

This function is the one used to bind a record variables to an ODBC statement.

Bug:
The dynamic record binding changes the target type from the SQL type to the corresponding C type. The table below shows the different conversions.
 The following shows what the SQL types are bound with.

 (=) SQL_<name> and SQL_C_<name> are equal
 (<>) SQL_<name> and SQL_C_<name> differ and a mapping is necessary

 We do not make use of SQL_C_DEFAULT at this time.

   SQL data types                    C data types

 SQL_UNKNOWN_TYPE       0            <undefined>
 SQL_CHAR               1            SQL_C_CHAR (=)
 SQL_NUMERIC            2            SQL_C_NUMERIC (=, SQL_C_CHAR up to v3.0 and thus <>)
 SQL_DECIMAL            3            SQL_C_CHAR (<>)
 SQL_INTEGER            4            SQL_C_LONG (=)
 SQL_SMALLINT           5            SQL_C_SHORT (=)
 SQL_FLOAT              6            SQL_C_DOUBLE (<>)
 SQL_REAL               7            SQL_C_FLOAT (=)
 SQL_DOUBLE             8            SQL_C_DOUBLE (=)
 SQL_DATETIME           9            ignore, same as SQL_DATE
 SQL_DATE               9            SQL_C_DATE (=)
 SQL_INTERVAL          10            ignore, same as SQL_TIME
 SQL_TIME              10            SQL_C_TIME (=)
 SQL_TIMESTAMP         11            SQL_C_TIMESTAMP (=)
 SQL_VARCHAR           12            SQL_C_CHAR (<>)
 SQL_TYPE_DATE         91            SQL_C_TYPE_DATE (=)
 SQL_TYPE_TIME         92            SQL_C_TYPE_TIME (=)
 SQL_TYPE_TIMESTAMP    93            SQL_C_TYPE_TIMESTAMP (=)
 SQL_LONGVARCHAR     (-1)            SQL_C_CHAR (<>)
 SQL_BINARY          (-2)            SQL_C_BINARY (=)
 SQL_VARBINARY       (-3)            SQL_C_CHAR (<>)
 SQL_LONGVARBINARY   (-4)            SQL_C_CHAR (<>)
 SQL_BIGINT          (-5)            SQL_C_SBIGINT (<>)
 SQL_TINYINT         (-6)            SQL_C_TINYINT (=)
 SQL_BIT             (-7)            SQL_C_BIT (=)
 SQL_WCHAR           (-8)            SQL_C_WCHAR (=)
 SQL_WVARCHAR        (-9)            SQL_C_WCHAR (<>)
 SQL_WLONGVARCHAR   (-10)            SQL_C_WCHAR (<>)
 SQL_GUID           (-11)            SQL_C_CHAR (<>)
Exceptions:
odbcpp_error A record with no variable will raise an odbcpp_error.

Implemented in odbcpp::record, and odbcpp::dynamic_record.

Referenced by bind().

odbcpp::record_base::finalize (  )  [inline, virtual]

Called after each call to SQLFetch().

After we read a row, there can be some data that we need to copy from the internal buffer to the user buffer. Namely, we copy C strings to std::string's in pre-bound records.

Reimplemented in odbcpp::record.

Definition at line 108 of file record.h.

Referenced by odbcpp::statement::fetch().

odbcpp::record_base::is_bound (  )  const [inline]

Bound was applied?

Check whether the data defined in that record need to be bound to the database or not. This is an internal flag and it should not be necessary to use it outside of the odbcpp library.

Returns:
true if the bound was already applied

Definition at line 104 of file record.h.

References f_statement.

odbcpp::record_base::is_dynamic (  )  const [pure virtual]

Bound all the columns to variables automatically?

If this function returns true, then the record will dynamically bound the columns to variables.

Returns:
true if the variables will automatically allocated and bound

Implemented in odbcpp::record, and odbcpp::dynamic_record.

record_base & odbcpp::record_base::operator= ( const record_base rec  ) 

Copy a record in another.

This function copies a record in another.

The destination record base f_statement field is reset with a call to unbind().

Parameters:
[in] rec The record to be copied.
See also:
record_base::record_base()
record_base::record_base(const record_base& rec)
record_base::unbind()

Definition at line 110 of file record.cpp.

References unbind().

odbcpp::record_base::unbind (  )  [inline]

Unbinds a record from its statement.

This function unbinds the statement from this record. This is used if you do not have direct control over the record and thus cannot know when the record will be freed and release the statement.

After a fetch() the data in a record is defined and thus keeping it bound is not necessary. However, if you are to reuse the same record over and over again, keeping it bound will make it a lot faster to read the next row.

See also:
bind(statement& stmt)
bind_impl()

Definition at line 107 of file record.h.

References f_statement, and odbcpp::smartptr< T >::reset().

Referenced by operator=().


Member Data Documentation

A link back to the statement that generated this record.

This variable member is set the first time a fetch() is called with this record.

If you call unbind() then the statement pointer is reset to NULL. This means the next call to a fetch() function will re-bind the statement with the record. This lets you use the same record with a different statement.

Definition at line 111 of file record.h.

Referenced by bind(), odbcpp::dynamic_record::bind_impl(), odbcpp::record::bind_impl(), is_bound(), and unbind().


The documentation for this class was generated from the following files:
Generated on Mon Sep 19 12:52:28 2011 for odbcpp by  doxygen 1.6.3