Can NOT delete record from ListBox table - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

elanius
Posts: 38
Joined: Fri May 15, 2009 9:49 am

Can NOT delete record from ListBox table

Hi

I have some problem to delete record from LIstBox table and I don't know what is wrong

Here is part of my code

UINT DeleteFromListBox(MSIHANDLE hInstall, MSIHANDLE hDatabase, LPCTSTR strPropertyValue)
{
UINT nRetval = ERROR_SUCCESS;
TCHAR* strQuery = _T("DELETE FROM `ListBox` WHERE `ListBox`.`Value`='?' AND `ListBox`.`Property`='?'");
MSIHANDLE hView = 0;
MSIHANDLE hRecord = 0;

DWORD dwLen;
TCHAR strValue[128];

dwLen = TSIZEOF(strValue);
nRetval = MsiGetProperty(hInstall, strPropertyValue, strValue, &dwLen);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

nRetval = MsiDatabaseOpenView(hDatabase, strQuery, &hView);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

hRecord = MsiCreateRecord(2);
MsiRecordSetString(hRecord, 1, strValue);
MsiRecordSetString(hRecord, 2, strPropertyValue);

nRetval = MsiViewExecute(hView, hRecord);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

nRetval = MsiCloseHandle(hRecord);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

nRetval = MsiDatabaseCommit(hDatabase);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

cleanup:
if (0 != hRecord)
MsiCloseHandle(hRecord);

return nRetval;
}

I can add records into talble without problems but I can not delete it.
Everything looks be all right because all function always return SUCCESS, I am forgot something?

Thanks for any reply,
Elanius.
elanius
Posts: 38
Joined: Fri May 15, 2009 9:49 am

Re: Can NOT delete record from ListBox table

I found solution for this problem. If somebody will have same problem, here is what works for me.

I don't use MsiCreateRecord but I made classic SQL query and than I used MsiViewModify.
Here is code:

TCHAR strQuery[256];
_tcsprintf_m(strQuery, TSIZEOF(strQuery), _T("SELECT * FROM `ListBox` WHERE `Value`='%s' AND `Property`='%s'"), strValue, strPropertyValue);

nRetval = MsiDatabaseOpenView(hDatabase, strQuery, &hView);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

nRetval = MsiViewExecute(hView, 0);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

nRetval = MsiViewFetch(hView, &hRecordOut);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

nRetval = MsiViewModify(hView, MSIMODIFY_DELETE, hRecordOut);
if (ERROR_SUCCESS != nRetval)
goto cleanup;

Regards.

Return to “Common Problems”