Sign in to follow this  
Followers 0
WSorich

[solved] Passing parameters using DllCall to a C++ dll

20 posts in this topic

#1 ·  Posted (edited)

Hello, I am looking for some advice on calling a function in a DLL.

The background is that the DLL has been written in C++ and I have the code of the dll.

The function of the DLL is to provide connection,disconnection and statement/select queries direct to a Firebird/Interbase database.

I have been able to call the DLL using the following for a connection, and it works

;------------------------------

;Main

$h_fbdll = Dllopen("fbdll4vb20.dll")

$result = _connectDB($h_fbdll,$TLSHO_Server,$TLSHO_DBName,$TLSHO_User,$TLSHO_Pass)

;------------------------------

Func _connectDB($f_handle,$f_servername,$f_dbname,$f_user,$f_password)

Local $f_result

$f_result = DllCall($f_handle, "int", "ConnectDatabase", "str", $f_servername, "str", $f_dbname, "str", $f_user, "str", $f_password)

MsgBox(0,"Debug","Attempt to connect to database returned error code : "&@error)

Return

EndFunc

;------------------------------

The corresonding information I have from the C++ code for the ConnectDatabase function shows

//Connects to a database . Only dialect 3 database supported

NOMANGLE bool CCONV ConnectDatabase(char *ServerName, char *DbName, char *UserName, char *Password)

And assistance has also been provided in the dll package that shows a VB equivalent for the call

Public Declare Function ConnectDatabase Lib "..\bin\fbdll4vb20.dll" (ByVal servername As String, ByVal dbname As String, ByVal username As String, ByVal password As String) As Boolean

So now we come to the issue....

I can use AutoIT DllCall to call the ConnectDB function in the dll,

I can use AutoIT DllCall to call the DisconnectDB function in the dll,

But I Cant seem to figure out how to use ExecuteSelect in the dll.

I'll show you what I have ...

The C++ Code shows this as the header to the function

NOMANGLE int CCONV ExecuteSelect(char *dmlCommand, BSTR *buffer, int *retlen)

And the Help in another part of the C++ code says

help += "- ExecuteSelect(Select,Buffer,ReturnLen) as Long => Executes a Select statement and returns XML dataset to buffer and recordcount.\n";

The VB example shows this

Public Declare Function ExecuteSelect Lib "..\bin\fbdll4vb20.dll" (ByVal dmlCommand As String, ByRef retVal As String, retlen As Long) As Long

Here is my AutoIT code to try and get this to go....I am trying to display the results in the function at this time.

CODE
;------------------------------

$result = _executeSelect($h_fbdll,"SELECT * FROM TABLE")

Exit

;------------------------------

Func _executeSelect($f_handle,$f_statement)

Local $f_result

Local $f_retlen = 65534

Local $f_str

Local $f_buffer

Local $f_buffer_pointer

$f_str = "char[65535]"

$f_buffer = DllStructCreate($f_str)

If @error Then

MsgBox(0,"","Error in DllStructCreate :" & @error);

Exit

EndIf

$f_buffer_pointer= DllStructGetPtr($f_buffer)

$f_result = DllCall($f_handle, "int", "ExecuteSelect2", "str", $f_statement,"ptr", $f_buffer_pointer, "long", $f_retlen)

MsgBox(0,"Debug","Attempt to execute select returned error code : "&@error)

MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($f_buffer) & @CRLF & _

"Struct pointer: " & DllStructGetPtr($f_buffer) & @CRLF & _

"Data:" & @CRLF & _

DllStructGetData($f_buffer,1) & @CRLF & _

DllStructGetData($f_buffer,2) & @CRLF & _

DllStructGetData($f_buffer,3) & @CRLF & _

DllStructGetData($f_buffer,4) & @CRLF & _

DllStructGetData($f_buffer,5) & @CRLF & _

DllStructGetData($f_buffer,6) & @CRLF & _

DllStructGetData($f_buffer,7) & @CRLF & _

DllStructGetData($f_buffer,8))

Return $f_result

EndFunc

;------------------------------

It seems as though that I need to pass a pointer to a buffer for the C++ code to populate, and then read the buffer area to find out what the results were. Am I making a big mistake here?

I'm not a VB person or a C++ person, so I have no real idea as to how the ByRef and ByVal statements should be implemented in AutoIT.

Can anyone shed some light on how my code should be modified to allow a correct call and ability to read the data back?

Kind Regards, Wal.

Edited by WSorich

Share this post


Link to post
Share on other sites



$f_result = DllCall($f_handle, "int", "ExecuteSelect2", "str", $f_statement,"ptr", $f_buffer_pointer, "long", $f_retlen)

Did you mean to have a 2 on the function name?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$f_result = DllCall($f_handle, "int", "ExecuteSelect2", "str", $f_statement,"ptr", $f_buffer_pointer, "long", $f_retlen)

Did you mean to have a 2 on the function name?

Actually there are two entry points and the code I showed had the 2.

I have changed it back to "ExecuteSelect" for the purposes of this question.

When I ran it again with the change there was no change in result.

Do you see anything else?

Regards, Wal.

Edited by WSorich

Share this post


Link to post
Share on other sites

Wasn't sure if that was a typo or not. It was just the most obvious.

The VB example is actually wrong I think... It is declaring long but the expected value type is int. Is it VB or VB.Net?

I'm not sure but I also think you are using DllStructGetData wrong. Just call it once for data item 1. DllStructGetData($f_buffer, 1)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Wasn't sure if that was a typo or not. It was just the most obvious.

The VB example is actually wrong I think... It is declaring long but the expected value type is int. Is it VB or VB.Net?

I'm not sure but I also think you are using DllStructGetData wrong. Just call it once for data item 1. DllStructGetData($f_buffer, 1)

I think that the VB example may be VB5, the site that the DLL comes from "http://fbdll4vb.sourceforge.net/" reports

"C++ Dll to be used in Visual Basic 5/6 (or any tool that can use a Win32 Dll, NOT COM)

to access a Firebird database directly. Uses IBPPs library. "

I also modified the code section you suggested, with no luck.

It now looks like this;

CODE
;------------------------------

$result = _executeSelect($h_fbdll,"SELECT * FROM TABLE")

Exit

;------------------------------

Func _executeSelect($f_handle,$f_statement)

Local $f_result

Local $f_retlen = 65534

Local $f_str

Local $f_buffer

Local $f_buffer_pointer

$f_str = "char[65535]"

$f_buffer = DllStructCreate($f_str)

If @error Then

MsgBox(0,"","Error in DllStructCreate :" & @error);

Exit

EndIf

$f_buffer_pointer= DllStructGetPtr($f_buffer)

$f_result = DllCall($f_handle, "int", "ExecuteSelect", "str", $f_statement,"ptr", $f_buffer_pointer, "long", $f_retlen)

MsgBox(0,"Debug","Attempt to execute select returned error code : "&@error)

MsgBox(0,"DllStruct","Struct Size: " & DllStructGetSize($f_buffer) & @CRLF & _

"Struct pointer: " & DllStructGetPtr($f_buffer) & @CRLF & _

"Data:" & @CRLF & DllStructGetData($f_buffer,1))

Return $f_result

EndFunc

;------------------------------

Edited by WSorich

Share this post


Link to post
Share on other sites

I had a thought about this code section

$f_result = DllCall($f_handle, "int", "ExecuteSelect", "str", $f_statement,"ptr", $f_buffer_pointer, "long", $f_retlen)

when comparing it to the C++ function header

NOMANGLE int CCONV ExecuteSelect(char *dmlCommand, BSTR *buffer, int *retlen)

the VB example code provided with the dll is

Public Declare Function ExecuteSelect Lib "..\bin\fbdll4vb20.dll" (ByVal dmlCommand As String, ByRef retVal As String, retlen As Long) As Long

Let me eliminate the autoit DllCall parameters piece by piece..

The syntax of DllCall shows

DllCall ( "dll", "return type", "function" [, "type1", param1 ,"type2",param2[, "type n", param n]] )

dll = $f_handle as derived from a DllOpen for the dll I am addressing, and this works elsewhere in my code to call the db connect function. So lets leave this.

