DumontEXE 0.0.1
cmcDatabase.cpp
00001 /* ***************************************************************************
00002 **
00003 ** Copyright (C) 2007 Lorimark Solutions, LLC. All rights reserved.
00004 **
00005 ** This file is part of the DumontEXE Scripting Extension Kit
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://dumont.showoff-db.org/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://dumont.showoff-db.org/licensing.html 
00017 ** or contact the sales department at sales@lorimarksolutions.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ** author: Mark Petryk ~ Lorimark Solutions, LLC
00023 ** **************************************************************************/
00024 
00025 #include <QVariant>
00026 
00027 #include "cmcDatabase.h"
00028 #include "cmcApplication.h"
00029 #include "cmcConversation.h"
00030 #include "cmcRowSet.h"
00031 #include "cmcForm.h"
00032 #include "cmcForms.h"
00033 #include "cmcItem.h"
00034 #include "cmcItems.h"
00035 
00036 namespace cmcDatabaseApi {
00037 
00038 cmcDatabase::cmcDatabase( IDispatch * dispatch, cmcApplication * app ):
00039   cmcApi( "Database", dispatch, app, (QObject*)app )
00040 {
00041 //  TRACE_FUNCTION
00042 }
00043 
00044 cmcDatabase::~cmcDatabase()
00045 {
00046 //  TRACE_FUNCTION
00047 
00048   /*
00049   ** Delete the forms collection.  This will do nothing if the collection
00050   **  was never instantiated.
00051   **
00052   */
00053   delete m_forms;
00054 
00055 } // endcmcDatabase::~cmcDatabase()
00056 
00057 QString cmcDatabase::name()
00058 {
00059 //  TRACE_FUNCTION
00060 
00061   return( GetServerString("name") );
00062 
00063 } // endQString cmcDatabase::name(void)
00064 
00065 QString cmcDatabase::path()
00066 {
00067 //  TRACE_FUNCTION
00068 
00069   return( GetServerString("path") );
00070 
00071 } // endQString cmcDatabase::path(void)
00072 
00073 QString cmcDatabase::registeredUser()
00074 {
00075 //  TRACE_FUNCTION
00076 
00077   return( GetServerString("RegisteredUser") );
00078 
00079 } // endQString cmcDatabase::registeredUser(void)
00080 
00081 bool cmcDatabase::shared()
00082 {
00083 //  TRACE_FUNCTION
00084 
00085   return( GetServerBool("Shared") );
00086 
00087 } // endbool cmcDatabase::shared(void)
00088 
00089 QString cmcDatabase::version()
00090 {
00091 //  TRACE_FUNCTION
00092 
00093   return( GetServerString("Version") );
00094 
00095 } // endQString cmcDatabase::version(void)
00096 
00097 QString cmcDatabase::versionExt()
00098 {
00099 //  TRACE_FUNCTION
00100 
00101   return( GetServerString("VersionExt") );
00102 
00103 } // endQString cmcDatabase::versionExt(void)
00104 
00105 cmcConversation * cmcDatabase::getConversation( const QString & applicationName, const QString & topic )
00106 {
00107 //  TRACE_FUNCTION
00108 
00109   /*
00110   ** If we've already fetched the conversation we don't need to do it
00111   **  again.
00112   **
00113   */
00114   if( !m_conversation )
00115   {
00116     /*
00117     ** Initialize the application and topic name to something in case
00118     **  nothing was provided on the parameter list.
00119     **
00120     */
00121     QString appName = applicationName;
00122     QString topName = topic;
00123 
00124     if( appName == "" ) appName = "Commence"; // app()-> databaseName();
00125     if( topName == "" ) topName = path();
00126 
00127     /*
00128     ** Try to get a dispatch pointer for the conversation object.
00129     **
00130     */
00131     IDispatch * dispatch = GetServerObject( appName, topName, "GetConversation" );
00132 
00133     /*
00134     ** Chances are we didn't get one.
00135     **
00136     */
00137     if( dispatch )
00138     {
00139       /*
00140       ** If we got a dispatch pointer, then create a new conversation object
00141       **  to manage it.
00142       **
00143       */
00144       m_conversation = new cmcConversation( appName, topName, dispatch, app(), this );
00145 
00146       /*
00147       ** Assign this object the same level of trace that is currently
00148       **  on the database object.
00149       **
00150       */
00151       m_conversation-> trace( trace() );
00152 
00153       /*
00154       ** Don't forget to release our initial dispatch pointer.
00155       **
00156       */
00157       dispatch-> Release();
00158 
00159     } // endif( dispatch )
00160 
00161   } // endif( !m_conversation )
00162 
00163   /*
00164   ** Return the conversation object.
00165   **
00166   */
00167   return( m_conversation );
00168 
00169 } // endcmcConversation * cmcDatabase::getConversation( const QString & applicationName, const QString & topic )
00170 
00171 
00172 cmcCursor * cmcDatabase::getCursor( const QString & i_name, long i_flags )
00173 {
00174 //  TRACE_FUNCTION
00175 
00176   return( getCursor( 0, i_name, i_flags ) );
00177 
00178 } // endcmcCursor * cmcDatabase::getCursor( const QString & i_name, const long i_flags )
00179 
00180 
00181 cmcCursor * cmcDatabase::getCursor( long i_mode, const QString & i_name, long i_flags )
00182 {
00183 //  TRACE_FUNCTION
00184 
00185   /*
00186   ** Default to an empty return value
00187   **
00188   */
00189   cmcCursor * retVal = NULL;
00190 
00191   /*
00192   ** Get a cursor from Commence (or try to)
00193   **
00194   */
00195   IDispatch * dispatch = GetServerObject( i_mode, i_name, i_flags, "GetCursor" );
00196 
00197   /*
00198   ** If we were able to get a cursor then wrap it.
00199   **
00200   */
00201   if( dispatch )
00202   {
00203     /*
00204     ** Wrap the dispatch pointer with a new cursor object.
00205     **
00206     */
00207     retVal = new cmcCursor( i_mode, i_name, i_flags, dispatch, app() );
00208 
00209     /*
00210     ** Set the trace on the cursor to the same as the database.
00211     **
00212     */
00213     retVal-> trace( trace() );
00214 
00215     /*
00216     ** Don't forget to release our original dispatch pointer.
00217     **
00218     */
00219     dispatch-> Release();
00220 
00221   } // endif( dispatch )
00222 
00223   /*
00224   ** Return the wrapped dispatch pointer if we were able to get one
00225   **
00226   */
00227   return( retVal );
00228 
00229 } // endcmcCursor * cmcDatabase::getCursor( const long i_mode, const QString & i_name, const long i_flags )
00230 
00231 
00232 cmcItem * cmcDatabase::getItem
00233 (
00234   const QString & categoryName,
00235   const QString & itemKey,
00236   long flags
00237 )
00238 {
00239   cmcItem * retVal = new cmcItem( categoryName, flags, app() );
00240 
00241   retVal-> loadByKey( itemKey );
00242 
00243   return( retVal );
00244 }
00245 
00246 cmcItem * cmcDatabase::getItemByGuid
00247 (
00248   const QString & categoryName,
00249   const QString & itemGuid,
00250   long flags
00251 )
00252 {
00253   cmcItem * retVal = new cmcItem( categoryName, flags, app() );
00254 
00255   retVal-> loadByGuid( itemGuid );
00256 
00257   return( retVal );
00258 }
00259 
00260 cmcItem * cmcDatabase::getItemByField
00261 (
00262   const QString & categoryName,
00263   const QString & fieldName,
00264   const QString & qualifier,
00265   const QString & value,
00266   bool notFlag,
00267   bool caseSensitive
00268 )
00269 {
00270   cmcItem * retVal = new cmcItem( categoryName, 0, app() );
00271 
00272   retVal-> loadByField( fieldName, qualifier, value, notFlag, caseSensitive );
00273 
00274   return( retVal );
00275 }
00276 
00277 cmcItems * cmcDatabase::getItems
00278 (
00279   const QString & categoryName
00280 )
00281 {
00282   cmcItems * retVal = new cmcItems( categoryName, this );
00283 
00284   return( retVal );
00285 }
00286 
00287 
00288 
00289 //cmcItems * cmcDatabase::getItems
00290 //(
00291 //  const QString & itemName,
00292 //  const QString & connectionName,
00293 //  const QString & targetCategoryName,
00294 //  const QString & reverseConnectionName,
00295 //  long flags
00296 //)
00297 //{
00298 //  return( new cmcItems( itemName, connectionName, targetCategoryName, reverseConnectionName, flags, app() ) );
00299 //}
00300 //
00301 
00302 cmcForms * cmcDatabase::forms()
00303 {
00304 //  TRACE_FUNCTION
00305 
00306   /*
00307   ** Check to see if we have a forms collection.  If not make one.
00308   **
00309   */
00310   if( !m_forms )
00311        m_forms = new cmcForms(this);
00312 
00313   /*
00314   ** Return the forms collection
00315   **
00316   */
00317   return( m_forms );
00318 
00319 } // endcmcForms * cmcDatabase::forms(void)
00320 
00321 
00322 cmcForm * cmcDatabase::form( long index )
00323 {
00324   return( forms()-> get( index ) );
00325 }
00326 
00327 cmcForm * cmcDatabase::form( const QString & name )
00328 {
00329   return( forms()-> get( name ) );
00330 }
00331 
00332 cmcForm * cmcDatabase::previousForm()
00333 {
00334   cmcForm * retVal = NULL;
00335 
00336   if( forms()-> count() > 1 )
00337     retVal = form( forms()-> count() - 2 );
00338 
00339   return( retVal );
00340 }
00341 
00342 cmcMeInfo * cmcDatabase::meInfo()
00343 {
00344   if( !m_meInfo )
00345        m_meInfo = new cmcMeInfo( app(), this );
00346 
00347   return( m_meInfo );
00348 }
00349 
00350 QString cmcDatabase::getLastID
00351 (
00352   const QString & category,
00353   const QString & field,
00354   const QString & filter
00355 
00356 )
00357 {
00358   QString retVal;
00359 
00360   /*
00361   ** Get a cursor on the category
00362   **
00363   */
00364   cmcCursor * cursor = getCursor( category );
00365 
00366   /*
00367   ** If we can't get a cursor, then there's nothing to do.
00368   **
00369   */
00370   if( cursor )
00371   {
00372     /*
00373     ** If a filter has been requested, then apply it.
00374     **
00375     */
00376     if( filter != "" )
00377       cursor-> setFilter( filter );
00378 
00379     /*
00380     ** If there aren't any rows in the cursor then there's
00381     **  nothing to do.
00382     **
00383     */
00384     if( cursor-> rowCount() )
00385     {
00386       /*
00387       ** Set the field as the only column.  Set the sort 
00388       **  on that column to descending, so that the last
00389       **  ID value used is the first record.
00390       **
00391       */
00392       cursor-> setColumn( field );
00393       cursor-> setSort( field + ",Descending" );
00394 
00395       /*
00396       ** Get a query rowset.
00397       **
00398       */
00399       cmcRowSet * rs = cursor-> getQueryRowSet(1);
00400 
00401       /*
00402       ** If we are unable to get a query rowset then
00403       **  there's nothing to do.
00404       **
00405       */
00406       if( rs )
00407       {
00408         /*
00409         ** Get the ID value from the one and only row.
00410         **
00411         */
00412         retVal = rs-> getRowValue( 0,0 );
00413         delete rs;
00414       }
00415     }
00416 
00417     delete cursor;
00418 
00419   }
00420 
00421   return( retVal );
00422   
00423 }
00424 
00425 
00426 } // endnamespace cmcDatabaseApi
00427 
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties




~ ~ ~ ~ ~ ~
Source Code without Comments is like a Cranberry Garland
without the berries. Comment your Code!
 
Commence Database User Support Group Forum
http://newsgroup.showoff-db.org/
~ ~ ~ ~ ~ ~
Author: Mark Petryk
Lorimark Solutions, LLC
mark@lorimarksolutions.com