Identificativo articolo: 214854 - Ultima modifica: venerdì 5 dicembre 2003 - Revisione: 4.1

INFORMAZIONI: Migliorare ODBC DataType mapping con Jet 4.0

Suggerimento di sistemaIl presente articolo fa riferimento a un sistema operativo diverso da quello in uso. Il contenuto dell'articolo che potrebbe non essere relativo al sistema in uso è disabilitato.

In questa pagina

Espandi tutto | Chiudi tutto

Sommario

Microsoft Data Access Components (MDAC) versione 2.1 installa il modulo di gestione di database Microsoft Jet 4.0. Il modulo di gestione di database Microsoft Jet viene utilizzato il driver ODBC di Microsoft Access, il Provider Microsoft Jet OLE DB e Microsoft Data Access Objects (DAO) per fornire l'accesso a database in formato di Microsoft Access, così come origini dati diverse ISAM di Jet e ODBC.

Ad esempio, è possibile utilizzare ActiveX Data Objects (ADO), Remote Data Objects (RDO) o DAO (Data Access Objects) per accedere a Microsoft Jet utilizzando uno dei metodi descritti di seguito:

   ADO -> OLE DB -> Jet OLE DB Provider -> Jet 
   ADO -> OLE DB -> MSDASQL -> ODBC -> Access ODBC Driver -> Jet
   DAO -> Jet
   RDO -> ODBC -> Access ODBC Driver -> Jet
				

Nota : "MSDASQL" sopra riportata è il provider di ODBC di Microsoft per OLE DB, che è un provider OLE DB che può comunicare con i driver ODBC (e pertanto consentire ADO comunicare con qualsiasi driver di ODBC).

Microsoft Jet stesso consente l'accesso le origini dati seguenti:

   Jet -> ODBC -> Non-ODBC Desktop Driver -> Any non-Jet data source
   Jet -> Jet ISAM Driver -> Jet ISAM data source
   Jet -> Microsoft Access database
				

Nota : un valore "ODBC Desktop driver" è qualsiasi dei driver Microsoft ODBC che utilizza internamente di Microsoft Jet per accedere a un'origine dati. Utilizzando uno qualsiasi dei driver ODBC Desktop da Jet non è supportata. Ad esempio, utilizzando il driver ODBC di Microsoft Excel non supportata da Jet. Jet supporta utilizza il driver di ISAM di Microsoft Excel, può essere utilizzato invece il driver ISAM di Excel in questo caso specifico. È possibile verificare se il driver ODBC è un driver di ODBC Desktop esaminando il nome del file di driver nel Pannello di controllo Amministratore ODBC nella sezione driver. Se il nome di file del driver è ODBCJT32.dll, il driver è un driver di ODBC Desktop e non è supportato per utilizzare con Jet tramite ODBC.

Microsoft Jet 4.0 fornisce un insieme di migliorata di tipo di dati ODBC per Jet i mapping di tipo di dati e il motore di database Microsoft Jet 3.5. Ad esempio, mappe di Jet 4.0 SQL_DECIMAL e campi di tipo SQL_NUMERIC su dati di Jet 4.0 nuovi tipo denominato Decimal, fornire un mapping di più da vicino il tipo di dati ODBC effettivo. Il tipo di dati decimale di Jet 4.0 è un dati numerico esatto tipo di (denominato valore intero scalare compreso) che contiene valori da (10 ^ 28) -1 e-(10^28). Con il tipo di dati Decimal, è possibile definire campi con precisione e scala da (1,0) fino a (28,28). Jet 3.5 associato campi SQL_DECIMAL e SQL_NUMERIC al tipo di dati numerici di Jet più vicino seconda la precisione e la scala del campo ODBC, quale tipo di dati numerici di Jet, ad esempio due in determinati risultati casi nel mapping a un valore esatto non (Mobile punto).

Informazioni

Prima che il modulo di gestione di database Microsoft Jet relativi tipi di dati viene associato una tabella ODBC, chiama la funzione API ODBC SQLColumns per raccogliere informazioni sul tipo di dati ODBC, precisione e scala per ogni colonna della tabella. Queste informazioni di tipo ODBC Jet corrisponde a ogni tipo di dati ODBC con il tipo di dati Jet appropriato. In questo articolo sono riepilogati il tipo di dati ODBC per il mapping del tipo di dati Jet utilizzati dai Jet 3.5 e in Jet 4.0.

Nota: Il tipo di dati Jet LongBinary è elencato come "Ole Object" nell'interfaccia utente di progettazione tabella Microsoft Access.

ODBC per Jet Data Type Mappings

