databaseColumn.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 ** Copyright (c) 1992-2010 VT MAK
00003 ** All rights reserved.
00004 ******************************************************************************/
00005 
00008 
00009 #ifndef databaseColumn_H_
00010 #define databaseColumn_H_
00011 
00012 #include "vlDatabase.h"
00013 
00014 
00015 #include <list>
00016 #include <vlutil/vlString.h>
00017 #include <vector>
00018 
00019 
00020 // DtDatabaseColumn represents a single column in an SQL database table. It
00021 // has a storage type from the enumerated list above, plus any of several
00022 // attributes such as being a primary or secondary key; a display size; default
00023 // value; et. al.  The class has a stringRep() method that, once the attributes
00024 // of the column have been defined, will provide a string that can be used as
00025 // part of an SQL CREATE TABLE query for defining the column.
00026 class DT_DLL_VLDB DtDatabaseColumn
00027 {
00028 public:
00029    // enumeration of storage types supported (note that this is not an
00030    // exhaustive list of what SQL can support; rather, it's a list of
00031    // useful types for our application).
00032    enum DataType
00033    {
00034       Type_SqlNone         = 0, // Nothing (not a type)
00035       Type_SqlChar         = 1, // a char treated as an 8-bit integer
00036       Type_SqlShort        = 2,
00037       Type_SqlInt          = 3,
00038       Type_SqlLong         = 4,
00039       Type_SqlFloat        = 5,
00040       Type_SqlDouble       = 6,
00041       Type_SqlFixedString  = 7,
00042       Type_SqlVarString    = 8,
00043       Type_SqlIndex        = 9, // not really a storage type, but a special column
00044                                 // type that refers to a multi-column index (key).
00045       Type_SqlEnum8     = 10,
00046       Type_SqlEnum16    = 11,
00047       Type_SqlEnum32    = 12,
00048       Type_SqlBool      = 13,
00049       Type_SqlUnsignedShort = 15,
00050       Type_SqlUnsignedInt = 16,
00051       Type_SqlUnsignedLong = 17
00052    };
00053 
00055    typedef std::list<DtString> IndexNameList;
00056 
00057    // Main constructor
00058    DtDatabaseColumn(const DtString& columnName, DataType columnType );
00059 
00060    // Destructor
00061    virtual ~DtDatabaseColumn();
00062 
00063    // Copy constructor
00064    DtDatabaseColumn( const DtDatabaseColumn& src );
00065 
00066    // Assignment operator
00067    virtual DtDatabaseColumn& operator=(const DtDatabaseColumn& src );
00068 
00069    // return the name of this column
00070    const DtString& columnName() const;
00072    virtual void setColumnName(const DtString&);
00073 
00074    // return the (storage) type of this column
00075    DataType columnType() const;
00076    virtual void setColumnType(DataType type);
00077 
00078    // return true if this column has a display size specified
00079    bool hasDisplaySize() const;
00080 
00081    // return true if this column has a default value specified
00082    bool hasDefaultValue() const;
00083 
00084    // Set / get common SQL field attributes
00085 
00086    // the width of the display field for this column
00087    int displaySize() const;
00088    void setDisplaySize(int displaySize );
00089 
00090    // the number of decimals to show (only applies to floats / doubles)
00091    int numDecimals() const;
00092    void setNumDecimals( int numDecimals );
00093 
00094    // is this field unsigned?
00095    bool isUnsigned() const;
00096    void setIsUnsigned( bool isUnsigned );
00097 
00098    // can this field have un-set (null) values?
00099    bool nullAllow() const;
00100    void setNullAllow( bool nullAllow );
00101 
00102    // Is there a default value for this field?  This is specifed as
00103    // a string to be type independent.
00104    const DtString& defaultValue() const;
00105    void setDefaultValue( const DtString& defaultValue );
00106 
00107    // Is this an auto-increment field? (auto-increment fields automatically
00108    // count up, such as a record number).
00109    bool autoIncrement() const;
00110    void setAutoIncrement( bool autoIncrement );
00111 
00112    // Is this field a table's primary key
00113    bool isPrimaryKey() const;
00114    void setIsPrimaryKey( bool isPrimaryKey );
00115 
00116    // Is this field a secondary key for a table?
00117    bool isSecondaryKey() const;
00118    void setIsSecondaryKey( bool isSecondaryKey );
00119 
00120    // If the column is an index definition, this is the list of column
00121    // names that makes up that index
00122    const IndexNameList& indexNameList() const;
00123 
00124    // Add a column name to an index column
00125    void addIndexName( const DtString& indexName );
00126 
00127    // clear the index name list
00128    void clearIndexNameList();
00129 
00130    // Get the current value.
00131    const DtString& value() const;
00132 
00133    // Set the current value.
00134    void setValue(const DtString& value);
00135 
00136    // Get the number of values.
00137    int valueCount() const;
00138 
00139    // Get a specific value.
00140    const DtString& value(size_t index) const;
00141 
00142    // Add a new value.
00143    void addValue(const DtString& value);
00144 
00145    // Get to see if the value is null.
00146    bool isNull(size_t index) const;
00147 
00148    // Get the data type for the native C/C++ type.
00149    static DataType dataTypeFromNativeType(const DtString& naticeCType);
00150 
00151 protected:
00152 
00153    static DtString theNullString;
00154 
00155    DtString myColumnName;
00156    DtString myDefaultValue;
00157 
00158    std::vector<DtString> myStringReps;
00159    IndexNameList myIndexNameList;
00160 
00161    DataType myColumnType;
00162 
00163    int myDisplaySize;
00164    int myNumDecimals;
00165 
00166    bool myAutoIncrement;
00167    bool myHasDefaultValue;
00168    bool myHasDisplaySize;
00169    bool myIsPrimaryKey;
00170    bool myIsSecondaryKey;
00171    bool myIsUnsigned;
00172    bool myNullAllow;
00173 
00174 };
00175 
00176 
00177 #endif

Document ID: Generated on Tue Oct 11 19:41:03 EDT 2011 from SVN revision 107422
Copyright © 2005-2011 VT MÄK Inc. All Rights Reserved (www.mak.com)