Sign in to follow this  
Followers 0
kcvinu

Can i connect Access database with an autoit application ?

5 posts in this topic

Hi there,

I need to make a little program that takes some text input from user and saves it in a database. Then later, user presses the hotkey of each text, my program will retrieve it and send to the top most window. I have made the GUI. Now i need to learn about how autoit deals with databases. I have access 2007 in my system. So i would like to make a table in access. Is it possible to connect access database to an autoit program. If so how. ?. Thanks in advance.


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites



Hi 

SmOke_N

That answer is a knock to my head but it really helped me. Thanks.  And i realized that access connection may be difficult. Learning sql lite is the possible way. Because, the link of Access UDF is not working. 


My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

Share this post


Link to post
Share on other sites

Well, I am preferable to sqlite myself.

But I guess you stopped looking through the links?

'?do=embed' frameborder='0' data-embedContent>>

That one looked promising.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Hi 

SmOke_N, I think that will be a great help for me. Let me read it. Thanks. 

My Contributions

UDF Link Viewer   --- A tool to visit the links of some most important UDFs 

 Includer_2  ----- A tool to type the #include statement automatically 

 Digits To Date  ----- date from 3 integer values

PrintList ----- prints arrays into console for testing.

 Alert  ------ An alternative for MsgBox 

 MousePosition ------- A simple tooltip display of mouse position

GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function

