Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members

FXDatabaseField.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                      Database field handling                                  *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 2003 by Mathew Robertson.       All Rights Reserved.            *
00007 * Copyright (C) 2003 by Giancarlo Formicuccia.  All Rights Reserved.            *
00008 *********************************************************************************
00009 * This library is free software; you can redistribute it and/or                 *
00010 * modify it under the terms of the GNU Lesser General Public                    *
00011 * License as published by the Free Software Foundation; either                  *
00012 * version 2.1 of the License, or (at your option) any later version.            *
00013 *                                                                               *
00014 * This library is distributed in the hope that it will be useful,               *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00017 * Lesser General Public License for more details.                               *
00018 *                                                                               *
00019 * You should have received a copy of the GNU Lesser General Public              *
00020 * License along with this library; if not, write to the Free Software           *
00021 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00022 *********************************************************************************/
00023 #ifndef FXDATABASEFIELD_H
00024 #define FXDATABASEFIELD_H
00025 
00026 
00027 #include "FXBaseObject.h"
00028 #include "FXVariant.h"
00029 #include <fox/FXObjectList.h>
00030 
00031 namespace FXEX {
00032 
00033 class FXDatabaseInterface;
00034 class FXDatabaseQuery;
00035 class FXDatabaseField;
00036 
00037 
00038 
00039 /* State of current FXDatabaseQuery */
00040 typedef enum {
00041   rsInvalid = -1,   /* Invalid (i.e. FXDatabaseInterface shut down) */
00042   rsClose,          /* Not open */
00043   rsRead,           /* Open and in read state */
00044   rsAddNew,         /* Open and in add-new state */
00045   rsModify,         /* Open and modify state */
00046   rsDelete          /* unused */
00047 } FXrsState;
00048 
00049 
00050 /* Type of event */
00051 typedef enum {
00052   dbRefresh,        /* Field value may have changed */
00053   dbUpdate,         /* Update successfully performed */
00054   dbCancelUpdate,   /* Update aborted */
00055   dbAddNew,         /* Entering add-new state */
00056   dbEdit,           /* Entering modify state */
00057   dbDelete,         /* Record has been deleted */
00058   dbConnect,        /* FXDatabaseInterface notified a new connection */
00059   dbDisconnect,     /* FXDatabaseInterface shut down */
00060   dbOpen,           /* FXDatabaseQuery just open */
00061   dbClose,          /* FXDatabaseQuery closed */
00062   dbDestroy,        /* FXDatabaseQuery is going to be destroyed */
00063   dbAskData,        /* FXDatabaseField is asking his target for (modified?) data */
00064 } FXdbEvType;
00065 
00066 
00067 /* FXDatabase* event (aka void * field of message handlers) */
00068 typedef struct {
00069   FXdbEvType type;            /* Event type */
00070   FXrsState state;            /* Current FXDatabaseQuery state */
00071   FXDatabaseInterface *dbi;   /* !=NULL if FXDatabaseInterface is in event chain */
00072   FXDatabaseQuery *dbq;       /* !=NULL if FXDatabaseQuery is in event chain */
00073   FXDatabaseField *dbf;       /* !=NULL if FXDatabaseField is in event chain */
00074   FXVariant data;             /* i.e. dbAskData, dbRefresh */
00075 } FXdbEvent;
00076 
00077 
00078 /* This struct describes the fox properties of a field */
00079 typedef struct {
00080   FXString name;    /* Field name */
00081   FXint index;      /* Field index (base 0) */
00082   FXbool nullable;  /* Field is nullable */
00083   FXint fxType;     /* Field fox type (FXVariant::DT_*) as reported from low-level driver */
00084   FXint maxSize;    /* including '\0' in strings */
00085   FXbool varSize;   /* <info> variable-sized field */
00086   FXbool counter;   /* <hint> auto-increment non-null field (not always reported) */
00087   FXbool readOnly;  /* <hint> Field value cannot be changed */
00088 } FXFieldType;
00089 
00090 
00091 
00092 
00093 
00094 class FXAPI FXDatabaseField: public FXBaseObject {
00095   FXDECLARE(FXDatabaseField)
00096 private:
00097   FXVariant oldValue;
00098   FXVariant value;
00099   FXDatabaseQuery *qry;
00100   FXFieldType fType;
00101 
00102   void checkBind() const;
00103   FXVariant convertData(const FXVariant &src);
00104 protected:
00105   FXDatabaseField() {}
00106 public:
00107   enum {
00108     ID_EVENT = FXBaseObject::ID_LAST,
00109     ID_SETFIELDTYPE,
00110     ID_SETDATA,
00111     ID_GETDATA,
00112     ID_REFRESHOLD, /* hack - set tgt with *old* value */
00113     ID_LAST
00114   };
00115 
00116   long onSetFieldType(FXObject *, FXSelector, void *);
00117   long onSetData(FXObject *, FXSelector, void *);
00118   long onGetData(FXObject *, FXSelector, void *);
00119   long onDispatch(FXObject *, FXSelector, void *);
00120   long onRefreshOld(FXObject *, FXSelector, void *);
00121 public:
00122   FXDatabaseField(FXDatabaseQuery *qry);
00123   virtual ~FXDatabaseField() {}
00124   virtual void save(FXStream& store) const;
00125   virtual void load(FXStream& store);
00126   operator FXVariant(); /* *not* const :-) */
00127   const FXVariant &getValue() const;
00128   FXDatabaseField &operator=(const FXVariant &v);
00129   FXint getType() const { checkBind(); return fType.fxType; }
00130   FXbool isNullable() const { checkBind(); return fType.nullable; }
00131   FXString name() const { checkBind(); return fType.name; }
00132   const FXFieldType &getFieldType() const { checkBind(); return fType; }
00133 };
00134 
00135 typedef FXObjectListOf<FXDatabaseField> FXDatabaseFieldList;
00136 
00137 }
00138 
00139 #endif /* FXDATABASEFIELD_H */