Sign in to follow this  
Followers 0
wolf9228

Msi Database

5 posts in this topic

#1 ·  Posted (edited)

Project interpreter for the language C ++ New

All project files

;Important information

;CREATE TABLE {table} ( {column} {column type}) [HOLD]

;CHAR [( {size} )] | CHARACTER [( {size} )] | LONGCHAR | SHORT | INT | INTEGER | LONG |

;OBJECT [NOT NULL] [TEMPORARY] [LOCALIZABLE] [, column...][, ...] PRIMARY KEY column [, column][, ...].

;Data Type String

;String ==> LONGCHAR,LONGCHAR LOCALIZABLE,CHAR(Size),CHARACTER(Size),CHAR(Size) LOCALIZABLE

;CHARACTER(Size) LOCALIZABLE

;Data Type integer

;integer ==> INT,INTEGER,LONG,SHORT

;Data Type OBJECT (File Binary Stream)

;Tables may not contain more than one column of type 'object'.

;OBJECT ==> OBJECT

;UPDATE queries only work on nonprimary key columns.

;Binary data cannot be inserted into a table directly using the

;INSERT INTO or UPDATE SQL queries. For more information,

; Only In InsertInToTable Func And In UpdateRowData Func

MsiDatabase.zip

Simple logic error in this function

;Returns the integer value from a record field.
;http://msdn.microsoft.com/en-us/library/aa370367(v=VS.85).aspx
Func MsiRecordGetInteger($hRecord,$iField)
$error = DllCall($MsiLibrary,"UINT","MsiRecordGetInteger","UINT",$hRecord,"UINT",$iField)
if @error Then Return SetError(1,0,0)
Return SetError($error[0] == 0,0,$error[0])
EndFunc

Function corrected

;Returns the integer value from a record field.
;http://msdn.microsoft.com/en-us/library/aa370367(v=VS.85).aspx
;The MsiRecordGetInteger function returns MSI_NULL_INTEGER if the 
;field is null or if the field is a string that cannot be converted 
;to an integer.
; If the function succeeds, the return value is the integer value of the field.
Func MsiRecordGetInteger($hRecord,$iField)
$MSI_NULL_INTEGER = - 0x80000000
$error = DllCall($MsiLibrary,"UINT","MsiRecordGetInteger","UINT",$hRecord,"UINT",$iField)
if @error Then Return SetError(1,0,0)
if $MSI_NULL_INTEGER = $error[0] Then Return SetError(2,$MSI_NULL_INTEGER,0)
Return SetError(0,0,$error[0])
EndFunc

New Script

MsiDatabase2.zip

Msi Database Functions

Msi Database Functions

SQL Syntax

SQL Syntax

Column Definition Format

Column Definition Format

Adding Binary Data to a Table Using SQL

Adding Binary Data to a Table Using SQL

SQL Tutorial

Examples

http://www.w3schools.com/sql/default.asp

MsiDatabase.au3

#Include <Memory.au3>
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>

Global $MsiLibrary , $MsiUnicode = True , $MsiDatabaseCommit = True
Const $MSIDBOPEN_READONLY = 0  ; database open read-only, no persistent changes
Const $MSIDBOPEN_TRANSACT = 1  ; database read/write in transaction mode
Const $MSIDBOPEN_DIRECT = 2  ; database direct read/write without transaction
Const $MSIDBOPEN_CREATE = 3  ; create new database, transact mode read/write
Const $MSIDBOPEN_CREATEDIRECT = 4  ; create new database, direct mode read/write
Const $MSIDBOPEN_PATCHFILE = 32/4 ; add flag to indicate patch file
Const $ERROR_NO_MORE_ITEMS = 259
Const $MSIMODIFY_REPLACE = 4 ;MsiViewModify Function Updates or deletes and inserts a record into a table.

;CREATE TABLE {table} ( {column} {column type}) [HOLD]
;CHAR [( {size} )] | CHARACTER [( {size} )] | LONGCHAR | SHORT | INT | INTEGER | LONG | 
;OBJECT [NOT NULL] [TEMPORARY] [LOCALIZABLE] [, column...][, ...] PRIMARY KEY column [, column][, ...].

;Data Type String
;String ==> LONGCHAR,LONGCHAR LOCALIZABLE,CHAR(Size),CHARACTER(Size),CHAR(Size) LOCALIZABLE
;CHARACTER(Size) LOCALIZABLE

;Data Type integer
;integer ==> INT,INTEGER,LONG,SHORT

;Data Type OBJECT (File Binary Stream)
;Tables may not contain more than one column of type 'object'.
;OBJECT ==> OBJECT


Func CreateTable($hDatabase,$TableName,$ColumnsList_Name_Type_Size,$Hold)
;Return False Or True
;@extended ==> Msi Func @error
;Tables may not contain more than one column of type 'object'.
$Query = "CREATE TABLE " & $TableName & " (" & $ColumnsList_Name_Type_Size & " " & $Hold & ")"
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then 
$error = @error 
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,True)
EndFunc

Func InsertInToTable($hDatabase,$TableName,$ColumnList,$ValueList)
;Return False Or True
;@extended ==> Msi Func @error
;Binary data cannot be inserted into a table directly using the 
;INSERT INTO or UPDATE SQL queries. For more information, 
$Query = "INSERT INTO " & $TableName & "(" & $ColumnList & ") " & _ 
"VALUES(" & $ValueList & ")"
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then 
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,True)
EndFunc

Func TableRemove($hDatabase,$TableName)
;Return False Or True
;@extended ==> Msi Func @error
$Query = "DROP TABLE " & $TableName
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,True)
EndFunc

Func ColumnAdd($hDatabase,$TableName,$ColumnNameTypeSize)
;Return False Or True
;@extended ==> Msi Func @error
$Query = "ALTER TABLE " & $TableName & " ADD " & $ColumnNameTypeSize 
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then 
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,True)
EndFunc

