Accueil
Rechercher:
sur developpez.com sur les forums
Forums | Tutoriels | F.A.Q's | Participez | Hébergement | Contacts
Club Emploi Blogs   TV   Dév. Web PHP XML Python Autres 2D-3D-Jeux Sécurité Windows Linux PC Mac
Accueil Conception Java DotNET Visual Basic  C  C++ Delphi MS-Office SQL & SGBD Oracle  4D  Business Intelligence
Accueil Access Forum Access F.A.Q Access F.A.Q VBA Tutoriels Sources Outils Livres Access TV Access 2007

Fonctionnalités recordset ADO

Date de publication : 28.11.2007

Par Christophe Le Fustec (http://ledzeppii.developpez.com)
 

Fonctionnalités d'un recordset ADO en fonction du fournisseur de données (Jet ou SQL Serveur) et des options d'ouverture

I. Introduction
II. Principe du test
III. Résultats pour Access
Ouverture d'une table par son nom
Ouverture d'une requête par son nom
Ouverture d'une instruction SQL SELECT
IV. Résultats pour SQL Serveur
Ouverture d'une table par son nom
Ouverture d'une Vue par son nom
Ouverture d'une procédure stockée par son nom
Ouverture d'une instruction SQL SELECT
V. Conclusion
Remerciements


I. Introduction

ADO offre un grand nombre d'options lors de l'ouverture d'un recordset. Type de curseur, type de verrouillage, curseur côté serveur ou côté client.
En fonction du fournisseur de données, toutes ces options ne sont pas supportées.
Cela peut se traduire par une erreur d'exécution ou par un recordset dont les fonctionnalités ne correspondent pas à celles choisies lors de l'ouverture.
En effet, si le fournisseur de données ne supporte le type de curseur demandé il ouvrira un recordset avec un curseur d'un autre type. De ce fait les fonctionnalités du curseur obtenu ne sont pas forcément celles que l'on attendait.
J'ai donc réalisé un petit programme de test pour déterminer les options valides et les fonctionnalités du recordset ouvert.


II. Principe du test


Création d'une connexion ADO faisant référence au fournisseur de données.

Microsoft.Jet.OLEDB.4.0 pour Access
			
Dim oConn As ADODB.Connection, oRS As ADODB.Recordset

Set oConn = New ADODB.Connection
oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=" & CurrentProject.FullName & ";"
oConn.Open
			
SQLOLEDB pour SQL Serveur
			
Dim oConn As ADODB.Connection, oRS As ADODB.Recordset

Set oConn = New ADODB.Connection
oConn.ConnectionString = "Provider=SQLOLEDB;DATA SOURCE=NomDuServeur;" & _
      "INITIAL CATALOG=NomBDD;" & _
      "INTEGRATED SECURITY=SSPI;"
oConn.Open
			

Ouverture d'un recordset ADO avec différents types de curseur, de verrouillage, d'option.

Curseur côté Serveur

Set oRS = New ADODB.Recordset
oRS.CursorLocation = adUseServer
			
Curseur côté Client

Set oRS = New ADODB.Recordset
oRS.CursorLocation = adUseClient
			
Ouverture

oRS.Open SCE, oConn, CursorType, LockType, Option
			
SCE peut être un nom de table, un nom de requête (de Vue pour SQL Serveur), une instruction SQL SELECT, une procédure stockée (SQL serveur).
Dans tous les cas, le jeu d'enregistrements peut être mis à jour (Ajout, Modification, Suppression).
La table possède une clé primaire. La requête (ou la Vue SQL Serveur) est une requête de sélection sur la table avec clé primaire.
La procédure stockée et l'instruction SQL ont le même code SQL que la requête.
CursorType pourra être une des constantes ADO adOpenForwardOnly, adOpenKeyset, adOpenDynamic, adOpenStatic
LockType pourra être une des constantes ADO adLockReadOnly, adLockPessimistic, adLockOptimistic, adLockBatchOptimistic
Option pourra être une des constantes ADO adCmdText, adCmdTable, adCmdTableDirect, adCmdStoredProc


Vérification des fonctionnalités du recordset si il a pu être ouvert

  1. A l'aide de la méthode Supports
  2. Lecture des propriétés RecordCount, AbsolutePosition
    Si la valeur est -1 cette fonctionnalité n'est pas supportée
  3. Lecture des propriétés CursorType, LockType
    Permet de vérifier si le recordset obtenu est conforme à celui qui a été demandé

Combinaisons non testées.

Certains type de curseur/verrouillage ne sont pas possibles.
- Le verrouillage adLockPessimistic n'existe pas pour un curseur côté client.
- Le verrouillage adLockBatchOptimistic n'existe pas côté serveur.


III. Résultats pour Access


Ouverture d'une table par son nom

SCE est un nom de table.

Côté Serveur

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenForwardOnly adLockReadOnly adCmdTable                      
adOpenKeyset adLockReadOnly adCmdTable                      
adOpenKeyset adLockReadOnly adCmdTableDirect                      
adOpenKeyset adLockPessimistic adCmdTable                      
adOpenKeyset adLockPessimistic adCmdTableDirect                      
adOpenKeyset adLockOptimistic adCmdTable                      
adOpenKeyset adLockOptimistic adCmdTableDirect                      
adOpenStatic adLockReadOnly adCmdTable                      

Côté Client

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenStatic adLockReadOnly adCmdTable                      
adOpenStatic adLockReadOnly adCmdTableDirect                      
adOpenStatic adLockOptimistic adCmdTable                      
adOpenStatic adLockOptimistic adCmdTableDirect                      
adOpenStatic adLockBatchOptimistic adCmdTable                      
adOpenStatic adLockBatchOptimistic adCmdTableDirect                      

Ouverture d'une requête par son nom

SCE est un nom de requête.

Côté Serveur

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenForwardOnly adLockReadOnly adCmdTable                      
adOpenForwardOnly adLockReadOnly adCmdTableDirect                      
adOpenKeyset adLockReadOnly adCmdTable                      
adOpenKeyset adLockReadOnly adCmdTableDirect                      
adOpenKeyset adLockPessimistic adCmdTable                      
adOpenKeyset adLockPessimistic adCmdTableDirect                      
adOpenKeyset adLockOptimistic adCmdTable                      
adOpenKeyset adLockOptimistic adCmdTableDirect                      
adOpenStatic adLockReadOnly adCmdTable                      
adOpenStatic adLockReadOnly adCmdTableDirect                      

Côté Client

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenStatic adLockReadOnly adCmdTable                      
adOpenStatic adLockReadOnly adCmdTableDirect                      
adOpenStatic adLockOptimistic adCmdTable                      
adOpenStatic adLockOptimistic adCmdTableDirect                      
adOpenStatic adLockBatchOptimistic adCmdTable                      
adOpenStatic adLockBatchOptimistic adCmdTableDirect                      

Ouverture d'une instruction SQL SELECT

SCE est une instruction SQL SELECT.

Côté Serveur

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenForwardOnly adLockReadOnly adCmdText                      
adOpenForwardOnly adLockReadOnly adCmdTableDirect                      
adOpenKeyset adLockReadOnly adCmdText                      
adOpenKeyset adLockReadOnly adCmdTableDirect                      
adOpenKeyset adLockPessimistic adCmdText                      
adOpenKeyset adLockPessimistic adCmdTableDirect                      
adOpenKeyset adLockOptimistic adCmdText                      
adOpenKeyset adLockOptimistic adCmdTableDirect                      
adOpenStatic adLockReadOnly adCmdText                      
adOpenStatic adLockReadOnly adCmdTableDirect                      

Côté Client

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenStatic adLockReadOnly adCmdText                      
adOpenStatic adLockReadOnly adCmdTableDirect                      
adOpenStatic adLockOptimistic adCmdText                      
adOpenStatic adLockOptimistic adCmdTableDirect                      
adOpenStatic adLockBatchOptimistic adCmdText                      
adOpenStatic adLockBatchOptimistic adCmdTableDirect                      

IV. Résultats pour SQL Serveur


Ouverture d'une table par son nom

SCE est un nom de table.

Côté Serveur

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenForwardOnly adLockReadOnly adCmdTable                      
adOpenForwardOnly adLockReadOnly adCmdTableDirect                      
adOpenForwardOnly adLockPessimistic adCmdTable                      
adOpenForwardOnly adLockPessimistic adCmdTableDirect                      
adOpenForwardOnly adLockOptimistic adCmdTable                      
adOpenForwardOnly adLockOptimistic adCmdTableDirect                      
adOpenKeyset adLockReadOnly adCmdTable                      
adOpenKeyset adLockReadOnly adCmdTableDirect                      
adOpenKeyset adLockPessimistic adCmdTable                      
adOpenKeyset adLockPessimistic adCmdTableDirect                      
adOpenKeyset adLockOptimistic adCmdTable                      
adOpenKeyset adLockOptimistic adCmdTableDirect                      
adOpenDynamic adLockReadOnly adCmdTable                      
adOpenDynamic adLockReadOnly adCmdTableDirect                      
adOpenDynamic adLockPessimistic adCmdTable                      
adOpenDynamic adLockPessimistic adCmdTableDirect                      
adOpenDynamic adLockOptimistic adCmdTable                      
adOpenDynamic adLockOptimistic adCmdTableDirect                      
adOpenStatic adLockReadOnly adCmdTable                      
adOpenStatic adLockReadOnly adCmdTableDirect                      

Côté Client

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenStatic adLockReadOnly adCmdTable                      
adOpenStatic adLockReadOnly adCmdTableDirect                      
adOpenStatic adLockOptimistic adCmdTable                      
adOpenStatic adLockOptimistic adCmdTableDirect                      
adOpenStatic adLockBatchOptimistic adCmdTable                      
adOpenStatic adLockBatchOptimistic adCmdTableDirect                      

Ouverture d'une Vue par son nom

SCE est un nom de Vue.

Côté Serveur

CursorType LockType Option Update
AddNew
Delete
Find Index
Seek
Move
Previous
RecCount AbsPos BookMark UpdateBatch Approx
Position
HoldRecords Resync
adOpenForwardOnly adLockReadOnly adCmdTable