ODBC SQL Type     Precision  Scale Jet 3.5 Type Jet 40 Type
-----------------------------------------------------------
SQL_BIT           N/A        N/A   Boolean      Boolean
SQL_TINYINT       N/A        N/A   Byte*        Byte*
SQL_TINYINT       N/A        N/A   Integer*     Integer*
SQL_SMALLINT      N/A        N/A   Integer      Integer
SQL_INTEGER       N/A        N/A   Long         Long
SQL_REAL          N/A        N/A   Single       Single
SQL_FLOAT         N/A        N/A   Double       Double
SQL_DOUBLE        N/A        N/A   Double       Double
SQL_DECIMAL       0 To 4     0     Integer      Decimal
SQL_DECIMAL       5 To 9     0     Long         Decimal
SQL_DECIMAL       10 to 15   0     Double       Decimal
SQL_DECIMAL       <=15       >0    Double       Decimal
SQL_DECIMAL       16 To 28   N/A   Text         Decimal
SQL_DECIMAL       > 28       N/A   Text         Text
SQL_NUMERIC       0 To 4     0     Integer      Decimal
SQL_NUMERIC       5 To 9     0     Long         Decimal
SQL_NUMERIC       10 to 15   0     Double       Decimal
SQL_NUMERIC       <=15       >0    Double       Decimal
SQL_NUMERIC       16 To 28   N/A   Text         Decimal
SQL_NUMERIC       > 28       N/A   Text         Text
SQL_CHAR          <= 255     N/A   Text         Text
SQL_CHAR          > 255      N/A   Memo         Memo
SQL_VARCHAR       <= 255     N/A   Text         Text
SQL_VARCHAR       > 255      N/A   Memo         Memo
SQL_LONGVARCHAR   N/A        N/A   Memo         Memo
SQL_WCHAR         <= 255     N/A   Unsupported  Text
SQL_WCHAR         > 255      N/A   Unsupported  Memo
SQL_WVARCHAR      <= 255     N/A   Unsupported  Text
SQL_WVARCHAR      > 255      N/A   Unsupported  Memo
SQL_WLONGVARCHAR  N/A        N/A   Unsupported  Memo
SQL_DATE          N/A        N/A   DateTime     DateTime
SQL_TIME          N/A        N/A   DateTime     DateTime
SQL_TIMESTAMP     N/A        N/A   DateTime     DateTime
SQL_BINARY        <=255      N/A   Binary       Binary
SQL_BINARY        256 To 510 N/A   LongBinary   Binary
SQL_BINARY        > 510      N/A   LongBinary   LongBinary
SQL_VARBINARY     <=255      N/A   Binary       Binary
SQL_VARBINARY     256 To 510 N/A   LongBinary   Binary
SQL_VARBINARY     > 510      N/A   LongBinary   LongBinary
SQL_LONGVARBINARY N/A        N/A   LongBinary   LongBinary
SQL_GUID          N/A        N/A   Text         Guid

* An unsigned SQL_TINYINT maps to a Jet Byte, a signed SQL_TINYINT
  maps to an Jet Integer. 
				

Speciale ODBC per Jet Data Type Mappings per SQL Server

Se Microsoft Jet è comunicare con il driver ODBC di Microsoft SQL Server, quindi si verificano i mapping dei seguenti tipi di dati aggiuntivi:
ODBC SQL Type     Precision  Scale Jet 3.5 Type Jet 40 Type
-----------------------------------------------------------
SQL_DECIMAL       10         4     Currency     Currency

SQL_DECIMAL       19         4     Currency     Currency
SQL_NUMERIC       10         4     Currency     Currency
SQL_NUMERIC       19         4     Currency     Currency
				

Codice per il mapping del tipo di dati di verifica

Nell'esempio di codice riportato di seguito consente di verificare la maggior parte dei mapping delle tabelle sopra. Eseguire il codice utilizzando DAO 3.5 e DAO 3.6 (ottenuto con Office 2000) per verificare i mapping di tipo di dati Jet 3.5 e in Jet 4.0, rispettivamente.