Func GetColumnData($hDatabase,$TableName,$ColumnsList)
;Return Success $ColumnsArray ;Failure: 0 
;@extended ==> Msi Func @error
$Query = "SELECT " & $ColumnsList & " FROM " & $TableName 
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,0)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,0)
EndIf
$hRecord = MsiViewFetch($hView)
if @error Then 
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,0)
EndIf
$FieldCount = MsiRecordGetFieldCount($hRecord)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,0)
EndIf
$AColumnsName = StringSplit($ColumnsList,",")
Dim $ColumnsArray[1][$FieldCount] , $i , $iMax 
For $j = 1 To $FieldCount
$Query = "SELECT " & $AColumnsName[$j] & " FROM " & $TableName
$ihView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(5,$error,0)
EndIf
MsiViewExecute($ihView)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(6,$error,0)
EndIf
$ihRecord = MsiViewGetColumnInfo($ihView,1)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiCloseHandle($ihRecord)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(7,$error,0)
EndIf
$Format = MsiRecordGetString($ihRecord,1,1)
if Not @error = 234 And Not @error = 0 Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiCloseHandle($ihRecord)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(8,$error,0)
EndIf
MsiCloseHandle($ihRecord)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
$i = 1
While 1
Switch StringUpper($Format)
Case "S","L","G"
$DataSize = MsiRecordDataSize($hRecord,$j)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(9,$error,0)
EndIf
$VALUE = MsiRecordGetString($hRecord,$j,$DataSize)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(10,$error,0)
EndIf
MsiCloseHandle($hRecord)
Case "V","O"
$DataSize = MsiRecordDataSize($hRecord,$j)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(11,$error,0)
EndIf
$VALUE = MsiRecordReadStream($hRecord,$j,$DataSize)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(12,$error,0)
EndIf
MsiCloseHandle($hRecord)
Case Else
$VALUE = MsiRecordGetInteger($hRecord,$j)
if @error = 2 Then $VALUE = ""
MsiCloseHandle($hRecord)
EndSwitch
$ColumnsArray[$i - 1][$j - 1] = $VALUE
$hRecord = MsiViewFetch($hView)
if @error Then ExitLoop
$i += 1
if $iMax < $i Then $iMax = $i
ReDim $ColumnsArray[$iMax][$FieldCount]
WEnd
$hRecord = MsiViewFetch($hView)
Next
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,$ColumnsArray)
EndFunc


Func UpdateRowData($hDatabase,$TableName,$SetColumnsList,$Id)
;Return False Or True
;@extended ==> Msi Func @error
;$SetColumnsList ==> {column}= {constant} [, {column}= {constant}
;UPDATE queries only work on nonprimary key columns.
;Binary data cannot be inserted into a table directly using the 
;INSERT INTO or UPDATE SQL queries. For more information, 
$Query = "UPDATE " & $TableName & " SET " & $SetColumnsList & " WHERE " & $Id
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,True)
EndFunc

Func GetRowData($hDatabase,$TableName,$ColumnsList,$Id)
;Return Success $RowArray ;Failure: 0 
;@extended ==> Msi Func @error
$Query = "SELECT " & $ColumnsList & " FROM " & $TableName & " WHERE " & $Id
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,0)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,0)
EndIf
$hRecord = MsiViewFetch($hView)
if @error Then 
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,0)
EndIf
$FieldCount = MsiRecordGetFieldCount($hRecord)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,0)
EndIf
$AColumnsName = StringSplit($ColumnsList,",")
Dim $RowArray[1][$FieldCount] , $i , $iMax
For $j = 1 To $FieldCount
$Query = "SELECT " & $AColumnsName[$j] & " FROM " & $TableName
$ihView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(5,$error,0)
EndIf
MsiViewExecute($ihView)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(6,$error,0)
EndIf
$ihRecord = MsiViewGetColumnInfo($ihView,1)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiCloseHandle($ihRecord)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(7,$error,0)
EndIf
$Format = MsiRecordGetString($ihRecord,1,1)
if Not @error = 234 And Not @error = 0 Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiCloseHandle($ihRecord)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(8,$error,0)
EndIf
MsiCloseHandle($ihRecord)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
$i = 1
While 1
Switch StringUpper($Format)
Case "S","L","G"
$DataSize = MsiRecordDataSize($hRecord,$j)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(9,$error,0)
EndIf
$VALUE = MsiRecordGetString($hRecord,$j,$DataSize)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(10,$error,0)
EndIf
MsiCloseHandle($hRecord)
Case "V","O"
$DataSize = MsiRecordDataSize($hRecord,$j)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(11,$error,0)
EndIf
$VALUE = MsiRecordReadStream($hRecord,$j,$DataSize)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(12,$error,0)
EndIf
MsiCloseHandle($hRecord)
Case Else
$VALUE = MsiRecordGetInteger($hRecord,$j)
if @error = 2 Then $VALUE = ""
MsiCloseHandle($hRecord)
EndSwitch
$RowArray[$i - 1][$j - 1] = $VALUE
$hRecord = MsiViewFetch($hView)
if @error Then ExitLoop
$i += 1
if $iMax < $i Then $iMax = $i
ReDim $RowArray[$iMax][$FieldCount]
WEnd
$hRecord = MsiViewFetch($hView)
Next
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)  
Return SetError(0,0,$RowArray)
EndFunc

Func DeleteRowById($hDatabase,$TableName,$Id)
;Return False Or True
;@extended ==> Msi Func @error
$Query = "DELETE FROM " & $TableName & " WHERE " & $Id
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,True)
EndFunc


