bcp_readfmt

Gilt für:SQL ServerAzure SQL-DatenbankAzure SQL Managed InstanceAzure Synapse AnalyticsAnalytics Platform System (PDW)

Liest eine Datendatei-Formatdefinition aus der angegebenen Formatdatei.

Syntax

  
RETCODE bcp_readfmt (  
        HDBC hdbc,  
        LPCTSTR szFormatFile);  

Argumente

hdbc
Das für den Massenkopiervorgang aktivierte ODBC-Verbindungshandle.

szFormatFile
Pfad und Dateiname der Datei, die die Formatwerte für die Datendatei enthält.

Gibt zurück

SUCCEED oder FAIL.

Bemerkungen

Nachdem bcp_readfmt die Formatwerte gelesen hat, werden die entsprechenden Aufrufe bcp_columns und bcp_colfmt. Sie brauchen keine Formatdatei zu analysieren, um diese Aufrufe zu tätigen.

Um eine Formatdatei beizubehalten, rufen Sie bcp_writefmt auf. Aufrufe von bcp_readfmt können auf gespeicherte Formate verweisen. Weitere Informationen finden Sie unter bcp_init.

Alternativ kann das Massenkopierprogramm (bcp) benutzerdefinierte Datenformate in Dateien speichern, auf die von bcp_readfmt verwiesen werden kann. Weitere Informationen zum bcp-Hilfsprogramm und zur Struktur von bcp-Datenformatdateien finden Sie unter Massenimport und -export von Daten (SQL Server).

Der BCPDELAYREADFMT-Wert des eOption-Parameters von bcp_control ändert das Verhalten von bcp_readfmt.

Hinweis

Die Formatdatei muss mit Version 4.2 oder höher des bcp-Hilfsprogramms erstellt worden sein.

Beispiel

// Variables like henv not specified.  
HDBC      hdbc;  
DBINT      nRowsProcessed;  
  
// Application initiation, get an ODBC environment handle, allocate the  
// hdbc, and so on.  
...   
  
// Enable bulk copy prior to connecting on allocated hdbc.  
SQLSetConnectAttr(hdbc, SQL_COPT_SS_BCP, (SQLPOINTER) SQL_BCP_ON,  
   SQL_IS_INTEGER);  
  
// Connect to the data source, return on error.  
if (!SQL_SUCCEEDED(SQLConnect(hdbc, _T("myDSN"), SQL_NTS,  
   _T("myUser"), SQL_NTS, _T("myPwd"), SQL_NTS)))  
   {  
   // Raise error and return.  
   return;  
   }  
  
// Initialize bulk copy.   
if (bcp_init(hdbc, _T("myTable"), _T("myData.csv"),  
   _T("myErrors"),    DB_IN) == FAIL)  
   {  
   // Raise error and return.  
   return;  
   }  
  
if (bcp_readfmt(hdbc, _T("myFmtFile.fmt")) == FAIL)  
   {  
   // Raise error and return.  
   return;  
   }  
  
if (bcp_exec(hdbc, &nRowsProcessed) == SUCCEED)  
   {  
   cout << nRowsProcessed << " rows copied to SQL Server\n";  
   }  
  
// Carry on.  

Weitere Informationen

Bulk Copy Functions