return type = "int" = Return type, Hmm, the VB example uses As Long at the end of the statement, so I'll change this to long in AutoIT, although is the C++ code telling me it is returning an int?

function = "ExecuteSelect". This is determined from the C++ function where it lists the names. I have derived the connectdb and disconnectdb function names in the same way and verified with the VB example. I think that this is correct so lets leave this.

type1,param1 = "str", $f_statement. "str" is the type string and $f_statement is a variable that contains the string "SELECT * FROM TABLE"

Now, in the VB example, the statement "ByVal dmlcommand as string" is used, so I am assuming that this means that I am just passing the string. Nothing special here, and this seems to work because the dll, when I issue the debug mode trigger, seems to report back in a msgbox that the command about to be issued is..."Select * from TABLE" so lets leave this.

type2,param2 = "ptr", $f_buffer_pointer... I have no real idea here... I guessed that autoit is supposed to pass a pointer to the variable so that the C++ dll can populate the memory that the pointer is pointing to... but am I correct? I also tried...

"str*",$buffer and just setup $buffer as Global $buffer="0".

This area is the main problem.. I think we are expecting a reply from the dll call to have a XML structure returned. Can anyone help here?

type3,param3 = "long", $f_retlen, looking at the VB setup, the best bet I can make is that this is a variable of type long that is neede. But I dont know if we are expected to pass a value here?.. Do I need to know the expected length of an SQL query select statement reply before I know the answer? Need help here too..

Anyway, I'm hoping to figure this all out as soon as possible, so I'll keep working on it and adding coments here in the hope that if the problem is solved, that it will be a reference for the rest. Cheers. Wal.

Share this post


Link to post
Share on other sites

"long" and "int" are the same in C++. In VB, "int" is only two bytes so it has to be "long". I believe your problem stems from the nasty BSTR* lurking in the function call. I would guess that the results of the command are being returned here. BSTR* is a pointer to a wide string. Try something along the following lines:

$f_result = DllCall($f_handle, "int", "ExecuteSelect", "str", $f_statement,"ptr", 0, "long", 0)oÝ÷ Ù.q©íéî±í7éúÞ²émÙ©ÝÓ~­ë.Ýí¢­¶jÖiÉ
¢×­«tߧëzË¥·|"Zh{m¡©âÜ!ÈmzYlÊ¡£   '!j¶µêìj·¢Ø^­ën®{-®)àÓ~­ë.Ý¢±ªh{^®ÚÂ'^r«iË^®Ëkx,£*.(!¶Úòjëh×6$hRetString = DllStructCreate("wchar[65535]", $f_result[2])
MsgBox(64, "Result?", DllStructGetData($hRetString, 1))

HTH

WBD

Share this post


Link to post
Share on other sites

The weird thing about BSTR is that the four byte integer prefix isn't pointed to by the BSTR itself; you can still use BSTR the same as you could wchar_t*. The four bytes IIRC indicate the length of the string.

WBD

Share this post


Link to post
Share on other sites

Yes, they are the length. I wonder why it couldn't just use a regular character pointer (array) with a null terminator and a length as a separate parameter like normal functions.

Share this post


Link to post
Share on other sites

"long" and "int" are the same in C++. In VB, "int" is only two bytes so it has to be "long". I believe your problem stems from the nasty BSTR* lurking in the function call. I would guess that the results of the command are being returned here. BSTR* is a pointer to a wide string. Try something along the following lines:

$f_result = DllCall($f_handle, "int", "ExecuteSelect", "str", $f_statement,"ptr", 0, "long", 0)
$hRetString = DllStructCreate("wchar[65535]", $f_result[2])
MsgBox(64, "Result?", DllStructGetData($hRetString, 1))
This has blown my mind a little, can I step through the above and have you correct me where needed.

In your example we do a DllCall with the settings "ptr",0 and "long",0.

I thought this was where the DllCall was passing the pointer to a structure (wchar[65535]) we have already created, so the ExecuteSelect function in the dll uses this pointer to dump the data into the structure. Then, when the DllCall returns, we just look at that structure and get the info out?

P.S I'll lay off the colours for a while. :)

Share this post


Link to post
Share on other sites

You should try something like this:

$hDll = DllOpen("that.dll")
$sStatement = "...whatever"

$aCall = DllCall($hDll, "int", "ExecuteSelect", _
        "str", $sStatement, _
        "str", "", _; try "wstr" too
        "dword*", 0)

;...checking errors...

$sReturned = $aCall[2]
$iReturned = $aCall[3]

That code have limitation on size of buffer that receives data and... it's kind of confusing in information you provided what would be correct types so play with str and wstr

In case BSTR is needed you need to create buffer before you make a call. Like this maybe:

$hDll = DllOpen("that.dll")
$sStatement = "...whatever"
$tBSTR = DllStructCreate("dword Length;" & _
        "wchar String[65536]")

$aCall = DllCall($hDll, "int", "ExecuteSelect", _
        "str", $sStatement, _
        "ptr", DllStructGetPtr($tBSTR), _
        "dword*", 0)

;...checking errors...

$sReturned = DllStructGetData($tBSTR, "String")
$iReturned = $aCall[3]

That $tBSTR is not caring for alignment nor null-terminators because default truncation is done by AutoIt when collecting data out of wchar/char buffers. All that you should check is that the buffer is big enough.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Hello everyone,

Thanks for all your constructive feedback so far.

I have tried all the suggestions posted here, and have been working hard to figure out why none of them have worked.

As such, I got a friend to load one of the example programs from the C++ Dll package into VB6 and extract the code segment for executing a select statement. I have added it here for further discussion...

I think that the line "Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument" may shed some light on why I have not been able to get results??

Can anyone translate this code into a suitable AutoIT equivalent?

CODE

' VB6 code

Private Sub Command4_Click()

Dim rv As Boolean

Dim rcount As Long

Dim rlen As Long

Dim result As String

Dim xmldoc As Object

result = Space(1)

Screen.MousePointer = vbHourglass

SetDebug True

rv = ConnectDatabase("localhost", "c:\icelive\ice.fdb", "SYSDBA", pwd)

rcount = ExecuteSelect("SELECT * FROM TABLE", result, rlen)

Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument")

xmldoc.async = False

Screen.MousePointer = vbDefault

If (Not xmldoc.loadXML(result)) Then

MsgBox "Response is not a valid XML document", vbCritical, "Error parsing Response"

Else

MsgBox "Response is a valid XML document." & vbCrLf & "Records retrieved: " & rcount & vbCrLf & "Open the " & App.Path & "\test.xml file.", vbInformation, "Response"

End If

Open App.Path & "\test.xml" For Output As #1

Print #1, result

Close #1

rv = DisConnectDatabase()

End Sub

Cheers, Wal.

Edited by WSorich

Share this post


Link to post
Share on other sites

Hello everyone,

Thanks for all your constructive feedback so far.

I have tried all the suggestions posted here, and have been working hard to figure out why none of them have worked.

As such, I got a friend to load one of the example programs from the C++ Dll package into VB6 and extract the code segment for executing a select statement. I have added it here for further discussion...

I think that the line "Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument" may shed some light on why I have not been able to get results??

Can anyone translate this code into a suitable AutoIT equivalent?

CODE

' VB6 code

Private Sub Command4_Click()

Dim rv As Boolean

Dim rcount As Long

Dim rlen As Long

Dim result As String

Dim xmldoc As Object

result = Space(1)

Screen.MousePointer = vbHourglass

SetDebug True

rv = ConnectDatabase("localhost", "c:\icelive\ice.fdb", "SYSDBA", pwd)

rcount = ExecuteSelect("SELECT * FROM TABLE", result, rlen)

Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument")

xmldoc.async = False

Screen.MousePointer = vbDefault

If (Not xmldoc.loadXML(result)) Then

MsgBox "Response is not a valid XML document", vbCritical, "Error parsing Response"

Else

MsgBox "Response is a valid XML document." & vbCrLf & "Records retrieved: " & rcount & vbCrLf & "Open the " & App.Path & "\test.xml file.", vbInformation, "Response"

End If

Open App.Path & "\test.xml" For Output As #1

Print #1, result

Close #1

rv = DisConnectDatabase()

End Sub

Cheers, Wal.
If you say that VB6 code is working and part of it related to posted problem is this:

