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

Fl_Database.h

00001 /***************************************************************************
00002                           Fl_Database.h  -  description
00003                              -------------------
00004     begin                : Sat Dec 28 2002
00005     copyright            : (C) 2002 by Alexey Parshin
00006     email                : alexeyp@m7.tts-sf.com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef _FL_DATABASE_H_
00019 #define _FL_DATABASE_H_
00020 
00021 #include <efltk/Fl_String.h>
00022 #include <efltk/Fl_Ptr_List.h>
00023 #include <efltk/Fl_Exception.h>
00024 #include <efltk/Fl_Thread.h>
00025 #include <efltk/db/Fl_Query.h>
00026 
00027 class Fl_Database {
00028     friend class   Fl_Query;
00029 
00030 protected:
00031     Fl_Ptr_List    m_queryList;
00032     Fl_String      m_connString;
00033     bool           m_active;
00034     bool           m_inTransaction;
00035     Fl_Mutex      *m_mutex;
00036 
00037 protected:
00038     // Operations over query handle
00039     // These methods should be implemented in actual database class
00040     virtual void allocate_query(Fl_Query *) = 0;
00041     virtual void deallocate_query(Fl_Query *) = 0;
00042     virtual void prepare_query(Fl_Query *) = 0;
00043     virtual void open_query(Fl_Query *)  = 0;
00044     virtual void fetch_query(Fl_Query *) = 0;
00045     virtual void close_query(Fl_Query *) = 0;
00046 
00047     // These methods should be implemented in actual database class
00048     virtual void open_connection() = 0;
00049     virtual void close_connection() = 0;
00050 
00051     // These methods provide access to protected data of Fl_Query
00052     void *query_handle(const Fl_Query *q) const     { return q->m_stmt; }
00053     void  query_handle(Fl_Query *q,void *handle)    { q->m_stmt = handle; }
00054     bool  query_active(Fl_Query *q)                 { return q->m_active; }
00055     void  query_active(Fl_Query *q,bool active)     { q->m_active = active; }
00056     void  query_eof(Fl_Query *q,bool eof)           { q->m_eof = eof; }
00057     Fl_Data_Fields& query_fields(Fl_Query *q)       { return q->m_fields; }
00058 
00059 public:
00060     // Capabilities:
00061     enum {
00062         UNKNOWN = 0,
00063         TRANSACTIONS,
00064         STMT_PREPARE,
00065     };
00066 
00067     Fl_Database(const Fl_String connString,bool threadSafe=false);
00068     virtual ~Fl_Database();
00069 
00070     void open(const char *connString="");
00071     void close();
00072 
00073     const Fl_String &connect_string() const         { return m_connString; }
00074     void connect_string(const char *connString)     { m_connString = connString; }
00075 
00076     bool active() const                             { return m_active; }
00077     bool in_transaction() const                     { return m_inTransaction; }
00078 
00079     bool thread_safe() const                        { return (m_mutex!=0); }
00080     void lock()                                     { if (m_mutex) m_mutex->lock(); }
00081     void unlock()                                   { if (m_mutex) m_mutex->unlock(); }
00082 
00083     // These methods should be implemented in actual database class
00084     virtual unsigned capabilities()                 { return UNKNOWN; }
00085 
00086     virtual void begin_transaction()                { fl_throw("Transactions are not supported"); }
00087     virtual void commit_transaction()               { fl_throw("Transactions are not supported"); }
00088     virtual void rollback_transaction()             { fl_throw("Transactions are not supported"); }
00089 };
00090 
00091 #define FL_DB_UNKNOWN      Fl_Database::UNKNOWN
00092 #define FL_DB_TRANSACTIONS Fl_Database::TRANSACTIONS
00093 #define FL_DB_STMT_PREPARE Fl_Database::STMT_PREPARE
00094 
00095 #endif

Generated on Thu Jul 31 15:33:43 2003 for eFLTK by doxygen1.2.15