Nota: Il codice richiede un server di database Microsoft SQL Server 7.0, è necessario modificare la stringa di connessione se il database di SQL Server si trova su un computer diverso (modificare il SERVER=(Local); token su SERVER = Nome Server;).
   Option Explicit

   ' Various constant strings.
   Const strConnect = "ODBC;Driver=SQL Server;SERVER=(Local);" & _
      "DATABASE=Pubs;UID=sa;PWD=;"
   Const strSelectSQL = "select * from tmpAllTypes"
   Const strDropTableSQL = "drop table tmpAllTypes"
   ' Outputs a listing of ODBC -> Jet Data Type mappings using a
   ' SQL Server 7.0 table as the data source.
   Sub ODBCJetMapTest()
      Dim eng As New DAO.DBEngine
      Dim qd As DAO.QueryDef
      Dim db As DAO.Database
      Dim rs As DAO.Recordset
      Dim f As DAO.Field
      Dim strSQL As String

      ' Verify DAO version used.
      ' Reference "Microsoft DAO 3.51 Object Library" to see 
      ' Jet 3.5 mappings or "Microsoft DAO 3.6 Object Library"
      ' to view Jet 4.0 ODBC mappings.
      Debug.Print "ODBCJetMapTest is using DAO version " & _
         eng.Version & "."

      ' Open SQL Server database connection.
      Set db = eng.OpenDatabase("", False, False, strConnect)

      ' Verify SQL Server version.
      Set qd = db.CreateQueryDef("")
      qd.Connect = strConnect
      qd.sql = "exec sp_server_info 500"
      Set rs = qd.OpenRecordset()
      Debug.Print "SQL Server version is " & _
         rs.Fields("attribute_value") & _
         " (version 7.X or greater required)."
      rs.Close

      ' Drop and re-create test table.
      On Error Resume Next
      db.Execute strDropTableSQL, dbSQLPassThrough
      On Error GoTo 0

      ' Build our create table SQL.
      strSQL = "CREATE TABLE tmpAllTypes("

      ' Common numeric mappings.
      AddField strSQL, "SQL_BIT", "bit", Empty
      AddField strSQL, "SQL_TINYINT", "tinyint", Empty
      AddField strSQL, "SQL_SMALLINT", "smallint", Empty
      AddField strSQL, "SQL_INTEGER", "int", Empty
      AddField strSQL, "SQL_REAL", "real", Empty
      AddField strSQL, "SQL_FLOAT", "float", Empty

      ' Decimal mappings.
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(4, 0)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(5, 0)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(9, 0)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(10, 0)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(15, 0)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(16, 0)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(28, 0)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(4, 1)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(5, 1)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(9, 1)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(10, 1)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(15, 1)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(16, 1)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(28, 1)

      ' SQL Server specific mappings -> Currency.
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(10, 4)
      AddField strSQL, "SQL_DECIMAL", "decimal", Array(19, 4)

      ' Numeric mappings.
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(4, 0)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(5, 0)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(9, 0)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(10, 0)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(15, 0)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(16, 0)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(28, 0)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(4, 1)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(5, 1)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(9, 1)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(10, 1)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(15, 1)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(16, 1)
      AddField strSQL, "SQL_NUMERIC", "numeric", Array(28, 1)

      ' Character mappings.
      AddField strSQL, "SQL_CHAR", "char", Array(255)
      AddField strSQL, "SQL_CHAR", "char", Array(256)
      AddField strSQL, "SQL_VARCHAR", "varchar", Array(255)
      AddField strSQL, "SQL_VARCHAR", "varchar", Array(256)
      AddField strSQL, "SQL_WCHAR", "nchar", Array(255)
      AddField strSQL, "SQL_WCHAR", "nchar", Array(256)
      AddField strSQL, "SQL_WVARCHAR", "nvarchar", Array(255)
      AddField strSQL, "SQL_WVARCHAR", "nvarchar", Array(256)

      ' Binary mappings.
      AddField strSQL, "SQL_BINARY", "binary", Array(255)
      AddField strSQL, "SQL_BINARY", "binary", Array(256)
      AddField strSQL, "SQL_BINARY", "binary", Array(510)
      AddField strSQL, "SQL_BINARY", "binary", Array(511)
      AddField strSQL, "SQL_LONGVARBINARY", "image", Empty

      ' Date mappings.
      AddField strSQL, "SQL_TIMESTAMP", "datetime", Empty
      
      ' Specialized mappings.
      AddField strSQL, "SQL_GUID", "uniqueidentifier", Empty, ")"

      ' Create table.
      db.Execute strSQL, dbSQLPassThrough

      ' Open recordset on table and dump out ODBC -> Jet mappings.
      Set rs = db.OpenRecordset(strSelectSQL, dbOpenForwardOnly, _
         dbReadOnly, dbReadOnly)
      For Each f In rs.Fields
         Debug.Print f.Name & " maps to " & GetJetTypeString(f.Type) & "."
      Next f
      rs.Close
      On Error Resume Next
      db.Execute strDropTableSQL, dbSQLPassThrough
      On Error GoTo 0
      db.Close

   End Sub
   ' Function to return string constant for Jet Type.
   Function GetJetTypeString(lngDataTypeEnum As Long) As String
      Dim strReturn As String
      strReturn = "UNKNOWN"
      Select Case lngDataTypeEnum
         Case dbBigInt: strReturn = "dbBigInt"
         Case dbBinary: strReturn = "dbBinary"
         Case dbBoolean: strReturn = "dbBoolean"
         Case dbByte: strReturn = "dbByte"
         Case dbChar: strReturn = "dbChar"
         Case dbCurrency: strReturn = "dbCurrency"
         Case dbDate: strReturn = "dbDate"
         Case dbDecimal: strReturn = "dbDecimal"
         Case dbDouble: strReturn = "dbDouble"
         Case dbFloat: strReturn = "dbFloat"
         Case dbGUID: strReturn = "dbGUID"
         Case dbInteger: strReturn = "dbInteger"
         Case dbLong: strReturn = "dbLong"
         Case dbLongBinary: strReturn = "dbLongBinary"
         Case dbMemo: strReturn = "dbMemo"
         Case dbNumeric: strReturn = "dbNumeric"
         Case dbSingle: strReturn = "dbSingle"
         Case dbText: strReturn = "dbText"
         Case dbTime: strReturn = "dbTime"
         Case dbTimeStamp: strReturn = "dbTimeStamp"
         Case dbVarBinary: strReturn = "dbVarBinary"
      End Select
      GetJetTypeString = strReturn
   End Function
   ' Function to append a SQL token to a SQL string.
   Sub AddField(sql As String, FieldName As String, SQLType As String, _
   PS As Variant, Optional Terminator As String = ",")
      If IsEmpty(PS) Then
         sql = sql & FieldName & " " & SQLType
      Else
         sql = sql & FieldName & "_" & Format(PS(0), "00")
         If UBound(PS) = 0 Then
            sql = sql & " " & SQLType
            sql = sql & "(" & PS(0) & ")"
         Else
            sql = sql & "_" & Format(PS(1), "00") & " " & SQLType
            sql = sql & "(" & PS(0) & "," & PS(1) & ")"
         End If
      End If
      sql = sql & Terminator
   End Sub
				