Func GetElementValueA($hDatabase,$TableName,$ColumnName,$Id)
;Return Success: Value Data ;Failure: blank string 
;@extended ==> Msi Func @error
$Query = "SELECT " & $ColumnName & " FROM " & $TableName & " WHERE " & $Id
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,"")
MsiViewExecute($hView)
if @error Then
$error = @error 
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,"")
EndIf
$hRecord = MsiViewFetch($hView)
if @error Then 
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,"")
EndIf
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,"")
EndIf
$ihRecord = MsiViewGetColumnInfo($hView,1)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(5,$error,"")
EndIf
$Format = MsiRecordGetString($ihRecord,1,1)
if Not @error = 234 And Not @error = 0 Then 
$error = @error
MsiCloseHandle($ihRecord)
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(6,$error,"")
EndIf
MsiCloseHandle($ihRecord)
Switch StringUpper($Format)
Case "S","L","G"
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(7,$error,"")
EndIf
$VALUE = MsiRecordGetString($hRecord,1,$DataSize)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(8,$error,"")
EndIf
Case "V","O"
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(9,$error,"")
EndIf
$VALUE = MsiRecordReadStream($hRecord,1,$DataSize)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)  
Return SetError(10,$error,"")
EndIf
Case Else
$VALUE = MsiRecordGetInteger($hRecord,1)
if @error = 2 Then $VALUE = ""
EndSwitch
MsiCloseHandle($hRecord)
MsiCloseHandle($ihRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(0,0,$VALUE)
EndFunc

Func GetElementValueB($hDatabase,$TableName,$ColumnName,$RowNumber)
;Return Success: Value Data ;Failure: blank string 
;@extended ==> Msi Func @error
$Query = "SELECT " & $ColumnName & " FROM " & $TableName 
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,"")
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,"")
EndIf
For $i = 1 To $RowNumber
$hRecord = MsiViewFetch($hView)
if $hRecord = 0 Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,"")
EndIf
if $i <> $RowNumber Then _ 
MsiCloseHandle($hRecord)
Next
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,"")
EndIf
$ihRecord = MsiViewGetColumnInfo($hView,1)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(5,$error,"")
EndIf
$Format = MsiRecordGetString($ihRecord,1,1)
if Not @error = 234 And Not @error = 0 Then 
$error = @error
MsiCloseHandle($ihRecord)
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(6,$error,"")
EndIf
MsiCloseHandle($ihRecord)
Switch StringUpper($Format)
Case "S","L","G"
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)  
Return SetError(7,$error,"")
EndIf
$VALUE = MsiRecordGetString($hRecord,1,$DataSize)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(8,$error,"")
EndIf
Case "V","O"
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(9,$error,"")
EndIf
$VALUE = MsiRecordReadStream($hRecord,1,$DataSize)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(10,$error,"")
EndIf
Case Else
$VALUE = MsiRecordGetInteger($hRecord,1)
if @error = 2 Then $VALUE = ""
EndSwitch
MsiCloseHandle($hRecord)
MsiCloseHandle($ihRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,$VALUE)
EndFunc

Func UpdateElementValueA($hDatabase,$NewValue_Or_StreamFilePath,$TableName,$ColumnName,$Id)
;Return False Or True
;@extended ==> Msi Func @error
$Query = "SELECT " & $ColumnName & " FROM " & $TableName & " WHERE " & $Id
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
$hRecord = MsiViewFetch($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,False)
EndIf
$ihRecord = MsiViewGetColumnInfo($hView,1)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,False)
EndIf
$Format = MsiRecordGetString($ihRecord,1,1)
if Not @error = 234 And Not @error = 0 Then
$error = @error
MsiCloseHandle($hRecord)
MsiCloseHandle($ihRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(5,$error,False)
EndIf
MsiCloseHandle($ihRecord)
Switch StringUpper($Format)
Case "S","L","G"
if Not IsString($NewValue_Or_StreamFilePath) Then
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(6,0,False)
EndIf
 MsiRecordSetString($hRecord,1,$NewValue_Or_StreamFilePath)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(7,$error,False)
EndIf
Case "V","O"
if Not FileExists($NewValue_Or_StreamFilePath) Then 
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(8,0,False)
EndIf
MsiRecordSetStream($hRecord,1,$NewValue_Or_StreamFilePath)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(9,$error,False)
EndIf
Case Else
if Not IsInt($NewValue_Or_StreamFilePath) Then 
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(10,0,False)
EndIf
MsiRecordSetInteger($hRecord,1,$NewValue_Or_StreamFilePath)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(11,$error,False)
EndIf
EndSwitch
MsiViewModify($hView,$MSIMODIFY_REPLACE,$hRecord)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)  
Return SetError(12,$error,False)
EndIf
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,True)
EndFunc

Func UpdateElementValueB($hDatabase,$NewValue_Or_StreamFilePath,$TableName,$ColumnName,$RowNumber)
;Return False Or True
;@extended ==> Msi Func @error
$Query = "SELECT " & $ColumnName & " FROM " & $TableName 
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
For $i = 1 To $RowNumber
$hRecord = MsiViewFetch($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,False)
EndIf
if $i <> $RowNumber Then _
MsiCloseHandle($hRecord)
Next
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,False)
EndIf
$ihRecord = MsiViewGetColumnInfo($hView,1)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(5,$error,False)
EndIf
$Format = MsiRecordGetString($ihRecord,1,1)
if Not @error = 234 And Not @error = 0 Then 
$error = @error
MsiCloseHandle($ihRecord)
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(6,$error,False)
EndIf
MsiCloseHandle($ihRecord)
Switch StringUpper($Format)
Case "S","L","G"
if Not IsString($NewValue_Or_StreamFilePath) Then 
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(7,0,False)
EndIf
 MsiRecordSetString($hRecord,1,$NewValue_Or_StreamFilePath)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(8,$error,False)
EndIf
Case "V","O"
if Not FileExists($NewValue_Or_StreamFilePath) Then 
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(9,0,False)
EndIf
MsiRecordSetStream($hRecord,1,$NewValue_Or_StreamFilePath)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(10,$error,False)
EndIf
Case Else
if Not IsInt($NewValue_Or_StreamFilePath) Then 
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(11,0,False)
EndIf
MsiRecordSetInteger($hRecord,1,$NewValue_Or_StreamFilePath)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)  
Return SetError(12,$error,False)
EndIf
EndSwitch
MsiViewModify($hView,$MSIMODIFY_REPLACE,$hRecord)
if @error Then 
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)  
Return SetError(13,$error,False)
EndIf
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
if $MsiDatabaseCommit Then MsiDatabaseCommit($hDatabase)
Return SetError(0,0,True)
EndFunc