Dim rcount As Long
Dim rlen As Long
Dim result As String
result = Space(1)
rcount = ExecuteSelect("SELECT * FROM TABLE", result, rlen)

MsgBox "Response is a valid XML document." & vbCrLf & "Records retrieved: " & rcount & vbCrLf & ...

Then I fail to see how this fails:

$hDll = DllOpen("...\fbdll4vb20.dll")
$sStatement = "SELECT * FROM TABLE"

$aCall = DllCall($hDll, "int", "ExecuteSelect", _
        "str", $sStatement, _
        "str", " ", _
        "dword*", 0)

;...check errors!

$sReturned = $aCall[2]; this should be what you need

The only difference is " " (space).

But... sometimes I fail to see even more obvious things so... nothing :)


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

If you say that VB6 code is working and part of it related to posted problem is this:

Dim rcount As Long
Dim rlen As Long
Dim result As String
result = Space(1)
rcount = ExecuteSelect("SELECT * FROM TABLE", result, rlen)

MsgBox "Response is a valid XML document." & vbCrLf & "Records retrieved: " & rcount & vbCrLf & ...

Then I fail to see how this fails:

$hDll = DllOpen("...\fbdll4vb20.dll")
$sStatement = "SELECT * FROM TABLE"

$aCall = DllCall($hDll, "int", "ExecuteSelect", _
        "str", $sStatement, _
        "str", " ", _
        "dword*", 0)

;...check errors!

$sReturned = $aCall[2]; this should be what you need

The only difference is " " (space).

But... sometimes I fail to see even more obvious things so... nothing :)

Hi, thanks for your reply, I did test the code segment that you indicated above and it does return a result.

$aCall [0] = 0, $aCall[1]= "SELECT * FROM TABLE", $aCall[2]=" ", $aCall[3]=0

So, I am thinking that the reason for this is that the DLLCall returns a different structure?

I have only managed to get the actual VB code example recently which shows the line that leads me to think there is some special XML structure.

Set xmldoc = CreateObject("MSXML2.FreeThreadedDOMDocument")

So now I am persuing a conversion of the VB code that I know works.

Share this post


Link to post
Share on other sites

Here is some working code (with the embedded version )

ExecuteStatement returns pointers for both the "BSTR" and the len of the buffer.

#include-once
; #INDEX# ====================================================================
; Title .........: _FireBird.au3
; Description ...: FireBird, Interbase dll udf.
; Author ........: Stephen Podhajecki (Eltorro)
; ==============================================================================

; #VARIABLES# ================================================================
Global $gs_fbDll
; ================================================================================

; #CURRENT# ======================================================================
;_FireBird_Check
;_FireBird_About
;_FireBird_SetDebug
;_FireBird_CreateDatabase
;_FireBird_SetPageBuffers
;_FireBird_ConnectDatabase
;_FireBird_DisConnectDatabase
;_FireBird_ExecuteBatch
;_FireBird_ExecuteSelect
;_FireBird_ExecuteStatement
;_FireBird_Help
; ================================================================================