Riferimenti

Per ulteriori informazioni sul mapping dei tipo di dati Jet e ODBC, vedere il capitolo 9 "Sviluppo di applicazione client/server" della Guida del programmatore di Microsoft Jet Database , Second Edition.

Le informazioni in questo articolo si applicano a:
  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft OLE DB Provider for Jet 4.0
Chiavi: 
kbmt kbdatabase kbinfo kbjet kbprovider KB214854 KbMtit
Traduzione automatica articoliTraduzione automatica articoli
Il presente articolo è stato tradotto tramite il software di traduzione automatica di Microsoft e non da una persona. Microsoft offre sia articoli tradotti da persone fisiche sia articoli tradotti automaticamente da un software, in modo da rendere disponibili tutti gli articoli presenti nella nostra Knowledge Base nella lingua madre dell?utente. Tuttavia, un articolo tradotto in modo automatico non è sempre perfetto. Potrebbe contenere errori di sintassi, di grammatica o di utilizzo dei vocaboli, più o meno allo stesso modo di come una persona straniera potrebbe commettere degli errori parlando una lingua che non è la sua. Microsoft non è responsabile di alcuna imprecisione, errore o danno cagionato da qualsiasi traduzione non corretta dei contenuti o dell?utilizzo degli stessi fatto dai propri clienti. Microsoft, inoltre, aggiorna frequentemente il software di traduzione automatica.
Clicca qui per visualizzare la versione originale in inglese dell?articolo: 214854  (http://support.microsoft.com/kb/214854/en-us/ )
LE INFORMAZIONI CONTENUTE NELLA MICROSOFT KNOWLEDGE BASE SONO FORNITE SENZA GARANZIA DI ALCUN TIPO, IMPLICITA OD ESPLICITA, COMPRESA QUELLA RIGUARDO ALLA COMMERCIALIZZAZIONE E/O COMPATIBILITA' IN IMPIEGHI PARTICOLARI. L'UTENTE SI ASSUME L'INTERA RESPONSABILITA' PER L'UTILIZZO DI QUESTE INFORMAZIONI. IN NESSUN CASO MICROSOFT CORPORATION E I SUOI FORNITORI SI RENDONO RESPONSABILI PER DANNI DIRETTI, INDIRETTI O ACCIDENTALI CHE POSSANO PROVOCARE PERDITA DI DENARO O DI DATI, ANCHE SE MICROSOFT O I SUOI FORNITORI FOSSERO STATI AVVISATI. IL DOCUMENTO PUO' ESSERE COPIATO E DISTRIBUITO ALLE SEGUENTI CONDIZIONI: 1) IL TESTO DEVE ESSERE COPIATO INTEGRALMENTE E TUTTE LE PAGINE DEVONO ESSERE INCLUSE. 2) I PROGRAMMI SE PRESENTI, DEVONO ESSERE COPIATI SENZA MODIFICHE, 3) IL DOCUMENTO DEVE ESSERE DISTRIBUITO INTERAMENTE IN OGNI SUA PARTE. 4) IL DOCUMENTO NON PUO' ESSERE DISTRIBUITO A SCOPO DI LUCRO.