Func DisplaySelect($hDatabase,$TableName,$ColumnsList,$Id = "")
;Return False Or True
;@extended ==> Msi Func @error
$Query = "SELECT " & $ColumnsList & " FROM " & $TableName 
if Not ($Id == "") Then $Query &= " WHERE " & $Id
$hView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then Return SetError(1,@error,False)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,False)
EndIf
$hRecord = MsiViewFetch($hView)
if @error Then 
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,False)
EndIf
$FieldCount = MsiRecordGetFieldCount($hRecord)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,False)
EndIf
$AColumnsName = StringSplit($ColumnsList,",")
Dim $SelectArray[1][$FieldCount] , $i , $iMax
For $j = 1 To $FieldCount
$Query = "SELECT " & $AColumnsName[$j] & " FROM " & $TableName
$ihView = MsiDatabaseOpenView($hDatabase,$Query)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(5,$error,False)
EndIf
MsiViewExecute($ihView)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(6,$error,False)
EndIf
$ihRecord = MsiViewGetColumnInfo($ihView,1)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(7,$error,False)
EndIf
$Format = MsiRecordGetString($ihRecord,1,1)
if Not @error = 234 And Not @error = 0 Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
MsiCloseHandle($ihRecord)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
Return SetError(8,$error,False)
EndIf
MsiCloseHandle($ihRecord)
MsiViewClose($ihView)
MsiCloseHandle($ihView)
$i = 1
While 1
Switch StringUpper($Format)
Case "S","L","G"
$DataSize = MsiRecordDataSize($hRecord,$j)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(9,$error,False)
EndIf
$VALUE = MsiRecordGetString($hRecord,$j,$DataSize)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(10,$error,False)
EndIf
MsiCloseHandle($hRecord)
Case "V","O"
$DataSize = MsiRecordDataSize($hRecord,$j)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(11,$error,False)
EndIf
$VALUE = MsiRecordReadStream($hRecord,$j,$DataSize)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(12,$error,False)
EndIf
MsiCloseHandle($hRecord)
Case Else
$VALUE = MsiRecordGetInteger($hRecord,$j)
if @error = 2 Then $VALUE = ""
MsiCloseHandle($hRecord)
EndSwitch
$SelectArray[$i - 1][$j - 1] = $VALUE
$hRecord = MsiViewFetch($hView)
if @error Then ExitLoop
$i += 1
if $iMax < $i Then $iMax = $i
ReDim $SelectArray[$iMax][$FieldCount]
WEnd
$hRecord = MsiViewFetch($hView)
Next
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
$TrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]") ;Taskbar Window
$WPos = WinGetPos($TrayWnd)
if Not IsArray($WPos) Then 
$iH = @DesktopHeight - 68
Else
$iH = (@DesktopHeight - $WPos[3]) - 30
EndIf
$RE = $i 
$CE = $FieldCount 
$W = (($CE + 1) * 70) + 15 ; $CE + 1 ==> 1 Rows Number
$H = (($RE + 1) * 20) + 50 ; $RE + 1 ==> 1 Clos Number
if $W > (@DesktopWidth - 5) Then $W = @DesktopWidth - 5
if $H > $iH Then $H = $iH
GUICreate("DisplaySelect",$W,$H,0,0)
$W -= 10
$H -= 40
$hListView = GUICtrlCreateListView("",5,5,$W,$H)
_GUICtrlListView_SetExtendedListViewStyle($hListView, _
BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES,$LVS_EX_FLATSB))
$CopyButton = GUICtrlCreateButton("Copy Selected", 5,$H + 10, $W - 5, 25)
For $i = 0 To $RE - 1
For $j = 0 To $CE - 1
$Value = $SelectArray[$i][$j]
If $i = 0 Then
if $J = 0 Then _
_GUICtrlListView_AddColumn($hListView, "Row",70)
_GUICtrlListView_AddColumn($hListView, $AColumnsName[$j + 1],70)
EndIf
if $j = 0 Then 
_GUICtrlListView_AddItem($hListView,"",$i)
_GUICtrlListView_AddSubItem($hListView,$i, "[" & $i & "]",$j)
_GUICtrlListView_AddSubItem($hListView,$i,$Value,$j + 1)
Else
_GUICtrlListView_AddSubItem($hListView,$i,$Value,$j + 1)
EndIf
Next
Next
GUISetState()
Do
$msg = GUIGetMsg()
if $msg = $CopyButton Then
$selectionmark = _GUICtrlListView_GetSelectionMark($hListView)
ClipPut(_GUICtrlListView_GetItemTextString($hListView,$selectionmark))
EndIf
Until $msg = $GUI_EVENT_CLOSE
GUIDelete()
Return SetError(0,0,True)
EndFunc

Func MemToFile($hMemory,$FileName,$iCreation = 3,$GlobalFree = False)
;Return False Or True
;@extended ==> Memory Func @error And Winapi File Func @error
;Action to take on files that exist and do not exist:
;0 - Creates a new file. The function fails if the file exists
;1 - Creates a new file. If a file exists, it is overwritten
;2 - Opens a file. The function fails if the file does not exist
;3 - Opens a file. If the file does not exist, the function creates the file
;4 - Opens a file and truncates it so that its size is 0 bytes. The function fails if the file does not exist.
Local $nBytes
$Size = _MemGlobalSize($hMemory)
if @error Then Return SetError(1,@error,False)
$hLock = _MemGlobalLock ($hMemory)
if @error Then Return SetError(2,@error,False)
$hFile = _WinAPI_CreateFile($FileName, $iCreation)
if @error Then Return SetError(3,@error,False)
$CharStruct = DllStructCreate("char[" & $Size & "]",$hLock)
_WinAPI_WriteFile($hFile, DllStructGetPtr($CharStruct),$Size, $nBytes)
if @error Then Return SetError(4,@error,False)
_WinAPI_CloseHandle($hFile)
if $GlobalFree Then _MemGlobalFree($hMemory)
Return SetError(0,0,True)
EndFunc

Func GetDataFromMem($hMemory,$GlobalFree = False)
;Return False Or True
;@extended ==> Memory Func @error
$Size = _MemGlobalSize($hMemory)
if @error Then Return SetError(1,@error,"")
$hLock = _MemGlobalLock ($hMemory)
if @error Then Return SetError(2,@error,"")
$CharStruct = DllStructCreate("char[" & $Size & "]",$hLock)
$Data = DllStructGetData($CharStruct,1)
if $GlobalFree Then _MemGlobalFree($hMemory)
Return SetError(0,0,$Data)
EndFunc

Func MsiOpenDatabase($szDatabasePath,$iAccessMode = 1,$TransactionMode = False)
;$iAccessMode
; 1 Open ; Defaults
; 2 CREATE
; 3 READONLY
;------------------
;$TransactionMode
;To make and save changes to a database first open the database in transaction 
;(MSIDBOPEN_TRANSACT), create (MSIDBOPEN_CREATE or MSIDBOPEN_CREATEDIRECT), 
;or direct (MSIDBOPEN_DIRECT) mode. After making the changes, always call 
;MsiDatabaseCommit before closing the

