/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CODBCField.h  -  description
                             -------------------
    begin                : Wed Dec 15 1999
    copyright            : (C) 1999-2005 by Alexey Parshin
    email                : alexeyp@gmail.com
 ***************************************************************************/

/***************************************************************************
   This library is free software; you can redistribute it and/or modify it 
   under the terms of the GNU Library General Public License as published by
   the Free Software Foundation; either version 2 of the License, or (at 
   your option) any later version.

   This library 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 Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@gmail.com"
 ***************************************************************************/

#ifndef __CODBCFIELD_H__
#define __CODBCFIELD_H__

#include <sptk3/sptk-config.h>

#if HAVE_ODBC == 1

#include <sptk3/CVariant.h>
#include <sptk3/CStrings.h>
#include <sptk3/CField.h>

class CQuery;
class CODBCDatabase;

/// @addtogroup Database Database Support
/// @{

/// @brief ODBC field
///
/// A special variation of CField to support ODBC field essentials
class SP_EXPORT CODBCField : public CField {
   friend class CQuery;
   friend class CODBCDatabase;
private:
   /// ODBC data type
   int          m_fldType;  
   /// Field column number in recordset
   int          m_fldColumn;
   /// Field size
   int          m_fldSize;
   /// Field scale
   int          m_fldScale;

protected:

   /// Checks the internal buffer size
   bool checkSize(unsigned sz);

public:

   /// Constructor
   /// @param fieldName std::string, field name
   /// @param fieldColumn int, field column number
   /// @param fieldType int, ODBC field type
   /// @param dataType CVariantType, variant data type
   /// @param fieldLength int, ODBC field length
   /// @param fieldScale int, ODBC field scale
   CODBCField(const std::string fieldName,int fieldColumn,int fieldType,CVariantType dataType,int fieldLength,int fieldScale);

   std::string      displayName;		///< Column display name
   std::string      displayFormat;	///< Column display format
   int              alignment;		///< Column alignment
   bool             visible;			///< Is column visible?

   /// Reports field column number
   int          fieldColumn() const { return m_fldColumn;   }

   /// Reports ODBC field type
   int          fieldType()   const { return m_fldType;     }

   /// Reports field size
   unsigned     fieldSize()   const { return m_fldSize;     }
};

/// @}

#endif

#endif
