Jump to content

Recommended Posts

Posted (edited)

Can someone help me with returning a postgreSQL query?  I have gotten the code to connect to the database working, but I am unable to actually run a query, i just get an error return every time.  I have successfully done so with MySQL.  From looking at other examples the setup to do so is a bit different for postgreSQL, but when using those examples i get a failure.

 

;====================  AUTOIT WRAPPER START  ====================
            #AutoIt3Wrapper_UseX64=n
;====================  AUTOIT WRAPPER STOP  ====================










;====================  INCLUDES START  ====================
            #include <Array.au3>
;====================  INCLUDES STOP  ====================










;====================  VARIABLES START  ====================
            $TEMP_QueryReturn = ObjCreate("ADODB.Recordset")

            Global $SETTING_Driver = "PostgreSQL Unicode"
            Global $SETTING_Server = "192.168.1.12"
            Global $SETTING_Port = "5432"
            Global $SETTING_DatabaseName = "test"
            GLobal $SETTING_Username = "test"
            Global $SETTING_Password = "test"
            Global $SETTING_Query = 'SELECT * FROM settings'

            $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler
;====================  VARIABLES STOP  ====================










;====================  CONNECT TO DATABASE START  ====================
            Global $Connection = ObjCreate("ADODB.Connection")
;~          $Connection.open ("DRIVER=" & $SETTING_Driver & ";SERVER=" & $SETTING_Server & ";DATABASE=" & $SETTING_DatabaseName & ";UID=" & $SETTING_Username & ";PWD=" & $SETTING_Password & ";PORT=" & $SETTING_Port)
            $Connection.open ("DSN=PostgreSQL;DATABASE=test;SERVER=192.168.1.12;Port=5432;Uid=test;Pwd=test")
            If @error Then MsgBox(0,"","Error Opening Connection")
;====================  CONNECT TO DATABASE STOP  ====================










;====================  RUN QUERY START  ====================
            $TEMP_QueryReturn.open($SETTING_Query,$Connection,1,3)
            If @error Then MsgBox(0,"","Error Executing Query")
;====================  RUN QUERY STOP  ====================

 

Edited by MistakenSanity
Posted (edited)

You shuold add COM ERROR HANDLER:
Check first example from here:

https://www.autoitscript.com/autoit3/docs/functions/ObjEvent.htm

 

but I I encourage you to use 

 

Also you could use:
_ADO_GetDSNList()
_ADO_GetProvidersList()

to check which Driver/Provider you have installed......

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...