;To make and save changes to a database first open the database in transaction 
;(MSIDBOPEN_TRANSACT), create (MSIDBOPEN_CREATE or MSIDBOPEN_CREATEDIRECT), or 
;direct (MSIDBOPEN_DIRECT) mode. After making the changes, always call MsiDatabaseCommit 
;before closing the database handle. MsiDatabaseCommit flushes all buffers.
if Not $MsiLibrary Then _
$MsiLibrary = DllOpen("Msi.dll")
if $iAccessMode = 3 Then
$szPersist = $MSIDBOPEN_READONLY
Else
if $iAccessMode = 2 Then
if $TransactionMode Then 
$szPersist = $MSIDBOPEN_CREATEDIRECT
Else
$szPersist = $MSIDBOPEN_CREATE
EndIf
Else
if $TransactionMode Then 
$szPersist = $MSIDBOPEN_TRANSACT
Else
$szPersist = $MSIDBOPEN_DIRECT
EndIf
EndIf
EndIf
if $MsiUnicode Then
$error = DllCall($MsiLibrary,"UINT","MsiOpenDatabaseW","wstr",$szDatabasePath,"int",$szPersist,"UINT*",0)
Else
$error = DllCall($MsiLibrary,"UINT","MsiOpenDatabaseA","str",$szDatabasePath,"int",$szPersist,"UINT*",0)
EndIf
if @error Then Return SetError(1,0,0)
if $MsiDatabaseCommit Then MsiDatabaseCommit($error[3])
Return SetError($error[0],0,$error[3])
EndFunc

;http://msdn.microsoft.com/en-us/library/aa370075(v=VS.85).aspx
Func MsiDatabaseCommit($hDatabase)
;The MsiDatabaseCommit function commits changes to a database.
;The MsiDatabaseCommit function finalizes the persistent form 
;of the database. All persistent data is then written to the 
;writable database. No temporary columns or rows are written. 
;The MsiDatabaseCommit function has no effect on a database 
;that is opened as read-only. You can call this function 
;multiple times to save the current state of tables loaded 
;into memory. When the database is finally closed, any changes 
;made after the database is committed are rolled back. This 
;function is normally called prior to shutdown when all database 
;changes have been finalized.
$error = DllCall($MsiLibrary,"UINT","MsiDatabaseCommit","UINT",$hDatabase)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

;Creates new record object with specified number of fields.
;http://msdn.microsoft.com/en-us/library/aa370072(v=VS.85).aspx
Func MsiCreateRecord($cParams)
$error = DllCall($MsiLibrary,"UINT","MsiCreateRecord","UINT",$cParams)
if @error Then Return SetError(1,0,0)
Return SetError($error[0] == 0,0,$error[0])
EndFunc

;Sets all fields in a record to null.
;http://msdn.microsoft.com/en-us/library/aa370364(v=VS.85).aspx
Func MsiRecordClearData($hRecord)
$error = DllCall($MsiLibrary,"UINT","MsiRecordClearData","UINT",$hRecord)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

;Copies a string into the designated field.
;http://msdn.microsoft.com/en-us/library/aa370373(v=VS.85).aspx
Func MsiRecordSetString($hRecord,$iField,$szValue)
if $MsiUnicode Then
$error = DllCall($MsiLibrary,"UINT","MsiRecordSetStringW","UINT",$hRecord,"UINT",$iField,"wstr",$szValue)
Else
$error = DllCall($MsiLibrary,"UINT","MsiRecordSetStringA","UINT",$hRecord,"UINT",$iField,"str",$szValue)
EndIf
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

;Sets a record field to an integer field.
;http://msdn.microsoft.com/en-us/library/aa370371(v=VS.85).aspx
Func MsiRecordSetInteger($hRecord,$iField,$iValue)
$error = DllCall($MsiLibrary,"UINT","MsiRecordSetInteger","UINT",$hRecord,"UINT",$iField,"int",$iValue)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

;Sets a record stream field from a file.
;http://msdn.microsoft.com/en-us/library/aa370372(v=VS.85).aspx
Func MsiRecordSetStream($hRecord,$iField,$StreamFilePath)
if $MsiUnicode Then
$error = DllCall($MsiLibrary,"UINT","MsiRecordSetStreamW","UINT",$hRecord,"UINT",$iField,"wstr",$StreamFilePath)
Else
$error = DllCall($MsiLibrary,"UINT","MsiRecordSetStreamA","UINT",$hRecord,"UINT",$iField,"str",$StreamFilePath)
EndIf
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

;Returns the string value of a record field.
;http://msdn.microsoft.com/en-us/library/aa370368(v=VS.85).aspx
Func MsiRecordGetString($hRecord,$iField,$pcchValueBuf)
if $pcchValueBuf = 0 Then Return SetError(0,0,"")
$DWORD = DllStructCreate("DWORD")
DllStructSetData($DWORD,1,$pcchValueBuf * 2)
$PDWORD = DllStructGetPtr($DWORD)
if $MsiUnicode Then
$char = DllStructCreate("wchar[" & $pcchValueBuf * 2 & "]")
$PChar = DllStructGetPtr($char)
$error = DllCall($MsiLibrary,"UINT","MsiRecordGetStringW","UINT",$hRecord,"UINT",$iField,"ptr",$PChar,"ptr",$PDWORD)
Else
$char = DllStructCreate("char[" & $pcchValueBuf * 2 & "]")
$PChar = DllStructGetPtr($char)
$error = DllCall($MsiLibrary,"UINT","MsiRecordGetStringA","UINT",$hRecord,"UINT",$iField,"ptr",$PChar,"ptr",$PDWORD)
EndIf
if @error Then Return SetError(1,0,0)
Return SetError($error[0],DllStructGetData($DWORD,1),DllStructGetData($char,1))
EndFunc

;Returns the integer value from a record field.
;http://msdn.microsoft.com/en-us/library/aa370367(v=VS.85).aspx
;The MsiRecordGetInteger function returns MSI_NULL_INTEGER if the 
;field is null or if the field is a string that cannot be converted 
;to an integer.
; If the function succeeds, the return value is the integer value of the field.
Func MsiRecordGetInteger($hRecord,$iField)
$MSI_NULL_INTEGER = - 0x80000000
$error = DllCall($MsiLibrary,"UINT","MsiRecordGetInteger","UINT",$hRecord,"UINT",$iField)
if @error Then Return SetError(1,0,0)
if $MSI_NULL_INTEGER = $error[0] Then Return SetError(2,$MSI_NULL_INTEGER,0)
Return SetError(0,0,$error[0])
EndFunc

;The MsiRecordIsNull function reports a null record field
;FALSE
;The function succeeds, and the field is not null or the record handle is invalid.
;TRUE
;The function succeeds, and the field is null or the field does not exist.
Func MsiRecordIsNull($hRecord,$iField)
$error = DllCall($MsiLibrary,"UINT","MsiRecordIsNull","UINT",$hRecord,"UINT",$iField)
if @error Then Return SetError(1,0,0)
Return SetError(0,0,$error[0] <> 0)
EndFunc