; #INTERNAL_USE_ONLY# ============================================================
;__FireBird_GetBstr
; ================================================================================

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_Check
; Description ...: Test function returns the same value given.
; Syntax ........: _FireBird_Check($iCheck)
; Parameters ....: $iCheck - IN -
; Return values .: Success - $iCheck
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_Check($iCheck)
    Local $vRet = DllCall($gs_fbDll, "int", "Check", "long", $iCheck)
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_Check

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_About
; Description ...: Shows about message
; Syntax ........: _FireBird_About()
; Parameters ....: None.
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_About()
    Local $vRet = DllCall($gs_fbDll, "none", "About")
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_About

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_SetDebug
; Description ...: Turns debugging on or off
; Syntax ........: _FireBird_SetDebug($xdebug)
; Parameters ....: $fDebug - IN True or false
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_SetDebug($fDebug)
    Local $vRet = DllCall($gs_fbDll, "int", "SetDebug", "int", $fDebug)
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_SetDebug

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_CreateDatabase
; Description ...: Creates a database
; Syntax ........: _FireBird_CreateDatabase($sServerName, $sDBName, $sUsername, $sPassword, $iWriteMode = 1,$iDialect = 3)
; Parameters ....: $sServerName - IN -
;                  $sDBName - IN -
;                  $sUsername - IN -
;                  $sPassword - IN -
;                  $iWriteMode - IN/OPTIONAL -
;                 $iDialect  - IN/OPTIONAL -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_CreateDatabase($sServerName, $sDBName, $sUsername, $sPassword, $iWriteMode,$iDialect = 3)
    Local $tagfbCreate = "char[%d];char[%d];char[%d];char[%d]"
    $tagfbCreate = StringFormat($tagfbCreate, StringLen($sServerName) + 1, StringLen($sDBName) + 1, StringLen($sUsername) + 1, StringLen($sPassword) + 1, $iWriteMode = 1,$iDialect =3)
    Local $t_fbCreate = DllStructCreate($tagfbCreate)
    DllStructSetData($t_fbCreate, 1, $sServerName)
    DllStructSetData($t_fbCreate, 2, $sDBName)
    DllStructSetData($t_fbCreate, 3, $sUsername)
    DllStructSetData($t_fbCreate, 4, $sPassword)
    Local $vRet = DllCall($gs_fbDll, "int", "CreateDatabase", "ptr", DllStructGetPtr($t_fbCreate, 1), "ptr", DllStructGetPtr($t_fbCreate, 2), "ptr", DllStructGetPtr($t_fbCreate, 3), "ptr", DllStructGetPtr($t_fbCreate, 4), "int", $iWriteMode, "int",$iDialect)
    $t_fbCreate = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_CreateDatabase

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_SetPageBuffers
; Description ...: Sets the page buffers when creating a database.
; Syntax ........: _FireBird_SetPageBuffers($a)
; Parameters ....: $iSize - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_SetPageBuffers($iSize)
    Local $vRet = DllCall($gs_fbDll, "int", "SetPageBuffers", "int", $iSize)
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_SetPageBuffers

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ConnectDatabase
; Description ...: Connect to a database.
; Syntax ........: _FireBird_ConnectDatabase($sDBName, $sUsername, $sPassword)
; Parameters ....: $sDBName - IN -
;                  $sUsername - IN -
;                  $sPassword - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ConnectDatabase($sDBName, $sUsername, $sPassword)
    Local $tagfbCreate = "char[%d];char[%d];char[%d]"
    $tagfbCreate = StringFormat($tagfbCreate, StringLen($sDBName) + 1, StringLen($sUsername) + 1, StringLen($sPassword) + 1)
    Local $t_fbCreate = DllStructCreate($tagfbCreate)
    DllStructSetData($t_fbCreate, 1, $sDBName)
    DllStructSetData($t_fbCreate, 2, $sUsername)
    DllStructSetData($t_fbCreate, 3, $sPassword)
    Local $vRet = DllCall($gs_fbDll, "int", "ConnectDatabase", "ptr", DllStructGetPtr($t_fbCreate, 1), "ptr", DllStructGetPtr($t_fbCreate, 2), "ptr", DllStructGetPtr($t_fbCreate, 3))
    $t_fbCreate = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ConnectDatabase

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_DisConnectDatabase
; Description ...: Disconnect from the database
; Syntax ........: _FireBird_DisConnectDatabase()
; Parameters ....: None.
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_DisConnectDatabase()
    Local $vRet = DllCall($gs_fbDll, "int", "DisConnectDatabase")
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_DisConnectDatabase

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ExecuteBatch
; Description ...: Do a batch execution of statements
; Syntax ........: _FireBird_ExecuteBatch($sCmd)
; Parameters ....: $sCmd - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ExecuteBatch($sCmd)
    Local $t_ExeBatch = DllStructCreate("char[" & StringLen($sCmd) + 1 & "]")
    DllStructSetData($t_ExeBatch, 1, $sCmd)
    Local $vRet = DllCall($gs_fbDll, "int", "ExecuteBatch", "ptr", DllStructGetPtr($t_ExeBatch))
    $t_ExeBatch = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ExecuteBatch

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ExecuteSelect
; Description ...: Executes an SQL query.
; Syntax ........: _FireBird_ExecuteSelect($sCmd, ByRef $sResult)
; Parameters ....: $sCmd - IN -
;                  $sResult - IN/OUT -
; Return values .: Success - Record count
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ExecuteSelect($sCmd, ByRef $sResult)
    Local $t_ExeSelect = DllStructCreate("char[" & StringLen($sCmd) + 1 & "];uint;uint")
    DllStructSetData($t_ExeSelect, 1, $sCmd)
    Local $vRet = DllCall($gs_fbDll, "int", "ExecuteSelect", "ptr", DllStructGetPtr($t_ExeSelect, 1), "ptr", DllStructGetPtr($t_ExeSelect, 2), "ptr", DllStructGetPtr($t_ExeSelect, 3))
    $sResult = __FireBird_GetBstr(DllStructGetData($t_ExeSelect, 2), DllStructGetData($t_ExeSelect, 3))
    $t_ExeSelect = 0
    Return SetError( $vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ExecuteSelect

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ExecuteStatement
; Description ...: Execute an SQL statement
; Syntax ........: _FireBird_ExecuteStatement($sCmd)
; Parameters ....: $sCmd - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ExecuteStatement($sCmd)
    Local $t_ExeStatement = DllStructCreate("char[" & StringLen($sCmd) + 1 & "]")
    DllStructSetData($t_ExeStatement, 1, $sCmd)
    Local $vRet = DllCall($gs_fbDll, "int", "ExecuteStatement", "ptr", DllStructGetPtr($t_ExeStatement, 1))
    $t_ExeStatement = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ExecuteStatement

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_Help
; Description ...: Shows help dialog
; Syntax ........: _FireBird_Help()
; Parameters ....: None.
; Return values .: 
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_Help()
    Local $vRet = DllCall($gs_fbDll, "none", "Help")
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_Help

; #INTERNAL_USE_ONLY# ============================================================
; Name ..........: __FireBird_GetBstr
; Description ...: 
; Syntax ........: __FireBird_GetBstr($ptr, $len)
; Parameters ....: $ptr - IN -
;                  $len - IN -
; Return values .: 
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......: 
; Remarks .......: 
; Related .......: 
; Link ..........: http://fbdll4vb.sourceforge.net/
; ================================================================================
Func __FireBird_GetBstr($ptr, $len)
    Local $t_ret = DllStructCreate("char[" & $len & "]", $ptr)
    Local $vRet = DllStructGetData($t_ret, 1)
    $t_ret = 0
    ;ConsoleWrite($vRet)
    Return $vRet
EndFunc   ;==>__FireBird_GetBstr

Some tests.

#include "_FireBird.au3"
 $gs_fbDll = DllOpen(@ScriptDir & "\emfbdll4vb20.dll")
_FireBird_About()
_FireBird_Help()

MsgBox(0, "Check", _FireBird_Check(3))
MsgBox(0, "SetDebug", _FireBird_SetDebug(True))
MsgBox(0, "CreateDatabase", _FireBird_CreateDatabase("", "c:\test3.fdb", "SYSDBA", "masterkey", 1, 3))

TestCreate()
If @error Then
    MsgBox(266288, "Error", @extended)
    DllClose($gs_fbDll)
    Exit
EndIf

TestSelect()
DllClose($gs_fbDll)
Exit

Func TestCreate()
    Local $rv = _FireBird_ConnectDatabase("c:\test3.fdb", "SYSDBA", "masterkey")
    If Not $rv Then Return SetError(1, 0, 0)
    If $rv Then
        $rv = _FireBird_ExecuteStatement("DROP TABLE test")
        $rv = _FireBird_ExecuteStatement("CREATE TABLE test (integer_fld integer not null primary key," _
                 & "varchar40_fld varchar (40), " _
                 & "varchar50_fld varchar (50), " _
                 & "char4_fld char(4), " _
                 & "char20_fld char(20), " _
                 & "date_fld date, " _
                 & "integer2_fld integer, " _
                 & "numeric5_2_fld numeric(5,2), " _
                 & "numeric8_2_fld numeric(8,2), " _
                 & "numeric16_4_fld numeric(16,4), " _
                 & "decimal5_2_fld decimal(5,2), " _
                 & "decimal8_2_fld decimal(8,2), " _
                 & "decimal16_4_fld decimal(16,4), " _
                 & "double_precision_fld double precision, " _
                 & "float_fld float, " _
                 & "smallint_fld smallint, " _
                 & "time_field time, " _
                 & "timestamp_field timestamp, " _
                 & "blob_fld blob, " _
                 & "html varchar (100) " _
                 & ") ")

        $rv = _FireBird_ExecuteStatement("CREATE GENERATOR " & Chr(34) & "test_seq" & Chr(34))
        If Not $rv Then Return SetError(1, 2, 0)

        Local $trigger = "CREATE TRIGGER " & Chr(34) & "TRG_INTEGER_TEST" & Chr(34) & " FOR " & Chr(34) & "TEST" & Chr(34) & @CRLF _
                 & "ACTIVE BEFORE INSERT POSITION 0 " & @CRLF _
                 & "AS" & @CRLF _
                 & "BEGIN" & @CRLF _
                 & " new.integer_fld = gen_id(" & Chr(34) & "test_seq" & Chr(34) & ", 1);" & @CRLF _
                 & "END"

        $rv = _FireBird_ExecuteStatement($trigger)
        If Not $rv Then Return SetError(1, 3, 0)
        MsgBox(0, "CreateTest", $rv)
    EndIf

    $rv = _FireBird_DisConnectDatabase()
EndFunc  ;==>TestCreate

Func TestSelect()
    Local $rv, $rcount, $result, $xmldoc
    _FireBird_SetDebug(True)
    $rv = _FireBird_ConnectDatabase("c:\test3.fdb", "SYSDBA", "masterkey")
    If $rv Then
        $rcount = _FireBird_ExecuteSelect("SELECT * FROM test", $result)

        $xmldoc = ObjCreate("MSXML2.FreeThreadedDOMDocument")
        $xmldoc.async = False

        If (Not $xmldoc.loadXML($result)) Then
            MsgBox(0, "Error parsing Response", "Response is not a valid XML document")
        Else
            MsgBox(0, "Response", "Response is a valid XML document." & @CRLF & "Records retrieved: " & $rcount & @CRLF & "Open the " & @ScriptDir & "\test.xml file.")
            FileWrite(@ScriptDir & "\test.xml", $result)
        EndIf
        $xmldoc = 0
        _FireBird_DisConnectDatabase()
    EndIf
EndFunc  ;==>TestSelect

I did not test _FireBird_ExecuteBatch.

Share this post


Link to post
Share on other sites

Thanks for the code segment. I have adjusted your code in the following way.

I do need to use the version that connects to a database, not the embedded version,

so I changed the _Firebird.au include file like this.

CODE
#include-once

; #INDEX# ====================================================================

; Title .........: _FireBird.au3

; Description ...: FireBird, Interbase dll udf.

; Author ........: Stephen Podhajecki (Eltorro)

; ==============================================================================

; #VARIABLES# ================================================================

;Global $gs_fbDll

; ================================================================================

; #CURRENT# ======================================================================

;_FireBird_Check

;_FireBird_About

;_FireBird_SetDebug

;_FireBird_CreateDatabase

;_FireBird_SetPageBuffers

;_FireBird_ConnectDatabase

;_FireBird_DisConnectDatabase

;_FireBird_ExecuteBatch

;_FireBird_ExecuteSelect

;_FireBird_ExecuteStatement

;_FireBird_Help

; ================================================================================

; #INTERNAL_USE_ONLY# ============================================================

;__FireBird_GetBstr

; ================================================================================

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_Check

; Description ...: Test function returns the same value given.

; Syntax ........: _FireBird_Check($iCheck)

; Parameters ....: $iCheck - IN -

; Return values .: Success - $iCheck

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_Check($gs_fbDll,$iCheck)

Local $vRet = DllCall($gs_fbDll, "int", "Check", "long", $iCheck)

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_Check

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_About

; Description ...: Shows about message

; Syntax ........: _FireBird_About()

; Parameters ....: None.

; Return values .: Success - 1

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_About($gs_fbDll)

Local $vRet = DllCall($gs_fbDll, "none", "About")

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_About

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_SetDebug

; Description ...: Turns debugging on or off

; Syntax ........: _FireBird_SetDebug($xdebug)

; Parameters ....: $fDebug - IN True or false

; Return values .: Success - 1

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_SetDebug($gs_fbDll,$fDebug)

Local $vRet = DllCall($gs_fbDll, "int", "SetDebug", "int", $fDebug)

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_SetDebug

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_CreateDatabase

; Description ...: Creates a database

; Syntax ........: _FireBird_CreateDatabase($sServerName, $sDBName, $sUsername, $sPassword, $iWriteMode = 1,$iDialect = 3)

; Parameters ....: $sServerName - IN -

; $sDBName - IN -

; $sUsername - IN -

; $sPassword - IN -

; $iWriteMode - IN/OPTIONAL -

; $iDialect - IN/OPTIONAL -

; Return values .: Success - 1

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_CreateDatabase($gs_fbDll,$sServerName, $sDBName, $sUsername, $sPassword, $iWriteMode,$iDialect = 3)

Local $tagfbCreate = "char[%d];char[%d];char[%d];char[%d]"

$tagfbCreate = StringFormat($tagfbCreate, StringLen($sServerName) + 1, StringLen($sDBName) + 1, _

StringLen($sUsername) + 1, StringLen($sPassword) + 1, $iWriteMode = 1,$iDialect =3)

Local $t_fbCreate = DllStructCreate($tagfbCreate)

DllStructSetData($t_fbCreate, 1, $sServerName)

DllStructSetData($t_fbCreate, 2, $sDBName)

DllStructSetData($t_fbCreate, 3, $sUsername)

DllStructSetData($t_fbCreate, 4, $sPassword)

Local $vRet = DllCall($gs_fbDll, "int", "CreateDatabase", "ptr", DllStructGetPtr($t_fbCreate, 1), _

"ptr", DllStructGetPtr($t_fbCreate, 2), _

"ptr", DllStructGetPtr($t_fbCreate, 3), _

"ptr", DllStructGetPtr($t_fbCreate, 4), _

"int", $iWriteMode, "int",$iDialect)

$t_fbCreate = 0

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_CreateDatabase

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_SetPageBuffers

; Description ...: Sets the page buffers when creating a database.

; Syntax ........: _FireBird_SetPageBuffers($a)

; Parameters ....: $iSize - IN -

; Return values .: Success - 1

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_SetPageBuffers($gs_fbDll,$iSize)

Local $vRet = DllCall($gs_fbDll, "int", "SetPageBuffers", "int", $iSize)

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_SetPageBuffers

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_ConnectDatabase

; Description ...: Connect to a database.

; Syntax ........: _FireBird_ConnectDatabase($sDBName, $sUsername, $sPassword)

; Parameters ....: $sDBName - IN -

; $sUsername - IN -

; $sPassword - IN -

; Return values .: Success - 1

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

; ================================================================================

;Func _FireBird_ConnectDatabase($sDBName, $sUsername, $sPassword)

; Local $tagfbCreate = "char[%d];char[%d];char[%d]"

; $tagfbCreate = StringFormat($tagfbCreate, StringLen($sDBName) + 1, StringLen($sUsername) + 1, StringLen($sPassword) + 1)

; Local $t_fbCreate = DllStructCreate($tagfbCreate)

; DllStructSetData($t_fbCreate, 1, $sDBName)

; DllStructSetData($t_fbCreate, 2, $sUsername)

; DllStructSetData($t_fbCreate, 3, $sPassword)

; Local $vRet = DllCall($gs_fbDll, "int", "ConnectDatabase", "ptr", DllStructGetPtr($t_fbCreate, 1), "ptr", DllStructGetPtr($t_fbCreate, 2), "ptr", DllStructGetPtr($t_fbCreate, 3))

; $t_fbCreate = 0

; Return SetError($vRet[0] <> 0, 0, $vRet[0])

;EndFunc ;==>_FireBird_ConnectDatabase

Func _FireBird_ConnectDatabase($gs_fbDll, $sServerName, $sDBName, $sUsername, $sPassword)

Local $tagfbCreate = "char[%d];char[%d];char[%d];char[%d]"

$tagfbCreate = StringFormat($tagfbCreate, StringLen($sServerName) + 1, StringLen($sDBName) + 1, StringLen($sUsername) + 1, StringLen($sPassword) + 1)

Local $t_fbCreate = DllStructCreate($tagfbCreate)

DllStructSetData($t_fbCreate, 1, $sServerName)

DllStructSetData($t_fbCreate, 2, $sDBName)

DllStructSetData($t_fbCreate, 3, $sUsername)

DllStructSetData($t_fbCreate, 4, $sPassword)

Local $vRet = DllCall($gs_fbDll, "int", "ConnectDatabase", "ptr", DllStructGetPtr($t_fbCreate, 1), _

"ptr", DllStructGetPtr($t_fbCreate, 2), _

"ptr", DllStructGetPtr($t_fbCreate, 3), _

"ptr", DllStructGetPtr($t_fbCreate, 4))

$t_fbCreate = 0

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_ConnectDatabase

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_DisConnectDatabase

; Description ...: Disconnect from the database

; Syntax ........: _FireBird_DisConnectDatabase()

; Parameters ....: None.

; Return values .: Success - 1

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_DisConnectDatabase($gs_fbDll)

Local $vRet = DllCall($gs_fbDll, "int", "DisConnectDatabase")

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_DisConnectDatabase

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_ExecuteBatch

; Description ...: Do a batch execution of statements

; Syntax ........: _FireBird_ExecuteBatch($sCmd)

; Parameters ....: $sCmd - IN -

; Return values .: Success - 1

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_ExecuteBatch($gs_fbDll,$sCmd)

Local $t_ExeBatch = DllStructCreate("char[" & StringLen($sCmd) + 1 & "]")

DllStructSetData($t_ExeBatch, 1, $sCmd)

Local $vRet = DllCall($gs_fbDll, "int", "ExecuteBatch", "ptr", DllStructGetPtr($t_ExeBatch))

$t_ExeBatch = 0

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_ExecuteBatch

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_ExecuteSelect

; Description ...: Executes an SQL query.

; Syntax ........: _FireBird_ExecuteSelect($sCmd, ByRef $sResult)

; Parameters ....: $sCmd - IN -

; $sResult - IN/OUT -

; Return values .: Success - Record count

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_ExecuteSelect($gs_fbDll,$sCmd, ByRef $sResult)

Local $t_ExeSelect = DllStructCreate("char[" & StringLen($sCmd) + 1 & "];uint;uint")

DllStructSetData($t_ExeSelect, 1, $sCmd)

Local $vRet = DllCall($gs_fbDll, "int", "ExecuteSelect", "ptr", DllStructGetPtr($t_ExeSelect, 1), _

"ptr", DllStructGetPtr($t_ExeSelect, 2), _

"ptr", DllStructGetPtr($t_ExeSelect, 3))

$sResult = __FireBird_GetBstr(DllStructGetData($t_ExeSelect, 2), DllStructGetData($t_ExeSelect, 3))

$t_ExeSelect = 0

Return SetError( $vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_ExecuteSelect

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_ExecuteStatement

; Description ...: Execute an SQL statement

; Syntax ........: _FireBird_ExecuteStatement($sCmd)

; Parameters ....: $sCmd - IN -

; Return values .: Success - 1

; Failure - 0 and @error to 1

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_ExecuteStatement($gs_fbDll, $sCmd)

Local $t_ExeStatement = DllStructCreate("char[" & StringLen($sCmd) + 1 & "]")

DllStructSetData($t_ExeStatement, 1, $sCmd)

Local $vRet = DllCall($gs_fbDll, "int", "ExecuteStatement", "ptr", DllStructGetPtr($t_ExeStatement, 1))

$t_ExeStatement = 0

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_ExecuteStatement

;Func _FireBird_ExecuteStatement($gs_fbDll,$sCmd)

; Local $vRet = DllCall($gs_fbDll, "int", "ExecuteStatement", "str", $sCmd)

; MsgBox(0,"Debug","Attempt to execute statement returned error code : "&@error)

; Return

;EndFunc

; #FUNCTION# =====================================================================

; Name ..........: _FireBird_Help

; Description ...: Shows help dialog

; Syntax ........: _FireBird_Help()

; Parameters ....: None.

; Return values .:

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; Example .......: [yes/no]

; ================================================================================

Func _FireBird_Help($gs_fbDll)

Local $vRet = DllCall($gs_fbDll, "none", "Help")

Return SetError($vRet[0] <> 0, 0, $vRet[0])

EndFunc ;==>_FireBird_Help

; #INTERNAL_USE_ONLY# ============================================================

; Name ..........: __FireBird_GetBstr

; Description ...:

; Syntax ........: __FireBird_GetBstr($ptr, $len)

; Parameters ....: $ptr - IN -

; $len - IN -

; Return values .:

; Author ........: Stephen Podhajecki (eltorro)

; Modified.......:

; Remarks .......:

; Related .......:

; Link ..........: http://fbdll4vb.sourceforge.net/

; ================================================================================

Func __FireBird_GetBstr($ptr, $len)

Local $t_ret = DllStructCreate("char[" & $len & "]", $ptr)

Local $vRet = DllStructGetData($t_ret, 1)

$t_ret = 0

;ConsoleWrite($vRet)

Return $vRet

EndFunc ;==>__FireBird_GetBstr

I then changed the main code to look like this...

CODE
#include "Lib\_FireBird.au3"

Global $h_fbDll = DllOpen(@ScriptDir & "\fbdll4vb20.dll")

Global $servername=@ComputerName&":"

Global $g_DBName="C:\TEST3.FDB"

_FireBird_About($h_fbDll)

_FireBird_Help($h_fbDll)

MsgBox(0, "Execute Firebird_Check Function. Passed 3, should return same.", _FireBird_Check($h_fbDll,3))

MsgBox(0, "Execute Firbird_SetDebug Function.", _FireBird_SetDebug($h_fbDll,True))

MsgBox(0, "Execute Firebird_CreateDatabase.", _FireBird_CreateDatabase($h_fbDll,$servername, $g_DBName, "SYSDBA", "masterkey", 1, 3))

TestCreate($h_fbDll, $servername, $g_DBName)

If @error Then

MsgBox(266288, "Error returned from TestCreate Function", @extended)

DllClose($h_fbDll)

Exit

EndIf

TestSelect($h_fbDll, $servername, $g_DBName)

DllClose($h_fbDll)

Exit

;-----------------------------------------------------------------------------------------------------------------

Func TestCreate($gs_fbDll, $sServerName, $sDBName)

Local $rv = _FireBird_ConnectDatabase($gs_fbDll, $sServerName, $sDBName, "SYSDBA", "masterkey")

If Not $rv Then Return SetError(1, 0, 0)

If $rv Then

$rv = _FireBird_ExecuteStatement($gs_fbDll,"DROP TABLE test")

$rv = _FireBird_ExecuteStatement($gs_fbDll, "CREATE TABLE test (integer_fld integer not null primary key," _

& "varchar40_fld varchar (40), " _

& "varchar50_fld varchar (50), " _

& "char4_fld char(4), " _

& "char20_fld char(20), " _

& "date_fld date, " _

& "integer2_fld integer, " _

& "numeric5_2_fld numeric(5,2), " _

& "numeric8_2_fld numeric(8,2), " _

& "numeric16_4_fld numeric(16,4), " _

& "decimal5_2_fld decimal(5,2), " _

& "decimal8_2_fld decimal(8,2), " _

& "decimal16_4_fld decimal(16,4), " _

& "double_precision_fld double precision, " _

& "float_fld float, " _

& "smallint_fld smallint, " _

& "time_field time, " _

& "timestamp_field timestamp, " _

& "blob_fld blob, " _

& "html varchar (100) " _

& ") ")

$rv = _FireBird_ExecuteStatement($gs_fbDll,"CREATE GENERATOR " & Chr(34) & "test_seq" & Chr(34))

If Not $rv Then Return SetError(1, 2, 0)

Local $trigger = "CREATE TRIGGER " & Chr(34) & "TRG_INTEGER_TEST" & Chr(34) & " FOR " & Chr(34) & "TEST" & Chr(34) & @CRLF _

& "ACTIVE BEFORE INSERT POSITION 0 " & @CRLF _

& "AS" & @CRLF _

& "BEGIN" & @CRLF _

& " new.integer_fld = gen_id(" & Chr(34) & "test_seq" & Chr(34) & ", 1);" & @CRLF _

& "END"

$rv = _FireBird_ExecuteStatement($gs_fbDll,$trigger)

If Not $rv Then Return SetError(1, 3, 0)

MsgBox(0, "CreateTest Complete. Result = ", $rv)

EndIf

$rv = _FireBird_DisConnectDatabase($gs_fbDll)

EndFunc ;==>TestCreate

;-------------------------------------------------------------------------------------------------------------------------

Func TestSelect($gs_fbDll,$sServerName,$sDBName)

Local $rv, $rcount, $result, $xmldoc

$rv = _FireBird_ConnectDatabase($gs_fbDll,$sServerName,$sDBName, "SYSDBA", "masterkey")

If $rv Then

$rcount = _FireBird_ExecuteSelect($gs_fbDll,"SELECT * FROM test", $result)

$xmldoc = ObjCreate("MSXML2.FreeThreadedDOMDocument")

$xmldoc.async = False

If (Not $xmldoc.loadXML($result)) Then

MsgBox(0, "Error parsing Response", "Response is not a valid XML document")

Else

MsgBox(0, "Response", "Response is a valid XML document." & @CRLF & "Records retrieved: " & $rcount & @CRLF & "Open the " & @ScriptDir & "\test.xml file.")

FileWrite(@ScriptDir & "\test.xml", $result)

EndIf

$xmldoc = 0

_FireBird_DisConnectDatabase($gs_fbDll)

EndIf

EndFunc ;==>TestSelect

And the following are the responses I get when I run it...I ensure there is no C:\Test3.fdb before I start.

-IBPP Wrapper for Firebird Database (FB1.5)..blah blah

-List of Methods in this DLL... blah blah

-Check function returns 3

-Set debug function returns 1

-Servername= Implementation:, DBName=C:\Test3.fdb

-"Database created for speed" message and noticed that C:\Test3.fdb file has been created with file size of 580kb

-Execute FireBird_Create database message returns 1

-"Connected.." message displayed

-"DROP TABLE test" message displayed

Then the following message displayed...

*** IBPP::Exception inside Statement::ExecuteImmediate ***

IBPP Message : isc_dsql_execute_immediate failed.

SQL Message : -901

can't format message 13:99 -- message system code -4.

Engine Code : 335544569

Engine Message :

Dynamic SQL Error

SQL error code = -901

feature is not supported

---------------------------

Click OK on error message and then this is displayed..

CREATE TABLE test (integer_fld integer not null primary key,varchar40_fld varchar (40), varchar50_fld varchar (50), char4_fld char(4), char20_fld char(20), date_fld date, integer2_fld integer, numeric5_2_fld numeric(5,2), numeric8_2_fld numeric(8,2), numeric16_4_fld numeric(16,4), decimal5_2_fld decimal(5,2), decimal8_2_fld decimal(8,2), decimal16_4_fld decimal(16,4), double_precision_fld double precision, float_fld float, smallint_fld smallint, time_field time, timestamp_field timestamp, blob_fld blob, html varchar (100) )

Click OK on Create table message and then this is displayed.

*** IBPP::Exception inside Statement::ExecuteImmediate ***

IBPP Message : isc_dsql_execute_immediate failed.

SQL Message : -901

can't format message 13:99 -- message system code -4.

Engine Code : 335544569

Engine Message :

Dynamic SQL Error

SQL error code = -901

feature is not supported

---------------------------

Click OK on error message and then this is displayed..

CREATE GENERATOR "test_seq"

Click on OK and then this is displayed

*** IBPP::Exception inside Statement::ExecuteImmediate ***

IBPP Message : isc_dsql_execute_immediate failed.

SQL Message : -901

can't format message 13:99 -- message system code -4.

Engine Code : 335544569

Engine Message :

Dynamic SQL Error

SQL error code = -901

feature is not supported

---------------------------

Then the final screen says...

Error returned from TestCreate function = 2

So .. Stuck again ..

Doh!

Share this post


Link to post
Share on other sites

Drop the ":" from the servername and it works for me.

I made some changes to the UDF. Mainly passing in the dll handle.

Also added a func for connection strictly to embeded db, _FireBird_ConnectEmbededDatabase.

include-once
; #INDEX# ====================================================================
; Title .........: _FireBird.au3
; Description ...: FireBird, Interbase dll udf.
; Author ........: Stephen Podhajecki (Eltorro)
; ==============================================================================

; #CURRENT# ======================================================================
;_FireBird_Check
;_FireBird_About
;_FireBird_SetDebug
;_FireBird_CreateDatabase
;_FireBird_SetPageBuffers
;_FireBird_ConnectEmbededDatabase
;_FireBird_ConnectDatabase
;_FireBird_DisConnectDatabase
;_FireBird_ExecuteBatch
;_FireBird_ExecuteSelect
;_FireBird_ExecuteStatement
;_FireBird_Help
; ================================================================================

; #INTERNAL_USE_ONLY# ============================================================
;__FireBird_GetBstr
; ================================================================================

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_Check
; Description ...: Test function returns the same value given.
; Syntax ........: _FireBird_Check($iCheck)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $iCheck - IN -
; Return values .: Success - $iCheck
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_Check($h_fbDll,$iCheck)
    Local $vRet = DllCall($h_fbDll, "int", "Check", "long", $iCheck)
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_Check

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_About
; Description ...: Shows about message
; Syntax ........: _FireBird_About()
; Parameters ....: $h_fbDll - Handle to firebird dll.
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_About($h_fbDll)
    Local $vRet = DllCall($h_fbDll, "none", "About")
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_About

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_SetDebug
; Description ...: Turns debugging on or off
; Syntax ........: _FireBird_SetDebug($xdebug)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $fDebug - IN True or false
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_SetDebug($h_fbDll,$fDebug)
    Local $vRet = DllCall($h_fbDll, "int", "SetDebug", "int", $fDebug)
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_SetDebug

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_CreateDatabase
; Description ...: Creates a database
; Syntax ........: _FireBird_CreateDatabase($sServerName, $sDBName, $sUsername, $sPassword, $iWriteMode = 1,$iDialect = 3)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $sServerName - IN -
;                  $sDBName - IN -
;                  $sUsername - IN -
;                  $sPassword - IN -
;                  $iWriteMode - IN/OPTIONAL -
;                 $iDialect  - IN/OPTIONAL -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......: Overwrites existing database if it exists unless it is being used.
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_CreateDatabase($h_fbDll,$sServerName, $sDBName, $sUsername, $sPassword, $iWriteMode, $iDialect = 3)
    Local $tagfbCreate = "char[%d];char[%d];char[%d];char[%d]"
    $tagfbCreate = StringFormat($tagfbCreate, StringLen($sServerName) + 1, StringLen($sDBName) + 1, StringLen($sUsername) + 1, StringLen($sPassword) + 1, $iWriteMode = 1, $iDialect = 3)
    Local $t_fbCreate = DllStructCreate($tagfbCreate)
    DllStructSetData($t_fbCreate, 1, $sServerName)
    DllStructSetData($t_fbCreate, 2, $sDBName)
    DllStructSetData($t_fbCreate, 3, $sUsername)
    DllStructSetData($t_fbCreate, 4, $sPassword)
    Local $vRet = DllCall($h_fbDll, "int", "CreateDatabase", "ptr", DllStructGetPtr($t_fbCreate, 1), "ptr", DllStructGetPtr($t_fbCreate, 2), "ptr", DllStructGetPtr($t_fbCreate, 3), "ptr", DllStructGetPtr($t_fbCreate, 4), "int", $iWriteMode, "int", $iDialect)
    $t_fbCreate = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_CreateDatabase

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_SetPageBuffers
; Description ...: Sets the page buffers when creating a database.
; Syntax ........: _FireBird_SetPageBuffers($a)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $iSize - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_SetPageBuffers($h_fbDll, $iSize)
    Local $vRet = DllCall($h_fbDll, "int", "SetPageBuffers", "int", $iSize)
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_SetPageBuffers

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ConnectDatabase
; Description ...: Connect to an embeded database.
; Syntax ........: _FireBird_ConnectDatabase($sDBName, $sUsername, $sPassword)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $sDBName - IN -
;                  $sUsername - IN -
;                  $sPassword - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......: Only dialect 3 database supported
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ConnectEmbededDatabase($h_fbDll, $sDBName, $sUsername, $sPassword)
    Local $tagfbCreate = "char[%d];char[%d];char[%d]"
    $tagfbCreate = StringFormat($tagfbCreate, StringLen($sDBName) + 1, StringLen($sUsername) + 1, StringLen($sPassword) + 1)
    Local $t_fbCreate = DllStructCreate($tagfbCreate)
    DllStructSetData($t_fbCreate, 1, $sDBName)
    DllStructSetData($t_fbCreate, 2, $sUsername)
    DllStructSetData($t_fbCreate, 3, $sPassword)
    Local $vRet = DllCall($h_fbDll, "int", "ConnectDatabase", "ptr", DllStructGetPtr($t_fbCreate, 1), "ptr", DllStructGetPtr($t_fbCreate, 2), "ptr", DllStructGetPtr($t_fbCreate, 3))
    $t_fbCreate = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ConnectEmbededDatabase
; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ConnectDatabase
; Description ...: Connect to a database.
; Syntax ........: _FireBird_ConnectDatabase($sDBName, $sUsername, $sPassword)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $sServerName - IN -
;                  $sDBName - IN -
;                  $sUsername - IN -
;                  $sPassword - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......: Only dialect 3 database supported
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ConnectDatabase($h_fbDll, $sServerName, $sDBName, $sUsername, $sPassword)
    Local $tagfbCreate = "char[%d];char[%d];char[%d];char[%d]"
    $tagfbCreate = StringFormat($tagfbCreate, StringLen($sServerName) + 1, StringLen($sDBName) + 1, StringLen($sUsername) + 1, StringLen($sPassword) + 1)
    Local $t_fbCreate = DllStructCreate($tagfbCreate)
    DllStructSetData($t_fbCreate, 1, $sServerName)
    DllStructSetData($t_fbCreate, 2, $sDBName)
    DllStructSetData($t_fbCreate, 3, $sUsername)
    DllStructSetData($t_fbCreate, 4, $sPassword)
    Local $vRet = DllCall($h_fbDll, "int", "ConnectDatabase", "ptr", DllStructGetPtr($t_fbCreate, 1), "ptr", DllStructGetPtr($t_fbCreate, 2), "ptr", DllStructGetPtr($t_fbCreate, 3), "ptr", DllStructGetPtr($t_fbCreate, 4))
    $t_fbCreate = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ConnectDatabase

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_DisConnectDatabase
; Description ...: Disconnect from the database
; Syntax ........: _FireBird_DisConnectDatabase()
; Parameters ....: $h_fbDll - Handle to firebird dll.
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_DisConnectDatabase($h_fbDll)
    Local $vRet = DllCall($h_fbDll, "int", "DisConnectDatabase")
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_DisConnectDatabase

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ExecuteBatch
; Description ...: Do a batch execution of statements
; Syntax ........: _FireBird_ExecuteBatch($sCmd)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $sCmd - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ExecuteBatch($h_fbDll, $sCmd)
    Local $t_ExeBatch = DllStructCreate("char[" & StringLen($sCmd) + 1 & "]")
    DllStructSetData($t_ExeBatch, 1, $sCmd)
    Local $vRet = DllCall($h_fbDll, "int", "ExecuteBatch", "ptr", DllStructGetPtr($t_ExeBatch))
    $t_ExeBatch = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ExecuteBatch

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ExecuteSelect
; Description ...: Executes an SQL query.
; Syntax ........: _FireBird_ExecuteSelect($sCmd, ByRef $sResult)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $sCmd - IN -
;                  $sResult - IN/OUT -
; Return values .: Success - Record count
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ExecuteSelect($h_fbDll, $sCmd, ByRef $sResult)
    Local $t_ExeSelect = DllStructCreate("char[" & StringLen($sCmd) + 1 & "];uint;uint")
    DllStructSetData($t_ExeSelect, 1, $sCmd)
    Local $vRet = DllCall($h_fbDll, "int", "ExecuteSelect", "ptr", DllStructGetPtr($t_ExeSelect, 1), "ptr", DllStructGetPtr($t_ExeSelect, 2), "ptr", DllStructGetPtr($t_ExeSelect, 3))
    $sResult = __FireBird_GetBstr(DllStructGetData($t_ExeSelect, 2), DllStructGetData($t_ExeSelect, 3))
    $t_ExeSelect = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ExecuteSelect

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_ExecuteStatement
; Description ...: Execute an SQL statement
; Syntax ........: _FireBird_ExecuteStatement($sCmd)
; Parameters ....: $h_fbDll - Handle to firebird dll.
;                  $sCmd - IN -
; Return values .: Success - 1
;                  Failure - 0 and @error to 1
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_ExecuteStatement($h_fbDll, $sCmd)
    Local $t_ExeStatement = DllStructCreate("char[" & StringLen($sCmd) + 1 & "]")
    DllStructSetData($t_ExeStatement, 1, $sCmd)
    Local $vRet = DllCall($h_fbDll, "int", "ExecuteStatement", "ptr", DllStructGetPtr($t_ExeStatement, 1))
    $t_ExeStatement = 0
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_ExecuteStatement

; #FUNCTION# =====================================================================
; Name ..........: _FireBird_Help
; Description ...: Shows help dialog
; Syntax ........: _FireBird_Help()
; Parameters ....: $h_fbDll - Handle to firebird dll.
; Return values .:
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; Example .......: [yes/no]
; ================================================================================
Func _FireBird_Help($h_fbDll)
    Local $vRet = DllCall($h_fbDll, "none", "Help")
    Return SetError($vRet[0] <> 0, 0, $vRet[0])
EndFunc   ;==>_FireBird_Help

; #INTERNAL_USE_ONLY# ============================================================
; Name ..........: __FireBird_GetBstr
; Description ...:
; Syntax ........: __FireBird_GetBstr($ptr, $len)
; Parameters ....: $ptr - IN -
;                  $len - IN -
; Return values .:
; Author ........: Stephen Podhajecki (eltorro)
; Modified.......:
; Remarks .......:
; Related .......:
; Link ..........: http://fbdll4vb.sourceforge.net/
; ================================================================================
Func __FireBird_GetBstr($ptr, $len)
    Local $t_ret = DllStructCreate("char[" & $len & "]", $ptr)
    Local $vRet = DllStructGetData($t_ret, 1)
    $t_ret = 0
    ;ConsoleWrite($vRet)
    Return $vRet
EndFunc   ;==>__FireBird_GetBstr

I made some minor changes to you test file.

#include "Lib\_FireBird.au3"
Global $h_fbDll = DllOpen(@ScriptDir & "\fbdll4vb20.dll")
Global $servername=@ComputerName
Global $g_DBName="C:\TEST3.FDB"

_FireBird_About($h_fbDll)
_FireBird_Help($h_fbDll)

MsgBox(0, "Execute Firebird_Check Function. Passed 3, should return same.", _FireBird_Check($h_fbDll,3))
MsgBox(0, "Execute Firbird_SetDebug Function.", _FireBird_SetDebug($h_fbDll,True))

If _FireBird_CreateDatabase($h_fbDll,$servername, $g_DBName, "SYSDBA", "masterkey", 1, 3) Then
    MsgBox(0, "Execute Firebird_CreateDatabase.", $g_DBName &" was successfully created.")
Else
    If MsgBox(4, "Execute Firebird_CreateDatabase.","Error creating database. Continue?") <> 6 Then
    DllClose($h_fbDll)
    Exit
    EndIf
EndIf

TestCreate($h_fbDll, $servername, $g_DBName)

If @error Then
MsgBox(266288, "Error returned from TestCreate Function", @extended)
DllClose($h_fbDll)
Exit
EndIf

TestSelect($h_fbDll, $servername, $g_DBName)

DllClose($h_fbDll)
Exit


;-----------------------------------------------------------------------------------------------------------------
Func TestCreate($gs_fbDll, $sServerName, $sDBName)
Local $rv = _FireBird_ConnectDatabase($gs_fbDll, $sServerName, $sDBName, "SYSDBA", "masterkey")
If Not $rv Then Return SetError(1, 0, 0)
If $rv Then
$rv = _FireBird_ExecuteStatement($gs_fbDll,"DROP TABLE test")
$rv = _FireBird_ExecuteStatement($gs_fbDll,"DROP GENERATOR " & Chr(34) & "test_seq" & Chr(34))
$rv = _FireBird_ExecuteStatement($gs_fbDll, "CREATE TABLE test (integer_fld integer not null primary key," _
& "varchar40_fld varchar (40), " _
& "varchar50_fld varchar (50), " _
& "char4_fld char(4), " _
& "char20_fld char(20), " _
& "date_fld date, " _
& "integer2_fld integer, " _
& "numeric5_2_fld numeric(5,2), " _
& "numeric8_2_fld numeric(8,2), " _
& "numeric16_4_fld numeric(16,4), " _
& "decimal5_2_fld decimal(5,2), " _
& "decimal8_2_fld decimal(8,2), " _
& "decimal16_4_fld decimal(16,4), " _
& "double_precision_fld double precision, " _
& "float_fld float, " _
& "smallint_fld smallint, " _
& "time_field time, " _
& "timestamp_field timestamp, " _
& "blob_fld blob, " _
& "html varchar (100) " _
& ") ")

$rv = _FireBird_ExecuteStatement($gs_fbDll,"CREATE GENERATOR " & Chr(34) & "test_seq" & Chr(34))
If Not $rv Then Return SetError(1, 2, 0)
Local $trigger = "CREATE TRIGGER " & Chr(34) & "TRG_INTEGER_TEST" & Chr(34) & " FOR " & Chr(34) & "TEST" & Chr(34) & @CRLF _
& "ACTIVE BEFORE INSERT POSITION 0 " & @CRLF _
& "AS" & @CRLF _
& "BEGIN" & @CRLF _
& " new.integer_fld = gen_id(" & Chr(34) & "test_seq" & Chr(34) & ", 1);" & @CRLF _
& "END"
$rv = _FireBird_ExecuteStatement($gs_fbDll,$trigger)
If Not $rv Then Return SetError(1, 3, 0)
MsgBox(0, "CreateTest Complete. Result = ", $rv)
EndIf

$rv = _FireBird_DisConnectDatabase($gs_fbDll)
EndFunc;==>TestCreate

;-------------------------------------------------------------------------------------------------------------------------
Func TestSelect($gs_fbDll,$sServerName,$sDBName)
Local $rv, $rcount, $result, $xmldoc
$rv = _FireBird_ConnectDatabase($gs_fbDll,$sServerName,$sDBName, "SYSDBA", "masterkey")
If $rv Then
$rcount = _FireBird_ExecuteSelect($gs_fbDll,"SELECT * FROM test", $result)

$xmldoc = ObjCreate("MSXML2.FreeThreadedDOMDocument")
$xmldoc.async = False

If (Not $xmldoc.loadXML($result)) Then
MsgBox(0, "Error parsing Response", "Response is not a valid XML document")
Else
MsgBox(0, "Response", "Response is a valid XML document." & @CRLF & "Records retrieved: " & $rcount & @CRLF & "Open the " & @ScriptDir & "\test.xml file.")
FileWrite(@ScriptDir & "\test.xml", $result)
EndIf
$xmldoc = 0
_FireBird_DisConnectDatabase($gs_fbDll)
EndIf
EndFunc;==>TestSelect

Hope this helps.

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

To all that have assisted in this problem, I would submit my humble thanks.

El Torro,

The code ran through ok on my system with your changes.

I will now integrate this into my main code and see if there are any conditions that need attention.

I hope that you would now submit this as a library (UDF?) for general use by others who have tried to connect to FireBird and found thst resources for portable, direct connects have been lacking.

Thanks again for the persistance from all involved to get this code working.

Kindest regards, Wal.

Edited by WSorich

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