bcp_readfmt
Gilt für:SQL Server
Azure SQL-Datenbank
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
Liest eine Datendatei-Formatdefinition aus der angegebenen Formatdatei.
Syntax
RETCODE bcp_readfmt (
HDBC hdbc,
LPCTSTR szFormatFile);
Unicode- und ANSI-Namen:
- bcp_readfmtA (ANSI)
- bcp_readfmtW (Unicode)
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.
Hinweise
Nachdem bcp_readfmt die Formatwerte gelesen hat, werden die entsprechenden Aufrufe an bcp_columns und bcp_colfmt. Es ist nicht erforderlich, eine Formatdatei zu analysieren und diese Aufrufe zu tätigen.
Rufen Sie bcp_writefmt auf, um eine Formatdatei beizubehalten. Aufrufe von bcp_readfmt können auf gespeicherte Formate verweisen. Weitere Informationen finden Sie unter bcp_init.
Alternativ kann das Hilfsprogramm für Massenkopien (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).For more information about the bcp utility and the structure of bcp data format files, see Bulk Import and Export of Data (SQL Server).For more information about the structure of bcp data format files, see Bulk Import and Export of Data (SQL Server).
Der BCPDELAYREADFMT-Wert des eOption-Parameters von bcp_control ändert das Verhalten von bcp_readfmt.
Hinweis
Die Formatdatei muss von Version 4.2 oder höher des hilfsprogramms bcp erstellt werden.
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.