;Reads bytes from a record stream field into a buffer.
;http://msdn.microsoft.com/en-us/library/aa370370(v=VS.85).aspx
;Return Handle to the newly allocated memory object
Func MsiRecordReadStream($hRecord,$iField,$pcbDataBuf)
if $pcbDataBuf = 0 Then Return SetError(0,0,0)
$DWORD = DllStructCreate("DWORD")
DllStructSetData($DWORD,1,$pcbDataBuf)
$PDWORD = DllStructGetPtr($DWORD)
$hMemory = _MemGlobalAlloc ($pcbDataBuf, $GHND)
$hLock = _MemGlobalLock ($hMemory)
$char = DllStructCreate("char[" & $pcbDataBuf & "]",$hLock)
$PChar = DllStructGetPtr($char)
$error = DllCall($MsiLibrary,"UINT","MsiRecordReadStream","UINT",$hRecord,"UINT",$iField,"ptr",$PChar,"ptr",$PDWORD)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$hMemory)
EndFunc

;Returns the names of all the primary key columns.
;CREATE TABLE {table} ( {column} {column type}) [HOLD]
;"HOLD ==> LOCALIZABLE PRIMARY KEY Name"
;http://msdn.microsoft.com/en-us/library/aa370078(v=VS.85).aspx
Func MsiDatabaseGetPrimaryKeys($hDatabase,$szTableName)
if $MsiUnicode Then
$error = DllCall($MsiLibrary,"UINT","MsiDatabaseGetPrimaryKeysW","UINT",$hDatabase,"wstr",$szTableName,"UINT*",0)
Else
$error = DllCall($MsiLibrary,"UINT","MsiDatabaseGetPrimaryKeysA","UINT",$hDatabase,"str",$szTableName,"UINT*",0)    
EndIf
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[2])
EndFunc

;Prepares a database query and creates a view object.
;http://msdn.microsoft.com/en-us/library/aa370082(v=VS.85).aspx
Func MsiDatabaseOpenView($hDatabase,$szQuery)
if $MsiUnicode Then
$error = DllCall($MsiLibrary,"UINT","MsiDatabaseOpenViewW","UINT",$hDatabase,"wstr",$szQuery,"UINT*",0)
Else
$error = DllCall($MsiLibrary,"UINT","MsiDatabaseOpenViewA","UINT",$hDatabase,"str",$szQuery,"UINT*",0)
EndIf
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[3])
EndFunc

;Executes the view query and supplies required parameters.
;http://msdn.microsoft.com/en-us/library/aa370513(v=VS.85).aspx
Func MsiViewExecute($hView,$hRecord = 0)
$error = DllCall($MsiLibrary,"UINT","MsiViewExecute","UINT",$hView,"UINT",$hRecord)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

;http://msdn.microsoft.com/en-us/library/aa370514(v=VS.85).aspx
Func MsiViewFetch($hView)
$error = DllCall($MsiLibrary,"UINT","MsiViewFetch","UINT",$hView,"UINT*",0)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[2])
EndFunc

;Fetches the next sequential record from the view.
;http://msdn.microsoft.com/en-us/library/aa370365(v=VS.85).aspx
Func MsiRecordDataSize($hRecord,$iField)
$error = DllCall($MsiLibrary,"UINT","MsiRecordDataSize","UINT",$hRecord,"UINT",$iField)
if @error Then Return SetError(1,0,0)
Return SetError(0,0,$error[0])
EndFunc

;Returns the number of fields in a record.
;http://msdn.microsoft.com/en-us/library/aa370366(v=VS.85).aspx
Func MsiRecordGetFieldCount($hRecord)
$error = DllCall($MsiLibrary,"UINT","MsiRecordGetFieldCount","UINT",$hRecord)
if @error Then Return SetError(1,0,0)
Return SetError($error[0] == 0,0,$error[0])
EndFunc

;http://msdn.microsoft.com/en-us/library/aa370519(v=VS.85).aspx
;Updates a fetched record.
Func MsiViewModify($hView,$eModifyMode,$hRecord)
$error = DllCall($MsiLibrary,"UINT","MsiViewModify","UINT",$hView,"UINT",$eModifyMode,"UINT",$hRecord)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

;Returns column names or definitions.
;definitions ==> column data Type
;http://msdn.microsoft.com/en-us/library/aa370516(v=VS.85).aspx
Func MsiViewGetColumnInfo($hView,$eColumnInfo)
$error = DllCall($MsiLibrary,"UINT","MsiViewGetColumnInfo","UINT",$hView,"UINT",$eColumnInfo,"UINT*",0)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[3])
EndFunc

;Releases the result set for an executed view.
;http://msdn.microsoft.com/en-us/library/aa370510(v=VS.85).aspx
Func MsiViewClose($hView)
$error = DllCall($MsiLibrary,"UINT","MsiViewClose","UINT",$hView)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

;The MsiCloseHandle function closes an open installation handle.
;http://msdn.microsoft.com/en-us/library/aa370067(VS.85).aspx
Func MsiCloseHandle($hAny)
$error = DllCall($MsiLibrary,"UINT","MsiCloseHandle","UINT",$hAny)
if @error Then Return SetError(1,0,0)
Return SetError($error[0],0,$error[0])
EndFunc

Example

CreateTable.au3

#Include "MsiDatabase.au3"
#Include <Array.au3>
;CREATE TABLE {table} ( {column} {column type}) [HOLD]
;CHAR [( {size} )] | CHARACTER [( {size} )] | LONGCHAR | SHORT | INT | INTEGER | LONG | 
;OBJECT [NOT NULL] [TEMPORARY] [LOCALIZABLE] [, column...][, ...] PRIMARY KEY column [, column][, ...].

;Data Type String
;String ==> LONGCHAR,LONGCHAR LOCALIZABLE,CHAR(Size),CHARACTER(Size),CHAR(Size) LOCALIZABLE
;CHARACTER(Size) LOCALIZABLE

;Data Type integer
;integer ==> INT,INTEGER,LONG,SHORT

;Data Type OBJECT (File Binary Stream)
;Tables may not contain more than one column of type 'object'.
;OBJECT ==> OBJECT


