NAME
Win32::MSI::DB - a Perl package to modify MSI databases
SYNOPSIS
use Win32::MSI::DB;
$database=Win32::MSI::DB::new('filename');
$table=$database->table("table");
$view=$database->view("SELECT * FROM File
WHERE FileSize < ?",100000);
@rec=$table->records();
$rec4=$table->record(4);
$rec->set("field","value"); # string
$rec->set("field",4); # int
$rec->set("field","file"); # streams
$rec->get("field");
$rec->getintofile("field","file");
$field=$rec->field("field");
$field->set(2);
$data=$field->get();
$field->fromfile("autoexec.bat");
$field->intofile("tmp.aa");
$db->error();
$view->error();
$rec->error();
DESCRIPTION
Obtaining a database object
This is currently done by using MSI::DB::new. It takes filename as first parameter and one of the following constants as optional second.
- $Win32::MSI::MSIDBOPEN_READONLY
-
This opens the file not read-only, but changes will not be written to disk.
- $Win32::MSI::MSIDBOPEN_TRANSACT
-
This allows transactional functionality, ie. changes are written on commit only. This is the default.
- $Win32::MSI::MSIDBOPEN_DIRECT
-
Opens read/write without transactional behaviour.
- $Win32::MSI::MSIDBOPEN_CREATE
-
This creates a new database in transactional mode.
This database object allows creation of table or views, depending on your needs. If you simply need access to a table you can use the table method; for a subset of records or even a SQL-query you can use the view method.
From a table or view to records
When you have obtained a table or view object, you can use the record method to access individual records. It takes a number as parameter. Here the records are fetched as needed; using undef as parameter fetches all records and returns the first (index 0).
Another possibility is to use the method records, which returns an array of all records in this table or view.
A record has fields
And this fields can be queried or changed using the record object, as in
$rec->set("field","value"); # string
$rec->set("field",4); # int
$rec->set("field","file"); # streams
$rec->get("field");
$rec->getintofile("field","file");
or you can have separate field objects:
$field=$rec->field("field");
$data=$field->get();
$field->set(2);
Remark: the access to files (streams) is currently not finished.
Errors
Each object may access an error method, which gives a string or an array (depending on context) containing the error information.
Help wanted: Is there a way to get a error string from the number which does not depend on the current MSI database?
Especially the developer-errors (2000 and above) are not listed.
REMARKS
This module depends on Win32::API, which is used to import the functions out of the msi.dll.
Currently the Exporter is not used - patches are welcome.
AUTHOR
Please contact pmarek@cpan.org for questions, suggestions, and patches (diff -wu2 please).
Further plans
A Win32::MSI::Tools package is planned - which will allow to compare databases and give a diff, and similar tools.
I have started to write a simple Tk visualization.
SEE ALSO
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/msi/setup/installer_database_reference.asp