SQL을 사용하여 테이블에 이진 데이터 추가

이진 데이터는 INSERT INTO 또는 UPDATE SQL 쿼리를 사용하여 테이블에 직접 삽입할 수 없습니다. 이진 데이터를 테이블에 추가하려면 먼저 쿼리에서 이진 값에 대한 자리 표시자로 매개 변수 표식(?)를 사용해야 합니다. 쿼리 실행에는 해당 필드 중 하나에 이진 데이터가 포함된 레코드가 포함되어야 합니다.

표식은 쿼리와 함께 제출된 레코드에서 제공하는 값에 대한 매개 변수 참조입니다. SQL 문에 물음표 (?)로 표시됩니다.

다음 샘플 코드는 테이블에 이진 데이터를 추가합니다.

#include <windows.h>
#include <Msiquery.h>
#include <tchar.h>
#pragma comment(lib, "msi.lib")


int main()  
{ 

PMSIHANDLE hDatabase = 0;
PMSIHANDLE hView = 0;
PMSIHANDLE hRec = 0;

if (ERROR_SUCCESS == MsiOpenDatabase(_T("c:\\temp\\testdb.msi"), MSIDBOPEN_TRANSACT, &hDatabase))
{
    //
    // Open view on Binary table so that we can add a new row, must use '?' to represent Binary data
    //

    if (ERROR_SUCCESS == MsiDatabaseOpenView(hDatabase, _T("INSERT INTO `Binary` (`Name`, `Data`) VALUES ('NewBlob', ?)"), &hView))
    {

        //
        // Create record with binary data in 1st field (must match up with '?' in query)
        //

        hRec = MsiCreateRecord(1);
        if (ERROR_SUCCESS == MsiRecordSetStream(hRec, 1, _T("c:\\temp\\data.bin")))
        {

            //
            // Execute view with record containing binary data value; commit database to save changes
            //

            if (ERROR_SUCCESS == MsiViewExecute(hView, hRec)
              && ERROR_SUCCESS == MsiViewClose(hView)
              && ERROR_SUCCESS == MsiDatabaseCommit(hDatabase))
            {
                //
                // New binary data successfully committed to the database
                //
            }
        }
    }
}

return 0;  
}

다음 샘플 스크립트는 테이블에 이진 데이터를 추가합니다.

Dim Installer
Dim Database
Dim View
Dim Record

Set Installer = CreateObject("WindowsInstaller.Installer")

Set Record = Installer.CreateRecord(1)
Record.SetStream 1, "c:\temp\data.bin"

Set Database = Installer.OpenDatabase("c:\temp\testdb.msi", msiOpenDatabaseModeTransact)
Set View = Database.OpenView("INSERT INTO `Binary` (`Name`, `Data`) VALUES ('NewBlob', ?)")
View.Execute Record
Database.Commit ' save changes

쿼리 작업

SQL 구문

SQL 및 스크립트를 사용한 데이터베이스 쿼리의 예