$hDatabase = MsiOpenDatabase("MsiDatabase.Msi",2) ;2 CREATE MsiDatabase
CreateTable($hDatabase,"Binary","Id INT,File OBJECT,String LONGCHAR","LOCALIZABLE PRIMARY KEY Id")
InsertInToTable($hDatabase,"Binary","Id","1") ;Add Id 1 And Row 1 (Row Start From 1)
InsertInToTable($hDatabase,"Binary","Id","2") ;Add Id 2 And Row 2 (Row Start From 1)
UpdateElementValueA($hDatabase,"iFile.txt","Binary","File","Id = 1") ;Update Column File In Id = 1 Or Row 1
UpdateElementValueB($hDatabase,"jFile.txt","Binary","File",2) ;Update Column File In Id = 2 Or Row 2
UpdateElementValueA($hDatabase,"MsiDatabase","Binary","String","Id = 2") ;Update Column String In Id = 2 Or Row 2
UpdateElementValueB($hDatabase,"Autoit","Binary","String",1) ;Update Column String In Id = 1 Or Row 1
MsiCloseHandle($hDatabase) ;Close MsiDatabase

$hDatabase = MsiOpenDatabase("MsiDatabase.Msi",1) ;1 Open MsiDatabase
DisplaySelect($hDatabase,"Binary","Id,File,String") ; Display Id,File,String Columns


$hMemory = GetElementValueA($hDatabase,"Binary","File","Id = 1") ;Get Id = 1 Or Row 1 In Column File 
MemToFile($hMemory,"NewiFile.txt",3,False) ; 3 Opens a file. If the file does not exist, the function creates the file
MsgBox(0,"iFile.Txt Id = 1",GetDataFromMem($hMemory,True)) ;True Free $hMemory

$hMemory = GetElementValueB($hDatabase,"Binary","File",2) ;Get Id = 2 Or Row 2 In Column File 
MemToFile($hMemory,"NewJFile.txt",3,False) ; Opens a file. If the file does not exist, the function creates the file
MsgBox(0,"jFile.Txt Id = 2",GetDataFromMem($hMemory,True)) ;True Free $hMemory

$Str = GetElementValueB($hDatabase,"Binary","String",1) ;Get Id = 1 Or Row 1 In Column String 
MsgBox(0,"Id = 1",$Str)

$Str = GetElementValueA($hDatabase,"Binary","String","Id = 2") ;Get Id = 2 Or Row 2 In Column String 
MsgBox(0,"Id = 2",$Str)

$ColumnsArray = GetColumnData($hDatabase,"Binary","Id,File,String")
if Not @error Then _ 
_ArrayDisplay($ColumnsArray,"Colu Id,File,String")

$ColumnsArray = GetColumnData($hDatabase,"Binary","Id")
if Not @error Then _ 
_ArrayDisplay($ColumnsArray,"Colu Id")

$ColumnsArray = GetColumnData($hDatabase,"Binary","Id,String")
if Not @error Then _ 
_ArrayDisplay($ColumnsArray,"Colu Id,String")

$ColumnsArray = GetColumnData($hDatabase,"Binary","String,Id")
if Not @error Then _ 
_ArrayDisplay($ColumnsArray,"Colu String,Id")

$ColumnsArray = GetColumnData($hDatabase,"Binary","String")
if Not @error Then _ 
_ArrayDisplay($ColumnsArray,"Colu String")

$RowArray = GetRowData($hDatabase,"Binary","Id,String","Id = 1")
if Not @error Then _ 
_ArrayDisplay($RowArray,"Rows(Id,String) Id = 1")

$RowArray = GetRowData($hDatabase,"Binary","Id,String","Id = 2")
if Not @error Then _ 
_ArrayDisplay($RowArray,"Rows(Id,String) Id = 2")

$RowArray = GetRowData($hDatabase,"Binary","String,Id","Id = 1")
if Not @error Then _ 
_ArrayDisplay($RowArray,"Rows(String,Id) Id = 1")

$RowArray = GetRowData($hDatabase,"Binary","String,Id","Id = 2")
if Not @error Then _ 
_ArrayDisplay($RowArray,"Rows(String,Id) Id = 2")

MsiCloseHandle($hDatabase) ;Close MsiDatabase

Example

Insert_Update.au3

