Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
SQLEXEC, resultcursor and datasession
Message
De
18/06/2007 21:56:07
 
 
À
18/06/2007 18:36:46
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01234140
Message ID:
01234151
Vues:
9
> Cursor 'curSecondDefects' is getting created in the form's datasession

The culprit is that calling the form's method...
ThisForm.mExecuteSqlCommand(lcSql, 'curSecondDefects', '')
.. during the execution of mExecuteSqlCommand the form's datasession is current.

You need something like this (lots of stuff left out for brevity):
   loSession = create('session')
   Thisform.mExecSQL_DS( "select ..from..", loSession.DataSessionID

...
* in the form class:
function mExecSQL_DS(  cSQLCommand, nDataSessionID )
  local nSaveDataSessionID
  nSaveDataSessionID = set("datasession")
  set datasession to (m.nDataSessionID)

  sqlexec( ..., m.cSQLCommand, ... )

  set datasession to (m.nSaveDataSessionID)
  return
endfunc
Saving and restoring the current datasession is important because the current datasession on exit from a method will change the object's datasession. You possibly should consider a TRY .. FINALLY block or some equivalent around the code where the datasession is switched. Getting into the pros and cons of this is beyond the scope of this message!

Note, object methods switch datasession on entry. Standalone procedures/functions don't. So another approaach might be something like this:
* In globals.prg or whatever
function ExecSQL( oForm, cSQL )
  sqlexec( oForm.ConnectionHandle, m.cSQL )
endfunc
Again, plus all the stuff a generic function should have, return values, parameters, error handling
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform