Commit 7491a7f1 authored by Alistair Leslie-Hughes's avatar Alistair Leslie-Hughes Committed by Alexandre Julliard

msdasql: Implement ICommandPrepare Prepare.

parent 1636530c
......@@ -43,7 +43,7 @@ DEFINE_GUID(DBPROPSET_DBINIT, 0xc8b522bc, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0
DEFINE_GUID(DBGUID_DEFAULT, 0xc8b521fb, 0x5cf3, 0x11ce, 0xad, 0xe5, 0x00, 0xaa, 0x00, 0x44, 0x77, 0x3d);
static void dump_sql_diag_records(SQLSMALLINT type, SQLHANDLE handle)
void dump_sql_diag_records(SQLSMALLINT type, SQLHANDLE handle)
{
SQLCHAR state[6], msg[SQL_MAX_MESSAGE_LENGTH];
SQLINTEGER native;
......@@ -611,7 +611,7 @@ static HRESULT WINAPI dbsess_CreateSession(IDBCreateSession *iface, IUnknown *ou
if (outer)
FIXME("outer currently not supported.\n");
hr = create_db_session(riid, &provider->MSDASQL_iface, (void**)session);
hr = create_db_session(riid, &provider->MSDASQL_iface, provider->hdbc, (void**)session);
return hr;
}
......
......@@ -16,4 +16,5 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
HRESULT create_db_session(REFIID riid, IUnknown *datasource, void **unk) DECLSPEC_HIDDEN;
HRESULT create_db_session(REFIID riid, IUnknown *datasource, HDBC hdbc, void **unk) DECLSPEC_HIDDEN;
void dump_sql_diag_records(SQLSMALLINT type, SQLHANDLE handle) DECLSPEC_HIDDEN;
......@@ -30,6 +30,7 @@
#include "msdasql.h"
#include "oledberr.h"
#include "sqlucode.h"
#include "msdasql_private.h"
......@@ -45,6 +46,8 @@ struct msdasql_session
LONG refs;
IUnknown *datasource;
HDBC hdbc;
};
static inline struct msdasql_session *impl_from_IUnknown( IUnknown *iface )
......@@ -305,6 +308,8 @@ struct command
LONG refs;
WCHAR *query;
IUnknown *session;
HDBC hdbc;
SQLHSTMT hstmt;
};
static inline struct command *impl_from_ICommandText( ICommandText *iface )
......@@ -424,6 +429,10 @@ static ULONG WINAPI command_Release(ICommandText *iface)
TRACE( "destroying %p\n", command );
if (command->session)
IUnknown_Release(command->session);
if (command->hstmt)
SQLFreeHandle(SQL_HANDLE_STMT, command->hstmt);
heap_free( command->query );
heap_free( command );
}
......@@ -1051,7 +1060,24 @@ static ULONG WINAPI commandprepare_Release(ICommandPrepare *iface)
static HRESULT WINAPI commandprepare_Prepare(ICommandPrepare *iface, ULONG runs)
{
struct command *command = impl_from_ICommandPrepare( iface );
RETCODE ret;
TRACE("%p, %u\n", command, runs);
if (!command->query)
return DB_E_NOCOMMAND;
if (command->hstmt)
SQLFreeHandle(SQL_HANDLE_STMT, command->hstmt);
SQLAllocHandle(SQL_HANDLE_STMT, command->hdbc, &command->hstmt);
ret = SQLPrepareW(command->hstmt, command->query, SQL_NTS);
if (ret != SQL_SUCCESS)
{
dump_sql_diag_records(SQL_HANDLE_STMT, command->hstmt);
return E_FAIL;
}
return S_OK;
}
......@@ -1147,6 +1173,8 @@ static HRESULT WINAPI createcommand_CreateCommand(IDBCreateCommand *iface, IUnkn
command->ICommandWithParameters_iface.lpVtbl = &command_with_params_vtbl;
command->refs = 1;
command->query = NULL;
command->hdbc = session->hdbc;
command->hstmt = NULL;
IUnknown_QueryInterface(&session->session_iface, &IID_IUnknown, (void**)&command->session);
......@@ -1163,7 +1191,7 @@ static const IDBCreateCommandVtbl createcommandVtbl =
createcommand_CreateCommand
};
HRESULT create_db_session(REFIID riid, IUnknown *datasource, void **unk)
HRESULT create_db_session(REFIID riid, IUnknown *datasource, HDBC hdbc, void **unk)
{
struct msdasql_session *session;
HRESULT hr;
......@@ -1179,6 +1207,7 @@ HRESULT create_db_session(REFIID riid, IUnknown *datasource, void **unk)
session->IDBCreateCommand_iface.lpVtbl = &createcommandVtbl;
IUnknown_QueryInterface(datasource, &IID_IUnknown, (void**)&session->datasource);
session->refs = 1;
session->hdbc = hdbc;
hr = IUnknown_QueryInterface(&session->session_iface, riid, unk);
IUnknown_Release(&session->session_iface);
......
......@@ -354,6 +354,7 @@ static void test_rowset_interfaces(IRowset *rowset, ICommandText *commandtext)
static void test_command_rowset(IUnknown *cmd)
{
ICommandText *command_text;
ICommandPrepare *commandprepare;
HRESULT hr;
IUnknown *unk = NULL;
IRowset *rowset;
......@@ -362,9 +363,22 @@ static void test_command_rowset(IUnknown *cmd)
hr = IUnknown_QueryInterface(cmd, &IID_ICommandText, (void**)&command_text);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IUnknown_QueryInterface(cmd, &IID_ICommandPrepare, (void**)&commandprepare);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = ICommandText_SetCommandText(command_text, &DBGUID_DEFAULT, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = ICommandPrepare_Prepare(commandprepare, 1);
ok(hr == DB_E_NOCOMMAND, "got 0x%08x\n", hr);
hr = ICommandText_SetCommandText(command_text, &DBGUID_DEFAULT, L"CREATE TABLE testing (col1 INT, col2 SHORT)");
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = ICommandPrepare_Prepare(commandprepare, 1);
ok(hr == S_OK, "got 0x%08x\n", hr);
ICommandPrepare_Release(commandprepare);
affected = 9999;
hr = ICommandText_Execute(command_text, NULL, &IID_IRowset, NULL, &affected, &unk);
ok(hr == S_OK, "got 0x%08x\n", hr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment