/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                          CDatabaseField.h  -  description
                             -------------------
    begin                : Wednesday November 2 2005
    copyright            : (C) 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 __CDATABASEFIELD_H__
#define __CDATABASEFIELD_H__

#include <sptk3/sptk-config.h>

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

class CQuery;
class CDatabase;

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

/// @brief database field
///
/// A special variation of CField to support database field essentials
class SP_EXPORT CDatabaseField : public CField {
   friend class CQuery;
   friend class CDatabase;
private:
   int          m_fldType;  	///< Native database data type
   int          m_fldColumn;	///< Field column number in recordset
   int          m_fldSize;		///< Field size
   int          m_fldScale;	///< Field scale, optional, for floating point fields

public:

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

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

   /// @brief Checks the internal buffer size
   ///
   /// The internal buffer is automatically extended to fit the required size of data
   /// @param sz unsigned, data size (in bytes)
   /// @returns true if success
   bool checkSize(unsigned sz);

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

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

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

/// @}

#endif
