Embarcadero_LLama, mit Docker, lokal, via Docker Image. Läuft überall, mehr Schnitzel-Schnipsel-KI, nichts wirklich brauchbares. Trainiert über SDK-MSDN, gut ist es. Für Delphi oder C++Builder. Ja es ließt einen Quellcode runter für die "Dokumentation" oder Analyse, aber eher zäh und nicht wirklich zielführend. Kann man eigentlich vergessen. Wenn man nicht MSDN Online, aka jetzt Microsoft Learn abgrasen will via Suchmaschine, kann sich was erstellen lassen für den Programmanfang. Anfrage: Create a c++ ole db example with oledbcommand. Weitere Anfragen sind noch gefolgt wie oledbtable, SQL Server, alles unvollständig und wenig hilfreich. Das komplexe ist nämlich das Erstellen des Ausgabepuffers. Fehlt komplett. It looks like you are interested in using OLE DB with C++. OLE DB (Object Linking and Embedding, Database) is a set of COM-based interfaces that allow C++ programs to access data from a variety of sources in a uniform manner. Here’s a very basic overview to get you started: ### 1. Include Headers and Link Libraries You'll need to include the OLE DB headers and link against the appropriate libraries: ```cpp #include #include #include ``` Link against `ole32.lib` and `oleaut32.lib`. ### 2. Initialize COM Before using OLE DB, initialize COM: ```cpp CoInitialize(NULL); ``` ### 3. Create Data Source Object You typically use `CoCreateInstance` to create a data source object, such as for SQL Server: ```cpp IDBInitialize* pIDBInitialize = NULL; HRESULT hr = CoCreateInstance(CLSID_SQLOLEDB, // OLE DB provider CLSID NULL, CLSCTX_INPROC_SERVER, IID_IDBInitialize, (void**)&pIDBInitialize); ``` ### 4. Set Initialization Properties OLE DB uses property sets to configure the connection (such as username, password, data source): ```cpp DBPROP rgdbprop[3]; DBPROPSET rgdbpropset[1]; // ...set up properties... ``` ### 5. Initialize and Connect ```cpp hr = pIDBInitialize->Initialize(); ``` ### 6. Create a Session, Command, and Execute - Use `IDBInitialize` to create a session (`IDBCreateSession`) - Use the session to create a command object (`IDBCreateCommand`) - Set the command text (SQL) and execute it ### 7. Release Resources Release all COM objects and uninitialize COM: ```cpp pIDBInitialize->Release(); CoUninitialize(); ``` --- ### Example Resource For a complete example, Microsoft’s [official OLE DB Programmer's Guide](https://learn.microsoft.com/en-us/sql/ado/guide/data/oledb-programmers-reference?view=sql-server-ver16) is a good resource. --- #### Note - OLE DB is a lower-level API. For simpler development, consider using ODBC, ADO, or higher-level libraries like SOCI or SQLAPI++ in modern C++. - If you have a specific database (e.g., SQL Server, Oracle), the provider will be different (e.g., `CLSID_SQLOLEDB` for SQL Server). If you want a full code example or have a specific use case (database type, platform), let me know! #include #include #include #pragma comment(lib, "ole32.lib") int main() { HRESULT hr; CoInitialize(NULL); // Initialize data source object IDBInitialize* pIDBInitialize = NULL; hr = CoCreateInstance(CLSID_SQLOLEDB, NULL, CLSCTX_INPROC_SERVER, IID_IDBInitialize, (void**)&pIDBInitialize); // Set initialization properties (connection string as DBPROP) // ... (usually you use Data Source, Initial Catalog, User ID, Password, etc.) // Initialize the data source hr = pIDBInitialize->Initialize(); // Create a session IDBCreateSession* pIDBCreateSession = NULL; hr = pIDBInitialize->QueryInterface(IID_IDBCreateSession, (void**)&pIDBCreateSession); IUnknown* pSession = NULL; hr = pIDBCreateSession->CreateSession(NULL, IID_IOpenRowset, (IUnknown**)&pSession); // Create a command object IDBCreateCommand* pIDBCreateCommand = NULL; hr = pSession->QueryInterface(IID_IDBCreateCommand, (void**)&pIDBCreateCommand); ICommandText* pICommandText = NULL; hr = pIDBCreateCommand->CreateCommand(NULL, IID_ICommandText, (IUnknown**)&pICommandText); // Set the command text hr = pICommandText->SetCommandText(DBGUID_DEFAULT, L"SELECT * FROM MyTable"); // Execute the command IMultipleResults* pIMultipleResults = NULL; hr = pICommandText->Execute(NULL, IID_IMultipleResults, NULL, NULL, (IUnknown**)&pIMultipleResults); // Cleanup if (pIMultipleResults) pIMultipleResults->Release(); if (pICommandText) pICommandText->Release(); if (pIDBCreateCommand) pIDBCreateCommand->Release(); if (pSession) pSession->Release(); if (pIDBCreateSession) pIDBCreateSession->Release(); if (pIDBInitialize) pIDBInitialize->Release(); CoUninitialize(); return 0; } TCHAR szInitStr[1024];// Initialize connection string TCHAR pszServerName[64] = _T("localhost\\SQLEXPRESS");//Data source TCHAR pszDataSource[64] = _T("master");//Database name // Assemble connection string // I've created a database named master in SQLEXPRESS service. swprintf( szInitStr, 1024, _T("Provider=SQLNCLI11;Data Source=%s;Initial Catalog=%s;Integrated Security=SSPI"), pszServerName, pszDataSource); CComPtr m_pIDataInitialize;// OleDb data COM Interface // Call CoCreateInstance to create IDataInitialize instance HRESULT hResult = ::CoCreateInstance( CLSID_MSDAINITIALIZE, NULL, CLSCTX_INPROC_SERVER, IID_IDataInitialize, ( void** )&m_pIDataInitialize ); if( FAILED( hResult ) ) return E_FAIL; // Call IDataInitialize GetDataSource method to acquire IDBInitialize instance hResult = m_pIDataInitialize->GetDataSource( NULL, CLSCTX_INPROC_SERVER, ( LPCOLESTR )szInitStr, IID_IDBInitialize, ( IUnknown** )&pIDBInitialize); if( FAILED( hResult ) ) return E_FAIL; // Call IDBInitialize Initialize method to initialize this instance hResult = pIDBInitialize->Initialize(); if( FAILED( hResult ) ) return E_FAIL; // Use interface IDBCreateSession to create session instance hResult = pIDBInitialize->QueryInterface( IID_IDBCreateSession, ( void** )&pSession ); if( FAILED( hResult ) ) return E_FAIL; // Call CreateSession method to create createcommand instance CComPtr m_pIDBCreateCommand; hResult = pSession->CreateSession( NULL, IID_IDBCreateCommand, (IUnknown**)&m_pIDBCreateCommand ); if ( FAILED( hResult ) ) return E_FAIL; // Commandtext interface hResult = m_pIDBCreateCommand->CreateCommand(NULL,IID_ICommandText, (IUnknown**)&pICommandText); if ( FAILED( hResult ) ) return E_FAIL; return S_OK;