#Include "MsiDatabase.au3"
#Include <Array.au3>
;$SetColumnsList ==> {column}= {constant} [, {column}= {constant}
;UPDATE queries only work on nonprimary key columns.
;Binary data cannot be inserted into a table directly using the 
;INSERT INTO or UPDATE SQL queries. For more information,
; Only In InsertInToTable Func And In UpdateRowData Func


$hDatabase = MsiOpenDatabase("MsiDB.Msi",2) ;2 CREATE MsiDB
CreateTable($hDatabase,"Identity","Id INT,Name LONGCHAR,Age INT,Country LONGCHAR","LOCALIZABLE PRIMARY KEY Id")
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","1,'Sword',10,'British'")
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","2,'Knight',20,'Egypt'") 
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","3,'Fighter',30,'Japan'") 
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","4,'Lightning',40,'Turkey'")
DisplaySelect($hDatabase,"Identity","Id,Name,Age,Country")
MsiCloseHandle($hDatabase) ;Close MsiDB

$hDatabase = MsiOpenDatabase("MsiDB.Msi",1) ;1 Open MsiDB
;;UPDATE queries only work on nonprimary key columns. key columns ==> Id 
$SetColumnsList = "Name = 'Thunder',Age = 40,Country = 'France'"
UpdateRowData($hDatabase,"Identity",$SetColumnsList,"Id = 1")
$SetColumnsList = "Name = 'Spear',Age = 30,Country = 'India'"
UpdateRowData($hDatabase,"Identity",$SetColumnsList,"Id = 2")
$SetColumnsList = "Name = 'Flood',Age = 20,Country = 'Korea'"
UpdateRowData($hDatabase,"Identity",$SetColumnsList,"Id = 3")
$SetColumnsList = "Name = 'Star',Age = 10,Country = 'Russia'"
UpdateRowData($hDatabase,"Identity",$SetColumnsList,"Id = 4")
DisplaySelect($hDatabase,"Identity","Id,Name,Age,Country")
MsiCloseHandle($hDatabase) ;Close MsiDB


$hDatabase = MsiOpenDatabase("MsiDB.Msi",2) ;2 CREATE MsiDB
;Tables may not contain more than one column of type 'object'.
;UPDATE queries only work on nonprimary key columns. key columns ==> Id 
;Binary data cannot be inserted into a table directly using the 
;INSERT INTO or UPDATE SQL queries. For more information,
CreateTable($hDatabase,"Binary","Id INT,File OBJECT,String LONGCHAR","LOCALIZABLE PRIMARY KEY Id")
InsertInToTable($hDatabase,"Binary","Id,File,String","1,'','MsiDB'") ;Add Id 1 And Row 1 (Row Start From 1)
InsertInToTable($hDatabase,"Binary","Id,File,String","2,'','Autoit'") ;Add Id 2 And Row 2 (Row Start From 1)
DisplaySelect($hDatabase,"Binary","Id,File,String")
MsiCloseHandle($hDatabase) ;Close MsiDB

$hDatabase = MsiOpenDatabase("MsiDB.Msi",1) ;1 Open MsiDB
;Tables may not contain more than one column of type 'object'.
;UPDATE queries only work on nonprimary key columns. key columns ==> Id 
;Binary data cannot be inserted into a table directly using the 
;INSERT INTO or UPDATE SQL queries. For more information,
$SetColumnsList = "File = '',String = 'Autoit'"
UpdateRowData($hDatabase,"Binary",$SetColumnsList,"Id = 1")
$SetColumnsList = "File = '',String = 'MsiDB'"
UpdateRowData($hDatabase,"Binary",$SetColumnsList,"Id = 2")
DisplaySelect($hDatabase,"Binary","Id,File,String")
MsiCloseHandle($hDatabase) ;Close MsiDB

Example

Delete_Add

#Include "MsiDatabase.au3"
#Include <Array.au3>

$hDatabase = MsiOpenDatabase("MsiDB.Msi",2) ;2 CREATE MsiDB
CreateTable($hDatabase,"Identity","Id INT,Name LONGCHAR,Age INT,Country LONGCHAR","LOCALIZABLE PRIMARY KEY Id")
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","1,'Sword',10,'British'")
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","2,'Knight',20,'Egypt'") 
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","3,'Fighter',30,'Japan'") 
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","4,'Lightning',40,'Turkey'")
DisplaySelect($hDatabase,"Identity","Id,Name,Age,Country")
DeleteRowById($hDatabase,"Identity","Id = 2 OR Id = 4") ; Delete Row 2 And Row 4
DisplaySelect($hDatabase,"Identity","Id,Name,Age,Country")
MsiCloseHandle($hDatabase) ;Close MsiDB

$hDatabase = MsiOpenDatabase("MsiDB.Msi",2) ;2 CREATE MsiDB
CreateTable($hDatabase,"Identity","Id INT","LOCALIZABLE PRIMARY KEY Id")
ColumnAdd($hDatabase,"Identity","Name CHAR(100)")
ColumnAdd($hDatabase,"Identity","Age INT")
ColumnAdd($hDatabase,"Identity","Country CHAR(100)")
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","1,'Sword',10,'British'")
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","2,'Knight',20,'Egypt'") 
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","3,'Fighter',30,'Japan'") 
InsertInToTable($hDatabase,"Identity","Id,Name,Age,Country","4,'Lightning',40,'Turkey'")
DisplaySelect($hDatabase,"Identity","Id,Name,Age,Country")

TableRemove($hDatabase,"Identity")
$RT = DisplaySelect($hDatabase,"Identity","Id,Name,Age,Country")
MsgBox(0,"MSG","Return => " & $RT & @CRLF & "error => " &  @error & @CRLF & "extended => " & @extended)
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

@wolf9228

Good to see this got you inspired :D

Good job :graduated:

Rgds,

ptrex

Thank you :(

Get_Tables

Func Get_Tables($hDatabase)
Local $TablesArray[1]
$TQuery = "SELECT Name FROM _Tables"
$hView = MsiDatabaseOpenView($hDatabase,$TQuery)
if @error Then Return SetError(1,@error,0)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,0)
EndIf
$i = 0
While 1
$hRecord = MsiViewFetch($hView)
if @error Then ExitLoop
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,0)
EndIf
$VALUE = MsiRecordGetString($hRecord,1,$DataSize)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,0)
EndIf
$TablesArray[$i] = $VALUE
ReDim $TablesArray[$i + 2]
MsiCloseHandle($hRecord)
$i += 1
WEnd
ReDim $TablesArray[$i]
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(0,0,$TablesArray)
EndFunc

Get_Columns

Func Get_Columns($hDatabase,$Table)
Local $ColumnsArray[1]
$CQuery = "SELECT Name FROM _Columns WHERE `Table` = '" & $Table & "'"
$hView = MsiDatabaseOpenView($hDatabase,$CQuery)
if @error Then Return SetError(1,@error,0)
MsiViewExecute($hView)
if @error Then
$error = @error
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(2,$error,0)
EndIf
$i = 0
While 1
$hRecord = MsiViewFetch($hView)
if @error Then ExitLoop
$DataSize = MsiRecordDataSize($hRecord,1)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(3,$error,0)
EndIf
$VALUE = MsiRecordGetString($hRecord,1,$DataSize)
if @error Then
$error = @error
MsiCloseHandle($hRecord)
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(4,$error,0)
EndIf
$ColumnsArray[$i] = $VALUE
ReDim $ColumnsArray[$i + 2]
MsiCloseHandle($hRecord)
$i += 1
WEnd
ReDim $ColumnsArray[$i]
MsiViewClose($hView)
MsiCloseHandle($hView)
Return SetError(0,0,$ColumnsArray)
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Simple logic error in this function

;Returns the integer value from a record field.
;http://msdn.microsoft.com/en-us/library/aa370367(v=VS.85).aspx
Func MsiRecordGetInteger($hRecord,$iField)
$error = DllCall($MsiLibrary,"UINT","MsiRecordGetInteger","UINT",$hRecord,"UINT",$iField)
if @error Then Return SetError(1,0,0)
Return SetError($error[0] == 0,0,$error[0])
EndFunc

Function corrected

;Returns the integer value from a record field.
;http://msdn.microsoft.com/en-us/library/aa370367(v=VS.85).aspx
;The MsiRecordGetInteger function returns MSI_NULL_INTEGER if the 
;field is null or if the field is a string that cannot be converted 
;to an integer.
; If the function succeeds, the return value is the integer value of the field.
Func MsiRecordGetInteger($hRecord,$iField)
$MSI_NULL_INTEGER = - 0x80000000
$error = DllCall($MsiLibrary,"UINT","MsiRecordGetInteger","UINT",$hRecord,"UINT",$iField)
if @error Then Return SetError(1,0,0)
if $MSI_NULL_INTEGER = $error[0] Then Return SetError(2,$MSI_NULL_INTEGER,0)
Return SetError(0,0,$error[0])
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Project interpreter for the language C ++

All project files

Edited by wolf9228

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0