Access_UDF  -------- An UDF for working with access database files. (.*accdb only)

 

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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      I'd like to know if there is a way to convert a PDF in CSV or, eventually, in TXT, in order to read from it, like a database...
      I have a PDF and I think ( I dind't search a lot on the forum ) with AutoIt, but I'd like work with Excel styles...
      Does anyone know a good program which convert PDF to CSV? 
      PS: the PDF file is 5 MB, and it contains 439 pages...
      Thanks everyone for the help
       
    • Queener
      By Queener
      Using the MSSQL.udf
      I asked this question once, but haven't had a chance to reply to my old post so posting a new one instead of bouncing the old post.
      I'm trying to retrieve data from my database in Microsoft SQL Server 2014. When I tried the code below; empty message box return and no error approaches.
      $Connection = _MSSQL_Con($ServerAddress, $ServerUsername, $ServerPassword, $ServerDBName) $Testquery = _MSSQL_Query($Connection, "SELECT User_ID From Banker where Manager like '%Jason%'") msgbox(0, "Test", $Testquery) exit
    • kcvinu
      By kcvinu
      Hi all,
      This is an UDF for working with Access(2007 above) databases. I would like to say thanks to @spudw2k for his wonderful ADODB udf. That is my inspiration. And i borrowed three functions from him. The difference of this UDF is that it is using SQL statements as parameters. So if you know the SQL, then you can easily work with this UDF.
      Functions in this UDF
      1. _Start_Connection
      2. _Close_Connection
      3. _Create_Table
      4. _Delete_Table
      5. _Alter_Table
      6. _Delete_FromTable
      7. _Insert_Data - You can use this to update or delete data
      8. _Get_Records
      This is an example. This example uses an access database named Test. It is packed with the zip file
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.0 Author: kcvinu Date : sep 2015 Script Function: Examples of Access_UDF Template AutoIt script. #ce ---------------------------------------------------------------------------- #include "Access_UDF.au3" #include <Array.au3> ; only for displaying data Example1() Func Example1() Local $MsgBox1 = MsgBox(4, "Access UDF Examples", " Starting Connection example, Ready ?") If $MsgBox1 = 6 Then ; We are starting a connection Local $Connection = _Start_Connection(@ScriptDir & "\Test.accdb;") ConsoleWrite($Connection & " Started" & @CRLF) ; Look for the function status Else Exit EndIf Local $MsgBox2 = MsgBox(4, "Access UDF Examples", " Starting Create Table example, Ready ?") If $MsgBox2 = 6 Then ; We need to create a new table Local $CreateTable = _Create_Table("CREATE TABLE TestTable(Column1 Text, Column2 Text);") ConsoleWrite($CreateTable & " Table Created" & @CRLF) Else Exit EndIf Local $MsgBox3 = MsgBox(4, "Access UDF Examples", " Starting Alter Table example, Ready ?") If $MsgBox3 = 6 Then ; We need to add a column to that table Local $AlterTable = _Alter_Table("ALTER TABLE TestTable ADD Column3 int;") ConsoleWrite($AlterTable & " Table Alterd" & @CRLF) Else Exit EndIf Local $MsgBox4 = MsgBox(4, "Access UDF Examples", " Starting Insert data example, Ready ?") If $MsgBox4 = 6 Then ; Insert some data Local $InsertData = _Insert_Data("INSERT INTO Table1([Col1], [Col2], [Col3]) VALUES ('AutoIt', 'Coding is Fun', 'AutoIt Rocks');") ConsoleWrite($InsertData & " Data inserted" & @CRLF) Else Exit EndIf Local $MsgBox5 = MsgBox(4, "Access UDF Examples", " Starting Update table example, Ready ?") If $MsgBox5 = 6 Then ; Let us update the table Local $UpdateData = _Insert_Data("UPDATE Table1 SET Col1 = 'Autoit Is Great', Col2 = 'Coding is Really Fun' WHERE Col3 = 'AutoIt Rocks';") ConsoleWrite($UpdateData & " Table Updated" & @CRLF) Else Exit EndIf Local $MsgBox6 = MsgBox(4, "Access UDF Examples", " Starting Get records example, Ready ?") If $MsgBox6 = 6 Then ; Now, collect some data Local $GetData = _Get_Records("SELECT [Col1],[Col2] FROM Table1 WHERE Col3 = 'AutoIt Rocks' ;") _ArrayDisplay($GetData) Else Exit EndIf Local $MsgBox7 = MsgBox(4, "Access UDF Examples", " Starting Delete from Table example, Ready ?") If $MsgBox7 = 6 Then ; Let us delete the whole data from that table, but not the table Local $DeleteAll = _Delete_FromTable("DELETE FROM Table1;") ConsoleWrite($DeleteAll & " All data deleted from Table" & @CRLF) Else Exit EndIf Local $MsgBox8 = MsgBox(4, "Access UDF Examples", " Starting Delete the entire table example, Ready ?") If $MsgBox8 = 6 Then ; Now, we are going to delete the entire table Local $DeleteTable = _Delete_Table("DROP TABLE TestTable;") ConsoleWrite($DeleteTable & " Table deleted" & @CRLF) Else Exit EndIf ; Last but not least, close the connection. _Close_Connection() ConsoleWrite("Examples Over...." & @CRLF) EndFunc ;==>Example1 Here is the files. 
      Access UDF.rar
      Access UDF.zip
    • mjolnirmarkiv
      By mjolnirmarkiv
      Hi,
      I'm trying to connect to Firebird database via AutoIt. Something that was supposed to be a cakewalk so far ended with no succes, as usual hoping for your help.
      I'm using the following Firebird Direct Access for Visual Basic DLL: http://sourceforge.net/projects/fbdll4vb/files/. And the code below comes from Stephen Podhajecki (Eltorro) Firebird UDF (only parts I need at the moment):
      The code above gives me this:

      The specific kind of server\database I need to connect to is belong to following application if that matters: http://www.projetex.com/, it is using Firebird 2.5. While ODBC\123 comes from following settings in the Server Administrator utility:

      I've installed a VM with above mentioned application, server and databse running on it so I have admin rights to access it for testing. Nevertheless when I tried to use a gsec (a command prompt utility that comes with the app) to display a list of users it only gave me this:
      gsec -user Admin -password admin -database "C:\Program Files\AIT\Projetex 9\Projetex Server\Database\Projetex.fdb" -display
      use gsec -? to get help
      Your user name and password are not defined. Ask your database administrator to setp up a Firebird login.
      unable to open database.
      So I changed it to ODBC, and there was some progress:
      gsec -user ODBC -password 123 -database "C:\Program Files\AIT\Projetex 9\Projetex Server\Database\Projetex.fdb" -display
      invalid request BLR at offset 37
      table USERS is not defined
      I tried to add a user mjolnir\123 and this time there was no progress:
      gsec -user ODBC -password 123 -database "C:\Program Files\AIT\Projetex 9\Projetex Server\Database\Projetex.fdb" -add mjolnir -pw 123
      An error occured while attempting to add the user.
      invalid request BLR at offset 51
      table USERS is not defined
      It seems I'm not quite understand how the damn thing works. The Server Administrator utility have plenty of users including the admin, all of the have access to read the database and could do this via Projetex client, neither cann't do this nor via gsec, not programmaticlly via AutoIt code above. And then it says smth about "table USERS" which is not defined apparently, looks like database users is not the same thing as server users and I'm doing it wrong.
    • GreenCan
      By GreenCan
      This is an example how to access/query different kind of Databases with AutoIt.  The demo contains also test Databases, so the script functions for most of the provided database connections.
      Databases covered here:
      Oracle (no demo database for this one) MS SQL Server (no demo database for this one) SQLite (requires installation of the SQLite ODBC driver software available here: http://www.ch-werner.de/sqliteodbc/ ) Of course SQLite is natively available in AutoIt but in some cases it might be preferable to use the ODBC approach accessing the database via the same scripted method, for example if you use different Databases in the same script, it is much easier to code.
      Excel DBase DBF MS Access CSV Text driver (semicolon delimited and comma delimited) The example script is based on Kinshima’s Oracle SQL example . I like the Dim by pack method, much better than redim one row at the time, which too slow.
      All the databases have the same data content (‘Timeline_of_space_exploration’)  to keep the examples similar for every database.
      The result of each SQL will be displayed in Arraydisplay, togheter with a window containing the ADO-less connection string (yellow) and SQL.
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Comment=Comprehensive DSN-Less Database connection demo #AutoIt3Wrapper_Res_Description=DSN-Less Database connection demo #AutoIt3Wrapper_Res_Fileversion=1.0.0.0 #AutoIt3Wrapper_Res_LegalCopyright=GreenCan #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <array.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> Opt('MustDeclareVars', 1) Global $oODBC_Connection = ObjCreate("ADODB.Connection") Global $oODBC_RecordSet = ObjCreate("ADODB.Recordset") Global $bODBC_conn = False Global $oErrADODB = ObjEvent("AutoIt.Error", "_ErrADODB") Global $bConn_error = False Global $sConnectionString, $sSQL Global Const $iDark_Blue = 0x2601D3 Global Const $iLight_Green = 0xEAFFE8 Global Const $iYellow = 0xFFFF99 ; setup GUI to display SQL Global $hGUI_View_SQL = GUICreate("SQL", 500, 500, 10, 10, $WS_CAPTION);, $WS_EX_TOPMOST) Global $hConnString = GUICtrlCreateEdit("", 5, 3, 490, 38, BitOR($ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL)) GUICtrlSetColor(-1, $iDark_Blue) GUICtrlSetBkColor(-1, $iYellow) Global $ViewSQL = GUICtrlCreateEdit("", 5, 45, 490, 450, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetColor(-1, $iDark_Blue) GUICtrlSetBkColor(-1, $iLight_Green) GUISetState() #========== Demo ============= Global $sDatabaseLocation = @ScriptDir & "\TestDatabases" #========== Oracle ============= ;~ #cs ;~ Not demo-able except if you have an Oracle instance ;~ #ce $sConnectionString = 'DRIVER={Oracle in OraClient11g_home1};DBQ=myDatabase.world;uid=myUserID;pwd=myPassword;' $sSQL = 'SELECT sysdate AS "Sysdate Raw", to_char(sysdate, ''Dy DD/MM/YY HH24:MI'') AS "Now" FROM dual' Format_SQL($sSQL, $sConnectionString) MsgBox(0,"Oracle SQL","You require to have access to an Oracle instance and modify the connection string before proceeding without error." & @CRLF & "The current Connection string will generate a COM error.") Query($sConnectionString, $sSQL, 500, "SQL Oracle") #========== MS SQL Server ============= MsgBox(0,"MS SQL Server","You require to have access to a SQL Server instance and modify the connection string before proceeding without error." & @CRLF & "The current Connection string will generate a COM error.") $sConnectionString = 'DRIVER={SQL Server};SERVER=ServerNameorIP;DATABASE=DatabaseServer;Trusted_Connection=no;uid=myUserID;pwd=myPassword;' $sSQL = 'SELECT 18 AS "Circle Radius",round(PI() * power(18,2) ,3) AS "Surface of circle", round(PI() * 18 * 2,3) AS "Circumference of circle"' Format_SQL($sSQL, $sConnectionString) Query($sConnectionString, $sSQL, 500, "MS SQL Server") #========== SQLite ============= #cs Accessing SQLite via ODBC requires installation of the SQLite ODBC driver software available here: http://www.ch-werner.de/sqliteodbc/ Note: You will have to install the 32-bit driver, as far as I could test, x6' version, sqliteodbc_w64 doesn't function on my x64 Windows You can access SQLite natively FROM AutoIt For example look at my topics - SQLite Report generator http://www.autoitscript.com/forum/topic/149767-sqlite-report-generator/#entry1068258 - SQLite demonstration of native recognition of BLOB object in Listview http://www.autoitscript.com/forum/topic/150876-sqlite-demonstration-of-native-recognition-of-blob-object-in-listview/#entry1078492 #ce $sConnectionString = 'DRIVER=SQLite3 ODBC Driver;Database=' & $sDatabaseLocation & '\Timeline_of_space_exploration.xdb;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;' ;~ $sConnectionString = 'DRIVER=SQLite3 ODBC Driver;Database=D:\SQLite\Netline.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;' $sSQL = 'SELECT * FROM space_exploration;' Format_SQL($sSQL, $sConnectionString) Query($sConnectionString, $sSQL, 500, "SQLite") #========== Excel ============= #cs The sheet range to be queried has a name defined AS SpaceTable Check the Excel sheet by selecting all (Ctrl-A) #ce $sConnectionString = 'DRIVER={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};dbq=' & $sDatabaseLocation & '\Timeline_of_space_exploration.xlsx;' $sSQL = 'SELECT Format (Date, ''dd-MM-yyyy'') AS "Event", Mission_Achievements AS "Mission Achievements", Country, Organization, Mission_Name AS "Mission Name" ' & _ ' FROM SpaceTable ORDER BY Date' Format_SQL($sSQL, $sConnectionString) Query($sConnectionString, $sSQL, 500, "SQL Microsoft Excel") #========== DBase DBF ============= #cs Old Borland/Clipper Database #ce $sConnectionString = 'DRIVER={Microsoft dBase Driver (*.dbf)};Dbq='& $sDatabaseLocation & ';' $sSQL = 'SELECT Format (DATE, ''dd MMM yyyy'') AS "Event", MISSION AS "Mission Achievements", Country, ORG AS "Organization", MNAME AS "Mission Name" ' & _ ' FROM SPACE.DBF WHERE (((DATE) Between #22/04/1900# And #22/04/2015# +1)) AND UCASE(Country) <> ''USA'' ORDER BY Date' Format_SQL($sSQL, $sConnectionString) Query($sConnectionString, $sSQL, 500, "SQL DBase") #========== MS Access ============= #cs The MSAccess Example.mdb is protected with following password: DatabaseSQL #ce $sConnectionString = 'DRIVER={Microsoft Access Driver (*.mdb)};Dbq=' & $sDatabaseLocation & '\Example.mdb;uid=;pwd=DatabaseSQL;' $sSQL = 'SELECT Format (Date, ''dd MMM yyyy'') AS "Event", Mission_Achievements AS "Mission Achievements", Country, Organization, Mission_Name AS "Mission Name" ' & _ ' FROM Timeline_of_space_exploration WHERE (((Date) Between #22/04/1900# And #22/04/2015# +1)) ORDER BY Date' Format_SQL($sSQL, $sConnectionString) Query($sConnectionString, $sSQL, 500, "SQL MS Access") #========== CSV Text driver, semicolon delimited ============= #cs Some variations of the same SQL requires schema.ini in the same folder AS the text file https://msdn.microsoft.com/en-us/library/windows/desktop/ms709353(v=vs.85).aspx schema.ini settings: [Timeline_of_space_exploration_semicolon.txt] ColNameHeader=True Format=Delimited(;) MaxScanRows=1 #ce $sConnectionString = 'DRIVER={Microsoft Text Driver (*.txt; *.csv)};Dbq=' & $sDatabaseLocation & ';Extensions=asc,csv,tab,txt;' $sSQL = 'SELECT Format (Date, ''dd MMM yyyy'') AS "Event", Mission_Achievements AS "Mission Achievements", Country, ' & _ 'Organization, Mission_Name AS "Mission Name" FROM Timeline_of_space_exploration_semicolon.txt ORDER BY Date' Format_SQL($sSQL, $sConnectionString) Query($sConnectionString, $sSQL, 500, "SQL Text semicolon delimited") #========== CSV Text driver, comma delimited ============= #cs schema.ini settings: [Timeline_of_space_exploration.csv] ColNameHeader=True Format=Delimited(,) DecimalSymbol=. MaxScanRows=1 #ce $sSQL = 'SELECT Format (Date, ''dd MMM yyyy'') AS "Event", Mission_Achievements AS "Mission Achievements", Country, ' & _ 'Organization, Mission_Name AS "Mission Name" FROM Timeline_of_space_exploration.csv ORDER BY Date' Query($sConnectionString, $sSQL, 500, "SQL Text comma delimited") ; USA only $sSQL = 'SELECT Format (Date, ''dd MMM yyyy'') AS "Event", Mission_Achievements AS "Mission Achievements", Country, ' & _ 'Organization, Mission_Name AS "Mission Name" FROM Timeline_of_space_exploration.csv WHERE (((Date) Between #22/04/1900# And #22/04/2015# +1)) and UCASE(Country) = ''USA''' Format_SQL($sSQL, $sConnectionString) Query($sConnectionString, $sSQL, 500, "SQL Text comma delimited - USA Only") #========== End Demo ============= Exit Func Query($sConnectionString, $sSQL, $iMaxRows, $sTitle) If _ODBC_OpenConnection($sConnectionString) Then Local $aRecords = _ODBC_GetRecords($sSQL, 500, $iMaxRows) _ODBC_CloseConnection() ; set header string Local $sHeader = "" For $i = 0 to UBound($aRecords, 2) - 1 $sHeader &= $aRecords[0][$i] & "|" Next $sHeader = StringTrimRight($sHeader, 1) ; trim of last separator _ArrayDisplay($aRecords, _ $sTitle & " - " & "Query result: " & UBound($aRecords)-1 & " rows" & (UBound($aRecords)-1 = $iMaxRows ? " (result limited to " & $iMaxRows & " rows)" : "") , _ "1:" & UBound($aRecords)-1, _ 0, _ Default, _ $sHeader) EndIf EndFunc ;==>Query Func _ExeSQL($sSQL) If Not IsObj($oODBC_Connection) Then Return -1 $oODBC_Connection.Execute($sSQL) If $oErrADODB.number Then MsgBox($MB_YESNO + $MB_ICONERROR + $MB_DEFBUTTON2, "_ExeSQL", $sSQL & @CRLF & @CRLF & 'Error. ' & @CRLF & 'Exiting.') Exit Else Return 1 EndIf EndFunc ;==>_ExeSQL Func _ODBC_CloseConnection() $bODBC_conn = False Return $oODBC_Connection.Close EndFunc ;==>_ODBC_CloseConnection Func _ODBC_OpenConnection($sConnectionString) If Not IsObj($oODBC_Connection) Then Return -1 If Not @Compiled Then ConsoleWrite ("@@ Debug(" & @ScriptLineNumber & ") : " & $sConnectionString & @CR) $oODBC_Connection.ConnectionString = ($sConnectionString) $bConn_error = False $oODBC_Connection.Open If $bConn_error = True Then Return False EndIf $bODBC_conn = True Return True EndFunc ;==>_ODBC_OpenConnection Func _ODBC_GetRecords($sSQL, $iArrayIncrement = 250, $iRows = 0) ; syntax: _ODBC_GetRecords(SQL, ArrayIncrement, MaxRows) If Not $bODBC_conn Then MsgBox($MB_OK, 'Error', 'Connection failure') Return EndIf If $iArrayIncrement = 0 Then $iArrayIncrement = 250 If Not IsObj($oODBC_Connection) Then Return -1 If Not IsObj($oODBC_RecordSet) Then Return -2 _ODBC_OpenRecordset($sSQL) Local $aRecords[1][1] If $oODBC_RecordSet.EOF = True Then _ODBC_CloseRecordSet() Return False EndIf $oODBC_RecordSet.MoveFirst Local $x = 0 ReDim $aRecords[1][$oODBC_RecordSet.Fields.Count] For $objField In $oODBC_RecordSet.Fields $aRecords[0][$x] = $objField.Name $x += 1 Next Local $iAIn = UBound($aRecords) + $iArrayIncrement ReDim $aRecords[$iAIn][$oODBC_RecordSet.Fields.Count] $oODBC_RecordSet.MoveFirst Local $y = 0 Do $x = 0 $y += 1 For $objField In $oODBC_RecordSet.Fields $aRecords[$y][$x] = $objField.Value $x += 1 Next If $y = $iAIn - 1 Then $iAIn += $iArrayIncrement ReDim $aRecords[$iAIn][$oODBC_RecordSet.Fields.Count] EndIf $oODBC_RecordSet.MoveNext If $iRows > 0 Then If $y = $iRows Then ;_ArrayDisplay($aRecords, @ScriptLineNumber) ReDim $aRecords[$y + 1][$oODBC_RecordSet.Fields.Count] ;_ArrayDisplay($aRecords, @ScriptLineNumber) Return $aRecords EndIf EndIf Until $oODBC_RecordSet.EOF ReDim $aRecords[$y + 1][$oODBC_RecordSet.Fields.Count] _ODBC_CloseRecordSet() Return $aRecords EndFunc ;==>_ODBC_GetRecords Func _ODBC_OpenRecordset($sSQL); If Not IsObj($oODBC_Connection) Then Return -1 If Not IsObj($oODBC_RecordSet) Then Return -2 Return $oODBC_RecordSet.Open($sSQL, $oODBC_Connection, 0, 1) EndFunc ;==>_ODBC_OpenRecordset Func _ODBC_CloseRecordSet() Return $oODBC_RecordSet.Close EndFunc ;==>_ODBC_CloseRecordSet Func _ErrADODB() MsgBox($MB_ICONWARNING, "ADODB COM Error", "We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oErrADODB.description & @CRLF & _ "err.windescription:" & @TAB & $oErrADODB.windescription & @CRLF & _ "err.number is: " & @TAB & Hex($oErrADODB.number, 8) & @CRLF & _ "err.lastdllerror is: " & @TAB & $oErrADODB.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oErrADODB.scriptline & @CRLF & _ "err.source is: " & @TAB & $oErrADODB.source & @CRLF & _ "err.helpfile is: " & @TAB & $oErrADODB.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oErrADODB.helpcontext _ ) ConsoleWrite($oErrADODB.description & @CR) $bConn_error = True Return SetError(@error, @error, 1) EndFunc ;==>_ErrADODB Func Format_SQL($sSQL, $sConnectionString) ; format SQL script a bit ; the formating does not consider UNION, Local $stempSQL, $sSQLPart1, $sSQLPart2, $sSQLPart3, $sSQLPart4, $sSQLPart5, $sSQLPart6 $stempSQL = $sSQL ; LIMIT - should be after FROM ! If StringInStr($stempSQL, "LIMIT", 0, -1) > 0 Then If StringInStr($stempSQL, "LIMIT", 0, -1) > StringInStr($stempSQL, "FROM", 0, -1) Then $sSQLPart6 = @CRLF & "LIMIT" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "LIMIT", 0, -1) + 5) $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "LIMIT", 0, -1) + 1), 2) EndIf EndIf ; ORDER BY - should be after FROM ! If StringInStr($stempSQL, "ORDER BY", 0, -1) > 0 Then If StringInStr($stempSQL, "ORDER BY", 0, -1) > StringInStr($stempSQL, "FROM", 0, -1) Then $sSQLPart5 = @CRLF & "ORDER BY" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "ORDER BY", 0, -1) + 8) $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "ORDER BY", 0, -1) + 1), 2) EndIf EndIf ; GROUP BY - should be after FROM ! If StringInStr($stempSQL, "GROUP BY", 0, -1) > 0 Then If StringInStr($stempSQL, "GROUP BY", 0, -1) > StringInStr($stempSQL, "FROM", 0, -1) Then $sSQLPart4 = @CRLF & "GROUP BY" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "GROUP BY", 0, -1) + 8) $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "GROUP BY", 0, -1) + 1), 2) EndIf EndIf ; WHERE - should be after FROM ! If StringInStr($stempSQL, "WHERE", 0, -1) > 0 Then If StringInStr($stempSQL, "WHERE", 0, -1) > StringInStr($stempSQL, "FROM", 0, -1) Then $sSQLPart3 = @CRLF & "WHERE" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "WHERE", 0, -1) + 5) $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "WHERE", 0, -1) + 1), 2) EndIf EndIf ; INNER JOIN If StringInStr($stempSQL, "INNER JOIN", 0, -1) > 0 Then $stempSQL = StringReplace($stempSQL, "INNER JOIN", @CRLF & @TAB & @TAB & "INNER JOIN") EndIf ; FROM If StringInStr($stempSQL, "FROM", 0, -1) > 0 Then $sSQLPart2 = @CRLF & "FROM" & @CRLF & @TAB & StringTrimLeft($stempSQL, StringInStr($stempSQL, "FROM", 0, -1) + 4) $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "FROM", 0, -1) + 1), 2) EndIf ; SELECT If StringInStr($stempSQL, "SELECT", 0, 1) > 0 Then $sSQLPart1 = "SELECT" & @CRLF & @TAB & StringReplace(StringReplace(StringTrimLeft($stempSQL, StringInStr($stempSQL, "SELECT", 0, 1) + 6),", ", ",") , ",", "," & @CRLF & @TAB) $stempSQL = StringStripWS(StringTrimRight($stempSQL, StringLen($stempSQL) - StringInStr($stempSQL, "SELECT", 0, 1) + 1), 2) EndIf GUICtrlSetData ( $hConnString, $sConnectionString) GUICtrlSetData ( $ViewSQL, $sSQLPart1 & $sSQLPart2 & $sSQLPart3 & $sSQLPart4 & $sSQLPart5 & $sSQLPart6 & @CRLF ) EndFunc ;==>Format_SQL Script and database packs
      SQL demo DSN-less connections (multi-DB).zip
      GreenCan